micropython / micropython/micropython-lib

aioble drops notifications

Open
#934 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
2.9k
Forks
1.1k
Avg merge
7d 6h
Merged PRs (30d)
3

Description

A glucose meter following the BT-SIG profile only stores measurements which must be retrieved by a Record Access Control Point (RACP) transaction. With aioble one is faced with the challenge of invoking the RACP transaction to transfer the data which causes the device to notify its stored data records. When all have been notified an indication is sent on the RACP characteristic.

One can see the challenge here - there are two nested await operations. Clearly impossible without placing one of these in a task.
Thus the RACP action to transfer is placed in a task.
Then one can write the command on the RACP characteristic.
Follow with a while loop that runs until the task completes (indication received)
The while loop has two consecutive await actions, one on the Glucose Measurement characteristic notification followed by the await on the Glucose Context Measurement characteristic notification. Fortunately the response of the Glucose Measurement Notification has a flag indicating if there is a following context measurement.

The issue is that these notifications are sent basically as fast as the device can dump them. So a log looks like this for a case with 3 stored measurements from a Roche Accu-chek Guide:

2024-11-05 00:16:30 DEBUG bt_sig_glucose: LNI: Number of stored measurements b'\x05\x00\x03\x00'
                                                                           // the 05, 00 indicates success and the 03, 00 is the number of msmts (little endian)
2024-11-05 00:16:30 DEBUG bt_sig_glucose: LNI: Task to wait for RACP indication started 
2024-11-05 00:16:30 DEBUG bt_sig_glucose: LNI: Send RACP command to transfer all records
LNI: AIOBLE: Notify received
LNI: AIOBLE: Notify received
LNI: AIOBLE: Notify received
LNI: AIOBLE: Notify received
LNI: AIOBLE: Notify received
LNI: AIOBLE: Notify received
LNI: AIOBLE: Indication received
2024-11-05 00:16:30 DEBUG bt_sig_glucose: LNI: Waiting for msmts
2024-11-05 00:16:30 DEBUG bt_sig_glucose: LNI: RACP indication: b'\x06\x00\x01\x01'.  // Indicates successful RACP transfer all
2024-11-05 00:16:30 DEBUG bt_sig_glucose: LNI: 1b 3b 00 e6 07 08 05 14 08 19 28 1b 2f b0 f8 00 08
2024-11-05 00:16:30 DEBUG bt_sig_glucose: LNI: 02 3b 00 01
2024-11-05 00:16:31 DEBUG bt_sig_glucose: LNI: Waiting for msmts
2024-11-05 00:16:31 DEBUG bt_sig_glucose: LNI: Exiting RACP task.

All the notifications are lost or overwritten by the aioble library except the last two (a single stored measurement contains both a measurement notification and measurement context notification.

Why is aioble losing all these notifications? Is the only way to rescue this problem to write code that intercepts the notification and puts them into an application queue? The aioble queue is clearly overwritten or at least they are not dumped by the *.notified() method as expected: msmt: bytes = await asyncio.wait_for(msmt_char.notified(), 1.0)

I tried the reverse as well - placing the notification handler in a task and invoking the racp commands 'outside'. I also added prints of the received notification bytes at the aioble level. I get the same result:

2024-11-05 11:36:12 DEBUG bt_sig_glucose: LNI: Number of stored measurements b'\x05\x00\x03\x00'
2024-11-05 11:36:12 DEBUG bt_sig_glucose: LNI: Waiting for msmts
2024-11-05 11:36:12 DEBUG bt_sig_glucose: LNI: Send RACP command to transfer all records
LNI: AIOBLE: Notify received 1b 39 00 e4 07 07 1f 0b 2e 09 00 00 8d b0 f8 00 00
LNI: AIOBLE: Notify received 02 39 00 02
LNI: AIOBLE: Notify received 1b 3a 00 e4 07 0b 04 0f 25 02 00 00 93 b1 f8 00 00
LNI: AIOBLE: Notify received 02 3a 00 01
LNI: AIOBLE: Notify received 1b 3b 00 e6 07 08 05 14 08 19 28 1b 2f b0 f8 00 08
LNI: AIOBLE: Notify received 02 3b 00 01
LNI: AIOBLE: Indication received
2024-11-05 11:36:12 DEBUG bt_sig_glucose: LNI: 1b 3a 00 e4 07 0b 04 0f 25 02 00 00 93 b1 f8 00 00
2024-11-05 11:36:12 DEBUG bt_sig_glucose: LNI: RACP indication: b'\x06\x00\x01\x01'.
2024-11-05 11:36:12 DEBUG bt_sig_glucose: LNI: RACP transfer-all task completed. Disconnecting.
LNI: Setting to disconnected
LNI: AIOBLE: Peripheral disconnect. Handle 64
2024-11-05 11:36:12 DEBUG bt_sig_glucose: LNI: 02 3b 00 01

But now it is clearer to see that the first 4 notifications are dropped.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing aioble's characteristic *.notified() path and notification handling, then reproduce the glucose-meter RACP transfer described in the issue. Verify whether rapid glucose measurement and context notifications are overwritten or left unread; done means the transfer delivers all notifications without requiring an application-level interception queue.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.