This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Sending multiple bluetooth notifications in quick succession (nRF Connect SDK 1.6.1)

Hey all,

I've run into an interesting situation where writing multiple notifications to successively to a multi-characteristic (custom) service causes data loss. Look like it may be similar to the case here: https://devzone.nordicsemi.com/f/nordic-q-a/77381/sending-multiple-notify-packets-per-connection-interval

The service is defined here. All characteristics have unique UUIDs (See below)

#define BT_UUID_ENV_TEMPERATURE_VAL \
    BT_UUID_128_ENCODE(0x12340002, 0xb5a3, 0xf393, 0xe0a9, 0xe50e24dcca9e)
#define BT_UUID_ENV_HUMIDITY_VAL \
    BT_UUID_128_ENCODE(0x12340003, 0xb5a3, 0xf393, 0xe0a9, 0xe50e24dcca9e)
#define BT_UUID_ENV_C02_VAL \
    BT_UUID_128_ENCODE(0x12340004, 0xb5a3, 0xf393, 0xe0a9, 0xe50e24dcca9e)
#define BT_UUID_ENV_PRESURE_VAL \
    BT_UUID_128_ENCODE(0x12340005, 0xb5a3, 0xf393, 0xe0a9, 0xe50e24dcca9e)

Here's how they're defined (along with some other characteristics)

BT_GATT_SERVICE_DEFINE(env_service,
                       BT_GATT_PRIMARY_SERVICE(BT_UUID_ENV_SERVICE),
                       BT_GATT_CHARACTERISTIC(BT_UUID_ENV_TEMPERATURE, BT_GATT_CHRC_NOTIFY,
                                              BT_GATT_PERM_NONE, NULL, NULL, NULL),
                       BT_GATT_CCC(env_ccc_cfg_changed,
                                   BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
                       BT_GATT_CHARACTERISTIC(BT_UUID_ENV_HUMIDITY, BT_GATT_CHRC_NOTIFY,
                                              BT_GATT_PERM_NONE, NULL, NULL, NULL),
                       BT_GATT_CCC(env_ccc_cfg_changed,
                                   BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
                       BT_GATT_CHARACTERISTIC(BT_UUID_ENV_C02, BT_GATT_CHRC_NOTIFY,
                                              BT_GATT_PERM_NONE, NULL, NULL, NULL),
                       BT_GATT_CCC(env_ccc_cfg_changed,
                                   BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
                       BT_GATT_CHARACTERISTIC(BT_UUID_ENV_PRESSURE, BT_GATT_CHRC_NOTIFY,
                                              BT_GATT_PERM_NONE, NULL, NULL, NULL),
                       BT_GATT_CCC(env_ccc_cfg_changed,
                                   BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
                       BT_GATT_CHARACTERISTIC(BT_UUID_ENV_AQ, BT_GATT_CHRC_NOTIFY,
                                              BT_GATT_PERM_NONE, NULL, NULL, NULL),
                       BT_GATT_CCC(env_ccc_cfg_changed,
                                   BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
                       BT_GATT_CHARACTERISTIC(BT_UUID_ENV_PH, BT_GATT_CHRC_NOTIFY,
                                              BT_GATT_PERM_NONE, NULL, NULL, NULL),
                       BT_GATT_CCC(env_ccc_cfg_changed,
                                   BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
                       BT_GATT_CHARACTERISTIC(BT_UUID_ENV_EC, BT_GATT_CHRC_NOTIFY,
                                              BT_GATT_PERM_NONE, NULL, NULL, NULL),
                       BT_GATT_CCC(env_ccc_cfg_changed,
                                   BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
                       BT_GATT_CHARACTERISTIC(BT_UUID_ENV_WT, BT_GATT_CHRC_NOTIFY,
                                              BT_GATT_PERM_NONE, NULL, NULL, NULL),
                       BT_GATT_CCC(env_ccc_cfg_changed,
                                   BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
                                   );

I get no errors when sending and the data shows up ok in the console:

[00:00:16.136,016] <inf> app_ble_service_env: Env service notifications enabled
[00:00:17.208,557] <inf> app_ble_service_env: Env service notifications enabled
[00:00:18.281,066] <inf> app_ble_service_env: Env service notifications enabled
[00:00:19.841,094] <inf> app_ble_service_env: Env service notifications enabled
[00:00:36.554,168] <inf> fluidd_sensors: Fetching Sensor Data Now
[00:00:36.556,335] <inf> fluidd_sensors: Temp: 28.190000
[00:00:36.556,335] <inf> fluidd_sensors: raw hex: 
                                         1c 00 00 00 30 e6 02 00                          |....0...         
[00:00:36.558,532] <inf> fluidd_sensors: Humidity: 51.497000
[00:00:36.558,532] <inf> fluidd_sensors: raw hex: 
                                         33 00 00 00 68 95 07 00                          |3...h...         
[00:00:36.559,387] <inf> fluidd_sensors: C02: 993.0
[00:00:36.559,387] <inf> fluidd_sensors: raw hex: 
                                         e1 03 00 00 00 00 00 00                          |........         
[00:00:36.561,553] <inf> fluidd_sensors: Pressure: 101.5000
[00:00:36.561,645] <inf> fluidd_sensors: raw hex: 
                                         65 00 00 00 88 13 00 00                          |e.......  

When received on the phone side, the first two characteristics usually show up correctly (right data). But the last subscribed characteristic receives the wrong data. I'm assuming there are some limits here (max notifications per interval?) If there's a way to work around this that'd be fantastic.

Here's the data on the phone side using nRF Connect on iOS:

Thanks!

  • Hi,

    What we are interested here happens in the connection, so the sniffer must follow the connection to be useful. I see you use the nRF Sniffer. It sometimes has problems following connections, but it is possible. You may need a few attempts for it to work as the sniffer could miss the connection establishment. See nRF Sniffer usage.

  • Got it! See the attached.

    Connected.
    [00:13:06.838,439] <inf> fluidd_sensors: Fetching Sensor Data Now
    [00:13:06.840,606] <inf> fluidd_sensors: Temp: 26.360000
    [00:13:06.840,606] <inf> fluidd_sensors: raw hex: 
                                             1a 00 00 00 40 7e 05 00                          |....@~..         
    [00:13:06.842,803] <inf> fluidd_sensors: Humidity: 58.459000
    [00:13:06.842,803] <inf> fluidd_sensors: raw hex: 
                                             3a 00 00 00 f8 00 07 00                          |:.......         
    [00:13:06.843,658] <inf> fluidd_sensors: C02: 1375.0
    [00:13:06.843,658] <inf> fluidd_sensors: raw hex: 
                                             5f 05 00 00 00 00 00 00                          |_.......         
    [00:13:06.845,825] <inf> fluidd_sensors: Pressure: 102.18000
    [00:13:06.845,855] <inf> fluidd_sensors: raw hex: 
                                             66 00 00 00 50 46 00 00                          |f...PF..         
    [00:13:36.845,947] <inf> fluidd_sensors: Fetching Sensor Data Now
    [00:13:36.848,114] <inf> fluidd_sensors: Temp: 26.370000
    [00:13:36.848,114] <inf> fluidd_sensors: raw hex: 
                                             1a 00 00 00 50 a5 05 00                          |....P...         
    [00:13:36.850,311] <inf> fluidd_sensors: Humidity: 58.580000
    [00:13:36.850,311] <inf> fluidd_sensors: raw hex: 
                                             3a 00 00 00 a0 d9 08 00                          |:.......         
    [00:13:36.851,165] <inf> fluidd_sensors: C02: 1364.0
    [00:13:36.851,165] <inf> fluidd_sensors: raw hex: 
                                             54 05 00 00 00 00 00 00                          |T.......         
    [00:13:36.853,332] <inf> fluidd_sensors: Pressure: 102.18000
    [00:13:36.853,363] <inf> fluidd_sensors: raw hex: 
                                             66 00 00 00 50 46 00 00                          |f...PF..         
    [00:14:06.853,454] <inf> fluidd_sensors: Fetching Sensor Data Now
    [00:14:06.855,621] <inf> fluidd_sensors: Temp: 26.380000
    [00:14:06.855,621] <inf> fluidd_sensors: raw hex: 
                                             1a 00 00 00 60 cc 05 00                          |....`...         
    [00:14:06.857,818] <inf> fluidd_sensors: Humidity: 58.379000
    [00:14:06.857,818] <inf> fluidd_sensors: raw hex: 
                                             3a 00 00 00 78 c8 05 00                          |:...x...         
    [00:14:06.858,673] <inf> fluidd_sensors: C02: 1362.0
    [00:14:06.858,673] <inf> fluidd_sensors: raw hex: 
                                             52 05 00 00 00 00 00 00                          |R.......         
    [00:14:06.860,839] <inf> fluidd_sensors: Pressure: 102.16000
    [00:14:06.860,870] <inf> fluidd_sensors: raw hex: 
                                             66 00 00 00 80 3e 00 00                          |f....>..         
    [00:14:36.860,961] <inf> fluidd_sensors: Fetching Sensor Data Now
    [00:14:36.863,128] <inf> fluidd_sensors: Temp: 26.380000
    [00:14:36.863,128] <inf> fluidd_sensors: raw hex: 
                                             1a 00 00 00 60 cc 05 00                          |....`...         
    [00:14:36.865,325] <inf> fluidd_sensors: Humidity: 58.424000
    [00:14:36.865,325] <inf> fluidd_sensors: raw hex: 
                                             3a 00 00 00 40 78 06 00                          |:...@x..         
    [00:14:36.866,180] <inf> fluidd_sensors: C02: 1358.0
    [00:14:36.866,180] <inf> fluidd_sensors: raw hex: 
                                             4e 05 00 00 00 00 00 00                          |N.......         
    [00:14:36.868,347] <inf> fluidd_sensors: Pressure: 102.16000
    [00:14:36.868,377] <inf> fluidd_sensors: raw hex: 
                                             66 00 00 00 80 3e 00 00                          |f....>..    

    full-connection.pcapng.gz

  • Hi,

    There are a few things that seems odd. At #100 in the trace there is no handle 0x15, but it is used later.

    and where there are notifications to handle 0x0016 the sniffer complains about illegal use of this characteristic (0x12340003):

    I do not immediately see what though, unfortunately.

  • Hi Einar, 

    Are you going to escalate this with the dev team? It's a core piece of the BLE stack that needs to work.

    Let me know if you need anything else from me to expedite. 

    Jared

  • HI Jared,

    I agree this needs to work but it is not clear what happens here or where the issue resides, and I have not found any other references to this exact behavior. Can you share a complete but minimal example project that reproducer this issue so that I can test on my side?

Related