Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Frequency of Notifications with Android BLE Library

I am working on a derivative of the Glucose sensor code from nRF Toolbox. The sensor peripheral accumulates a number of readings. The central  sends a command to the Record Access Control Point characteristic asking for the readings. The peripheral sends the requested data as a sequence of Notifications from the Glucose Measurement Characteristic, then sends a status message as an Indication from the Record Access Control Point characteristic.

For a small number of readings this works as expected: I see the Notifications arriving at the central (in the Notification callback code onDataReceived() ).

However, I find that when the number of characteristics exceed about 6, the central stops receiving the Notifications. The peripheral hangs up as it sends the Notification AFTER the last one received by the central.

If I insert a delay of about 8ms on my device, to throttle the Notification stream, then it starts working again. I am doing some work on the incoming Notification data (checking validity) then add it to an Array List for later processing, so probably not spending a huge amount of time.

The question is whether there are limitations at the central on the rate at which it can receive Notifications. Are Notifications queued by the OS? Do I need to do somewthing with threads? etc.

I get the same result with two tablets running Android 7.

Parents
  • Hi again

    You should be getting all notifications in the order they were sent. The limit how fast notifications can be sent and received is build into Att protocol, so the sender doesn't send more then it can, and the received doesn't confirm more then it can handle.

    Are you using the Ble Library v2 (nRF Toolbox from *develop* branch)?

  • Hi Aleksander

    I would like to press you further on this. While my code has changed (on both Peripheral and Central) since my earlier post, I am still seeing unexpected results - somewhat different from above but possibly with the same root cause. The top-level question is, can Nordic's Android library cope with a rapid succession of Notifications?

    Today I see correct operation with two tablets (Asus and Acer, Android 7, with no delay added between Notifications at the Peripheral end). But with a Samsung phone (Android 8), when I attempt to transfer 5 notifications in quick succession:

     - With no added delay between Notifications, the phone receives 5 notifications, but the payload of earlier Notifications have been lost and are replaced by the payload of later Notifications.  Example: each payload includes a sequence number. The BLE peripheral sends sequence numbers 300, 301, 302, 303, 304 but the app on the phone receives 302, 302, 302, 304, 304. The messages in nRF Logger show the same payload data. It looks as though the events are happening too quickly and some variables are being over-written before their contents are picked up by my own application code (and nRF Logger).

    - I have to add a delay of 50ms between Notification transmissions (on the BLE Peripheral)  before I can get reliable operation.

    I have looked at your source code. Can you tell me if I get this right:

    - The operating system gets a Notification and calls onCharacteristicChanged() in your MainThreadBluetoothGattCallback().

    - You grab the payload and call onCharacteristicChangedSafe() in BleManager.

    - That prints the messages I can see on nRF Logger, and then (somehow) passes the data back to the onDataReceived() callback in my app - which is where I pick up the payload and process it. But it looks like by the time I get the callback, earlier data has been overwritten by later data.

    Is there an inherent throughput problem with your library? Or something I need to do at my end so I can process an arbitrarily long sequence of Notifications?

    My build.gradle has this:

    implementation 'no.nordicsemi.android:ble-common:2.0-alpha6'
    implementation 'no.nordicsemi.android:log:2.1.1'
    implementation 'no.nordicsemi.android.support.v18:scanner:1.1.0'

    Thx - Charles

  • Hi Alexsander. It was not entirely clear from your post where you have made changes: both to nRF Toolbox and BLE Library? I assume that changes to BLE Library will be picked up if I collect the latest version of nRF Toolbox? Anyway, that is what I have done (the Master branch). I see some differences, as follows:

    My two Android 7 tablets now seem to be working OK. Notifications are displayed correctly. Thanks. (Though I seem to have a bonding issue: I might post separately on this).

    My Android 8 phone (Samsung AM-A520F, Android 8.0.0, API26) still misbehaves. Exactly one record is displayed by the app (if it has any), regardless of how many are downloaded. Previously one record was displayed if it contained one record, and no records were displayed if it had more than one record. nRF Logger shows that every notification contains the same payload (as before).

    Have you seen the problem with Android 8 devices?

  • I have done further work on this. First: I have bought another tablet: Lenovo TB-710F (Android 8.1.0, API27) and tried it with nRF Toolbox built from Github. That does NOT show the problem (kinda rules out a generic Android 8 fault). So I now have 4 devices all of which work except my Samsung A5 (SM-A520F, Android 8.0.0) phone, and that only fails with the latest version of nRF Toolbox.

    On the Samsung phone I looked at radio RX and TX signal timing and see they are the same with both versions of nRF Toolbox. So we can apparently rule out the problem as being due to some radio timing differences. The version from Playstore collects notifications correctly but the new version returns all notifications containing the same data.

    With the Nordic dev kit containing 20 records (seq. no.s 0-19) I download all and over 3 cycles see notifications with these sequence numbers:
    7, 7, 7, 15, 15, 15, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19
    6, 6, 6, 15, 15, 15, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19
    0, 8, 8, 17, 17, 17, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19

    I have a CSR peripheral which I also load with 20 records (seq. no. 2-21). Notifications received were as follows (slightly different pattern?):
    8, 8, 8, 8, 8, 8, 8, 9, 13, 13, 13, 13, 14, 21, 21, 21, 21, 21, 21, 21
    8, 8, 8, 8, 8, 8, 8, 9, 16, 16, 16, 16, 16, 16, 16, 17, 21, 21, 21, 21
    8, 8, 8, 8, 8, 8, 8, 9, 10, 11, 18, 18, 18, 18, 18, 18, 18, 19, 21, 21

    There is clearly a bug here, but what???? Can you guys find a Samsung A5 phone to look at?

  • Hi Aleksander - is there any chance of a response from Nordic on this? Summary: the "latest" BLE Library returns the wrong Notification data but only on one of my 4 Android devices (Samsung A5). The problem is not present with the earlier BLE Library.

    I think it is a real bug, even if it is obscure.

  • Please report it on GitHub. I'll take it from there. Provide some logs or way to reproduce. I'll try to arrange Samsung a5, but can't guarantee.

  • Is there an update to this?

    I have a similar problem: I want to receive 4 items at about .001 sec intervals. I've used the relevant UART and profile files from GitHub Toolbox app source, but both my custom app and what I think is the latest nordic toolbox UART activity (with log) only show the first, and 3 copies of the last received packet.

    However, the current version of NRF Connect does catch all packets with the right data.

    I've tried debugging both my app and the toolbox with and without nrf connect attached, and the apps show repeated catches, where NRF connect catches correctly (when connected and running).

    I can not get to all devices right now to set a higher delay in broadcasting packets.

    Any suggestions on what is different between NRF Connect and NRF Toolbox?

Reply
  • Is there an update to this?

    I have a similar problem: I want to receive 4 items at about .001 sec intervals. I've used the relevant UART and profile files from GitHub Toolbox app source, but both my custom app and what I think is the latest nordic toolbox UART activity (with log) only show the first, and 3 copies of the last received packet.

    However, the current version of NRF Connect does catch all packets with the right data.

    I've tried debugging both my app and the toolbox with and without nrf connect attached, and the apps show repeated catches, where NRF connect catches correctly (when connected and running).

    I can not get to all devices right now to set a higher delay in broadcasting packets.

    Any suggestions on what is different between NRF Connect and NRF Toolbox?

Children
  • nRF Connect isn't using BLE Library, it has its own implementation. Did you try BLE Library 2.0.4? The latest nRF Toolbox may not be using the latest version. I'll update nrf Toolbox soon.

  • David this sounds like it could be the same bug as I found. However for me the bug only occurs in certain conditions. It would be interesting to know what setup you have. Could you provide extra information:

    (1)   What devices have you tried, and do they all show the same results? (I only see the problem on a Samsung Galaxy A5 phone - no problem seen with 3 other tablets).

    (2)   Can you compare the results of nRF Toolbox downloaded from Play Store with nRF Toolbox re-built from GitHub source code? (I only see problems with the re-built nRF Toolbox; the version downloaded from Play Store works OK. Unfortunately they both report the same version number (2.6.0)).

    If you wanted to replicate my experiments then you could program a PCA10040 development board with the Glucose app here:
    infocenter.nordicsemi.com/index.jsp
    then create some simulated readings and read these using the BGM app within nRF Toolbox. This uses notifications to read the glucose data.

    LATER:

    Aleksander suggests trying BLE Library 2.0.4. This is not straight-forward, as nRF Toolbox uses nRF Common 2.0.0, which uses BLE Library 2.0.0 - however after downloading nRF Common 2.0.0 and BLE Library 2.0.4 and making approprate edits in build.gradle files, nRF Toolbox builds and the bug is fixed!

    IMHO it would be useful if David provides the information (1) and (2) above, then reports on results of using BLE Library 2.0.4. Then it would be good if Aleksander could report that he understands the bug and the fix.

  • Hi! First of all, sorry for the delay. Secondly, sorry for a) not releasing ble-common 2.0.4 (I forgot! will do this asap) and b) not updating nRF Toolbox to ble-common 2.0.4. @Acutetech, thanks for the efforts and testing the code with those mixed up libraries.

Related