Using BLE Demo with the NAVQ Plus Linux BSP

This application note explains how to use a BLE demo with the NAVQ Plus Linix BSP.

The NAVQ Plus Linix BSP contains several BLE demos located in the ml_ble_platform project.

BLE demos use a similar communications protocol for sending commands and receiving responses:

  • Commands are sent by writing to TX characteristic with UUID=813dd366-179e-11eb-b214-a3729d689162 and the value handle=0x15;

  • The demo responds to a command by sending notifications in RX characteristic with UUID=89accce6-179e-11eb-a4b6-e3d7b2402624 and value handle=0x17.

In this application note the ml_ble_platform/sensor_base demo is used as an example. This application provides a platform for supporting external sensors and logging raw sample values over BLE. IMU readings are sent as notifications on ACC_SAMPLES (UUID=110d8470-2eb3-11eb-bf0c-8ff42f5dc2bc and value handle=0x1d) characteristic value change. Refer to “ML_BLE_Platform BLE Interface Specification” for more information.

1. Uploading a BLE Demo to the Target

BLE demos included in the NAVQ Plus Linix BSP consist of two parts: the bootloader and a working (“mission“) firmware.

Bootloader binaries are located in the build/core_drivers_ble_v3p2/CMakeProjects/bootloader directory:

ls -l build/core_drivers_ble_v3p2/CMakeProjects/bootloader total 44 -rwxrwxr-x 1 user user 260 Nov 15 00:15 bootloader.bin -rwxrwxr-x 1 user user 6080 Nov 15 00:15 bootloader.elf drwxrwxr-x 3 user user 4096 Nov 24 19:53 CMakeFiles -rw-rw-r-- 1 user user 1029 Nov 15 00:14 cmake_install.cmake -rw-rw-r-- 1 user user 6260 Nov 15 00:14 Makefile -rw-rw-r-- 1 user user 3969 Nov 15 00:15 objdump.txt -rw-rw-r-- 1 user user 4242 Nov 15 00:15 readelf.txt -rw-rw-r-- 1 user user 856 Nov 15 00:15 symbol.txt

Refer to for more information.

Perform the following steps to upload the demo to the target:

  1. Sync the Telink programmer with the target:

    sudo tcdb 9518 sws
  2. Program the bootloader with the 0 offset:

    sudo tcdb 9518 wf 0 -i ./bootloader.bin -b
  3. Program the demo binary with the 1000 offset:

  4. Reset the target.

2. Checking a Local Interface

  1. Verify that a local interface is detected with hcitool:

    Follow the instructions provided in application note if a local interface is not detected by hcitool.

  2. Check a local interface status and switch it on if it is disabled:

3. Scanning for Remote Devices and Pairing

The default device name in the ml_ble_platform/sensor_base demo is AZN1-EVB. This name can be changed in the source files or by sending a command over BLE.

3.1. Scanning for Remote Devices with hcitool

Run sudo hcitool lescan to start scanning for LE devices:

3.2. Scanning for Remote Devices and Pairing Using bluetoothctl

  1. Open bluetoothctl:

  2. Scan for available remote devices with the scan le command:

    The list of remote devices can be printed using the devices command:

  3. Use the pair <BD address> command to initiate pairing:

4. Communicating with the BLE Demo

4.1. Communicating with the BLE Demo Using gatttool in an Interactive Mode

  1. Open gatttool in an interactive mode:

  2. Connect to the device:

  3. The characteristics list can be printed using the characteristics command:

  4. To send commands to the target, write to the TX characteristic using the char-write-req or the char-write-cmd command. A response from the demo is received as a notification on RX characteristic value change.
    To read a device name send the sys device-name=? command:

    To set a new name use the sys device-name=<new name> command.

    To enable IMU sample streaming send the acc set_config, acc stream-on, and acc stream-on commands:

    After that notifications with IMU samples are being received:

    In the notification value the first 4 bytes are a timestamp, the next 2 bytes are a sequence number and the last 12 bytes are IMU samples.

4.2. Communicating with the BLE Demo Using gatttool in a Non-Interactive Mode

In a non-interactive mode gatttool connects to the target automatically, executes a requested command, and disconnects from the target.

Use --char-write-req -a <characteristic value handle> -n <value> to write to characteristic. Use the --listen flag to prevent disconnecting from the target.

  • To read a device name execute the following command:

  • To enable IMU sample streaming execute the following commands:

Note: To send a command convert it to a hex-string without any quotes or the 0x prefix. Gatttool outputs also receive notification values as hex value arrays.

4.3. Useful Commands

Here are some useful commands for communicating with BLE demo:

Command

Gatttool command

Description

Command

Gatttool command

Description

sys fw-ver

char-write-req 0x15 7379732066772d7665720a

Device firmware version request

sys device-name=?

char-write-req 0x15 737973206465766963652d6e616d653d3f0a

Device name request

sys log-lvl=0

char-write-req 0x15 737973206c6f672d6c766c3d300a

Set system debug output verbosity (0 - disabled, 3 - max level)

acc log-lvl=0

char-write-req 0x15 616363206c6f672d6c766c3d300a

Set IMU debug output verbosity

tmp log-lvl=0

char-write-req 0x15 746d70206c6f672d6c766c3d300a

Set temp sensor debug output verbosity

sys log-lvl=?

char-write-req 0x15 737973206c6f672d6c766c3d3f0a

Current system debug output verbosity request

acc log-lvl=?

char-write-req 0x15 616363206c6f672d6c766c3d3f0a

Current IMU debug output verbosity request

tmp log-lvl=?

char-write-req 0x15 746d70206c6f672d6c766c3d3f0a

Current temp sensor debug output verbosity request

acc set_config

char-write-req 0x15 616363207365745f636f6e6669670a

Configure IMU

acc start

char-write-req 0x15 6163632073746172740a

Enable IMU

acc stop

char-write-req 0x15 6163632073746f70200a

Disable IMU

acc stream-on

char-write-req 0x15 6163632073747265616d2d6f6e0a

Enable IMU sample streaming

acc stream-off

char-write-req 0x15 6163632073747265616d2d6f66660a

Disable IMU sample streaming

tmp set_config

char-write-req 0x15 746d70207365745f636f6e6669670a

Configure temp sensor

tmp start

char-write-req 0x15 746d702073746172740a

Enable temp sensor

tmp stop

char-write-req 0x15 746d702073746f700a

Disable temp sensor

tmp stream-on

char-write-req 0x15 746d702073747265616d2d6f6e0a

Enable temp sensor sample streaming

tmp stream-off

char-write-req 0x15 746d702073747265616d2d6f66660a

Disable temp sensor sample streaming