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

  • I will improve the lib in this aspect. Would there be a chance to get your firmware and app for testing?

  • Let me clean some stuff up before I send you something. However I am expecting to see the problem with your example Glucose app as the Peripheral and the corresponding receiver in the nRF Toolbox. Get the two bonded, then disable BLE on the phone, then get many readings pending in the Peripheral, then turn BLE back on. The Peripheral will then send all its readings as notifications quickly. As my code is derived from the Glucose app within nRF Toolbox, I think I will see the same problem. But perhaps not!

  • It has proved quite complex to get quality evidence. However I have some results, running a slightly modified version Nordic's Glucose App running on the PCA10040 dev kit, and two versions of nRF Toolbox, on three Android devices. I have used nRF Logger to view activity. In my experiments I simulate 0, 1, 2, 3, 4 and 5 glucose readings and download these (as Notifications) to nRF Toolkit by pressing the "ALL" button.

    There is no fault with the nRF Toolbox downloaded from Play Store, on any device.

    If I rebuild the Develop branch of nRF Toolbox from Github then I get different, incorrect, results, depending on which device I use.

    With my Samsung Phone (Android 8), nRF Logger shows that all the Notifications contain the same payload. In every case the payload is of the final notification (determined by the "Sequence Number" which increments with each glucose reading).

    With both tablets (Android 7), nRF Logger shows that the Notifications contain the correct payloads. However the nRF Toolbox misbehaves. The toast messages in nRF Toolbox are correct, but reading data is not displayed properly. When the peripheral has one record it is always displayed. When it has more than one record, records are almost always NOT displayed (I see "No values to display"). But very occasionally the readings are displayed correctly.

    So: two bugs, or two manifestations of the same bug.

    I can provide a more detailed report and nRF Logger files, if you want these.

  • Hi, I've just pushed some changes to nRF Toolbox. The master branch is not using BLE library 2.0. Also, I've fixed an issue with GLS, but that was related only to UI and refreshing the table. I've also updated BLE lib dependency from beta5 to final version, but the fix seems to be already there (https://github.com/NordicSemiconductor/Android-BLE-Library/commit/e5e054b5952ce6c85798895c8c84f973cf58a624). Nevertheless, I've tested with 20 notifications and they are all displayed on Pixel 2.

Related