This tutorial will guide you through the complete process of:
Simulating a BLE (Bluetooth Low Energy) device on a mobile phone using nRF Connect for Mobile.
Scanning for and connecting to the simulated BLE device from a RobustOS Pro device.
Reading from and writing to the BLE device's characteristics using the GATT protocol.
RobustOS Pro Device: EG5100, EG5120, EG5200, or EV8100 (models with a Bluetooth module).
Android or iOS Device: To run the nRF Connect for Mobile application.
Install the nRF Connect for Mobile app on your phone:
Android: [Google Play Store]
iOS: [App Store]
On your RobustOS Pro device, execute the following command:
sudo renv get board
Example output: eg5120, eg5100, eg5200, ev8100, etc.
Open the nRF Connect for Mobile app on your phone.
Grant the necessary Bluetooth and location permissions when prompted.
Tap the hamburger menu (☰) in the top-left corner and select "Configure GATT Server".
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.
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.
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.
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 Options.
Tap the edit icon in the top-right corner to change the BLE peripheral's name.
Toggle the switch to start advertising your simulated BLE peripheral.
Follow these steps on your RobustOS Pro device to enable the Bluetooth module.
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
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
EV8100:
sudo hciattach /dev/ttymxc1 any 115200 flow
sudo hciconfig hci0 up
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
...
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
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.
Use the gatttool utility to connect to and operate the BLE device.
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.
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...).
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
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.
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
Possible Causes & Solutions:
Ensure the ADVERTISER switch is enabled in the nRF Connect app.
Confirm that Bluetooth is enabled on your phone.
Move the phone closer to the RobustOS Pro device (within 1-2 meters).
Move away from sources of interference like Wi-Fi routers.
sudo systemctl status bluetooth
sudo systemctl restart bluetooth
Error Message: connect error: No route to host or Connection refused.
Solution:
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.
# 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
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.
sudo hciconfig hci0 down
sudo hciconfig hci0 up
Error Message: Characteristic value read failed or Write failed.
Solution:
Re-run the --characteristics command to list all characteristics.
Ensure you are using the **
char value handle
**, not the base handle.
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).
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.
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.