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!

Parents
  • Hello,

    Yes, this seems to be the same issue as in this thread. That is currently ongoing, but a workaround has been suggested in this post.

  • Thanks!

    I increase SDC_DEFAULT_TX_PACKET_COUNT but still am having the issue. I'm using a nRF52840 not and nRF53. (not sure if that makes a difference here). 

    The value for the characteristic 12340005 still shows up in characteristic 12340004's value. 12340005 still shows up N/A like the above screenshot.

  • 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?

  • https://github.com/circuitdojo/air-quality-wing-zephyr-demo/tree/bt-debug

    Build with the following:

    git clone https://github.com/circuitdojo/air-quality-wing-zephyr-demo.git
    cd air-quality-wing-zephyr-demo
    git checkout bt-debug
    west init -l .
    west update
    cd demo/ble
    west build -b nrf52840dk_nrf52840
    nrfjprog --program build/zephyr/merged.hex --chiperase --reset

    You can run this on a nRF52840 DK no problem. 

    I then subscribe to all the characteristics. The application *should* send a value of 0-3 to each of the values in nRF Connect App, but it goes 0, 1, 3, null. (Basically the same as explained above)

    Thanks

Reply Children
Related