RobustOS Pro Bluetooth Tutorial: Simulating a BLE Device…

RobustOS Pro Bluetooth Tutorial: Simulating a BLE Device with nRF Connect

Overview

A Robustel gateway running RobustOS Pro can support testing Bluetooth Low Energy with nRF Connect when a phone must simulate a BLE advertiser and GATT server for gateway development. This guide explains how to create the mobile BLE service, scan from the gateway and read or write the documented characteristic. Following the steps below, you'll go through the complete process of:
  1. Simulating a BLE (Bluetooth Low Energy) device on a mobile phone using nRF Connect for Mobile.

  2. Scanning for and connecting to the simulated BLE device from a RobustOS Pro device.

  3. Reading from and writing to the BLE device's characteristics using the GATT protocol.

The key conclusion is that Bluetooth support and device paths must be confirmed for the target model before testing. 

1. Prerequisites

1.1 Hardware Requirements

  • RobustOS Pro Device: EG5100, EG5120, EG5200,R1520LG or EV8100 (models with a Bluetooth module).

  • Android or iOS Device: To run the nRF Connect for Mobile application.

1.2 Software Installation

Install the nRF Connect for Mobile app on your phone:

  • Android: [Google Play Store]

  • iOS: [App Store]

1.3 Confirm Device Model

On your RobustOS Pro device, execute the following command:

sudo renv get board

Example output: eg5120, eg5100, eg5200, ev8100, etc.

2. Simulating a BLE Device with nRF Connect

2.1 Launch the nRF Connect App

  1. Open the nRF Connect for Mobile app on your phone.

  2. Grant the necessary Bluetooth and location permissions when prompted.

2.2 Add a GATT Server

Tap the hamburger menu (☰) in the top-left corner and select "Configure GATT Server".

2.2.1 Add a New GATT Configuration

By default, there is no GATT Server. Tap the ⊕ button at the top to add a new GATT configuration.

Enter a unique name for your GATT configuration.

2.2.2 Add a Service

Add a SERVICE to the new GATT configuration. You can choose a predefined service or create a custom one.

Enter a custom Service name and a randomly generated UUID.

2.2.3 Add a Characteristic

Add a characteristic to the new service.

Enter a characteristic name, a randomly generated UUID, and select its properties (e.g., Read, Write) and permissions (e.g., Read, Write).

You can also set an initial value for the characteristic.

Click OK to save the configuration.

2.3 Create a BLE Peripheral (Advertiser)

2.3.1 Configure the Advertising Packet

Return to the main screen by tapping the hamburger menu (☰) and selecting Devices. Then, switch to the ADVERTISER tab.

Tap the + button to add a new advertising template.

  • Enter a display name (for the app).

  • Click Add Record.

    • Select Complete Local Name.
  • Select Options.

    • Check the Connectable box.

2.3.2 Rename the BLE Peripheral

Tap the edit icon in the top-right corner to change the BLE peripheral's name.

2.4 Start BLE Advertising

Toggle the switch to start advertising your simulated BLE peripheral.

3. RobustOS Pro Bluetooth Initialization

Follow these steps on your RobustOS Pro device to enable the Bluetooth module.

3.1 Enable the Bluetooth Module (EG5200 Only)

If your device is an EG5200, you must run the following command to enable the Bluetooth module. Skip this step for all other models!

# Enable the Bluetooth module
sudo sh -c 'echo 1 > /sys/class/gpio/gpio1/value'

# Verify the status (should output 1)
cat /sys/class/gpio/gpio1/value

3.2 Attach the HCI Interface

Choose the command corresponding to your device model:

EG5200:

sudo hciattach /dev/ttymxc3 qca -t120 3000000 flow

EG5100/EG5120:

sudo hciattach /dev/ttymxc3 any 115200 flow

R1520LG:

sudo hciattach /dev/ttymxc4 any 115200 flow
EV8100:
sudo hciattach /dev/ttymxc1 any 115200 flow

3.3 Bring Up the Bluetooth Controller

sudo hciconfig hci0 up

3.4 Verify Bluetooth Status

hciconfig

The expected output should include the "UP RUNNING" status:

hci0:   Type: Primary  Bus: UART
BD Address: 44:1A:84:DF:7F:99 ACL MTU: 1021:8 SCO MTU: 255:16
UP RUNNING
...

4. Scanning for BLE Devices

4.1 Scanning with bluetoothctl

4.1.1 Interactive Mode

Start the bluetoothctl utility in interactive mode:

bluetoothctl

Inside the bluetoothctl prompt, execute:

power on        # Turn the Bluetooth power on
scan on # Start scanning for devices

Wait for the scan results. You should see your device appear:

[NEW] Device 5E:2E:EA:59:B2:6D 5E-2E-EA-59-B2-6D
[NEW] Device 69:7B:B4:A2:ED:A7 MyTestDevice
[NEW] Device 53:34:2F:8F:76:2D 53-34-2F-8F-76-2D
[NEW] Device 55:66:6E:66:26:49 55-66-6E-66-26-49
...

Stop the scan and exit:

scan off        # Stop scanning
exit # Exit bluetoothctl

4.1.2 Non-Interactive Mode

Use the following command to scan for 5 seconds:

timeout 5 bluetoothctl scan on

Take note of your target device's MAC address, for example: 69:7B:B4:A2:ED:A7.

5. Connecting to and Interacting with the BLE Device

Use the gatttool utility to connect to and operate the BLE device.

5.1 List the Device's GATT Services

Command Format:

sudo gatttool -b <MAC_Address> -t random --primary

Example:

sudo gatttool -b 69:7B:B4:A2:ED:A7 -t random --primary

Example Output:

attr handle = 0x0001, end grp handle = 0x0009 uuid: 00001801-0000-1000-8000-00805f9b34fb
attr handle = 0x0014, end grp handle = 0x001a uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle = 0x0028, end grp handle = 0x002e uuid: 0000fdaa-0000-1000-8000-00805f9b34fb
attr handle = 0x002f, end grp handle = 0x0034 uuid: 0000fcc0-0000-1000-8000-00805f9b34fb
attr handle = 0x0035, end grp handle = 0xffff uuid: a645f9d8-e2e2-4faa-a910-aab5c27b87b1

Service Descriptions:

  • 00001801-0000-1000-8000-00805f9b34fb: GATT Service (Generic Attribute)

  • 00001800-0000-1000-8000-00805f9b34fb: GAP Service (Generic Access Profile)

  • a645f9d8-e2e2-4faa-a910-aab5c27b87b1: Our custom service.

5.2 List All Device Characteristics

sudo gatttool -b 69:7B:B4:A2:ED:A7 -t random --characteristics

Example Output:

handle = 0x0002, char properties = 0x20, char value handle = 0x0003, uuid = 00002a05-0000-1000-8000-00805f9b34fb
handle = 0x0004, char properties = 0x02, char value handle = 0x0005, uuid = 00002b3a-0000-1000-8000-00805f9b34fb
...
handle = 0x0036, char properties = 0x0a, char value handle = 0x0037, uuid = b8f4c163-2de7-4096-83d4-83a69f633e09

Characteristic Properties Explained:

  • 0x02: Read

  • 0x04: Write Without Response

  • 0x08: Write

  • 0x0a: Read + Write

  • 0x0c: Write + Write Without Response

  • 0x10: Notify

Record the char value handle of the characteristic you want to interact with. In our case, it is 0x0037 for our custom read/write characteristic (b8f4c163...).

5.3 Read a Characteristic

5.3.1 Read the Custom Characteristic

sudo gatttool -b 69:7B:B4:A2:ED:A7 -t random --char-read -a 0x0037

Output:

Characteristic value/descriptor: 52 65 61 64 79

Convert HEX to ASCII:

The value 52 65 61 64 79 is the hexadecimal representation of the string "Ready".

echo "52 65 61 64 79" | xxd -r -p
Ready

5.4 Write to a Characteristic

5.4.1 Write "Run" to the Custom Characteristic

First, convert the string "Run" to its hexadecimal representation:

printf "Run" | xxd
00000000: 5275 6e Run

The HEX value is 52756e.

Now, execute the write command:

sudo gatttool -b 69:7B:B4:A2:ED:A7 -t random --char-write-req -a 0x37 -n 52756e

Output:

Characteristic value was written successfully

Verification in nRF Connect:

On the BLE connection page in the nRF Connect app, you can now see that the value of the custom characteristic has been updated.

6. Troubleshooting

6.1 Bluetooth Module Not Starting (EG5200)

Symptom: hciconfig shows no output or the device is DOWN.

Solution:

# 1. Check the module enable status (EG5200 only)
cat /sys/class/gpio/gpio1/value # Should return 1

# 2. If it returns 0, re-enable it
sudo sh -c 'echo 1 > /sys/class/gpio/gpio1/value'

# 3. Re-attach the HCI interface and bring it up
sudo hciattach /dev/ttymxc3 qca -t120 3000000 flow
sudo hciconfig hci0 up

6.2 Cannot Scan/Find the nRF Connect Device

Possible Causes & Solutions:

  1. nRF Connect is Not Advertising:
  • Ensure the ADVERTISER switch is enabled in the nRF Connect app.

  • Confirm that Bluetooth is enabled on your phone.

  1. Distance or Signal Interference:
  • Move the phone closer to the RobustOS Pro device (within 1-2 meters).

  • Move away from sources of interference like Wi-Fi routers.

  1. Permission Issues:
  • Ensure you are using sudo to execute scan commands.
  1. Bluetooth Service Not Running:
  • Check and restart the Bluetooth service on the RobustOS Pro device.
sudo systemctl status bluetooth
sudo systemctl restart bluetooth

6.3 gatttool Connection Fails

Error Message: connect error: No route to host or Connection refused.

Solution:

  1. Verify the MAC Address:
  • The random MAC address used by nRF Connect can change.

  • If you stop and restart advertising, the MAC address will likely change.

  • Perform a new scan to get the latest MAC address.

  1. Use the -t random Parameter:
  • nRF Connect uses a random address type. You must specify this with gatttool.
# Incorrect: Missing address type parameter
sudo gatttool -b 58:9E:35:ED:FD:B3 --primary

# Correct: Specify random address type
sudo gatttool -b 58:9E:35:ED:FD:B3 -t random --primary
  1. Device is Already Connected:
  • A BLE peripheral can typically only be connected to one central device at a time.

  • Disconnect any other devices that might be connected to your nRF Connect peripheral and try again.

  1. Bluetooth Controller State Issue:
  • Reset the Bluetooth controller on the RobustOS Pro device.
sudo hciconfig hci0 down
sudo hciconfig hci0 up

6.4 Failed to Read/Write Characteristic

Error Message: Characteristic value read failed or Write failed.

Solution:

  1. Confirm the Handle is Correct:
  • Re-run the --characteristics command to list all characteristics.

  • Ensure you are using the **

char value handle

**, not the base handle.

  1. Check Characteristic Permissions:
  • You cannot write to a read-only characteristic.

  • You cannot read from a write-only characteristic.

  • Check the properties field for the characteristic to confirm its permissions (e.g., 0x0a for Read/Write).

  1. Incorrect Data Format (for Writes):
  • Ensure the value you are writing is in HEX format (e.g., 48656c6c6f).

  • Do not include spaces or other separators in the HEX string.

  • Use the -n parameter to specify the HEX data.

6.5 Viewing Detailed Logs

To see low-level HCI packet exchanges for debugging, use the btmon tool.

Start the Bluetooth monitoring tool in one terminal:

sudo btmon

In a second terminal, execute your gatttool commands. The btmon terminal will display all HCI data packet interactions in real-time.

7. Conclusion 

A Robustel gateway running RobustOS Pro is correctly configured for testing Bluetooth Low Energy with nRF Connect when the gateway discovers the simulated device and completes the intended GATT read or write. This confirms both BLE discovery and characteristic-level communication.