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.

  • I'm trying to get a sniffer trace as well but not sure if I'm getting the full connection details. So far I can see the advertising and connection request. After that nothing. I'm using just works pairing no bonding etc.

    Here's my filter:

    (btle.advertising_address == e7:60:41:d9:f2:72) || (btle.initiator_address == 55:44:8b:f6:98:3e)

    If there's a better way to filter please let me know:

    1401.capture.pcapng

  • 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

Reply Children
  • 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

  • Hi,

    This wont build because of some missing dependencies. Then I attempted to check out using west init -m github.com/.../air-quality-wing-zephyr-demo.git && west update instead to get everything, but I get  Permission denied for the air-quality-wing-drivers.

  • You need to checkout the correct branch Einar. I did leave out initializing the repository. (west init -l .) I did find one build issue but it wasn't related to the drivers repo. Are you set up with Github on SSH? The repo in question is public. Here's the public link for your reference: github.com/.../air-quality-wing-zephyr-drivers

    I did a force push on the main repo so you may need to reset to origin/main before pulling more changes.

  • Hi,

    I get the same with the bt-debug branch, following the exact instructions from your previous post:

    === updating air-quality-wing-drivers (aqw):
    --- air-quality-wing-drivers: initializing
    Initialized empty Git repository in C:/Users/eith/Downloads/case_276243/aqw/.git/
    --- air-quality-wing-drivers: fetching, need revision main
    [email protected]: Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    FATAL ERROR: command exited with status 128: fetch -f --tags -- [email protected]:circuitdojo/air-quality-wing-zephyr-drivers.git main

    I have not had time to look more closely at getting the project checked out today.

Related