NordicSemiconductor / Kotlin-BLE-Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing Notification Sent While Subscribing

WkGl001 opened this issue · comments

Hello,

Thank you for this library. I'm currently using it with a peripheral that has several notify only characteristics. The initial value of the characteristic is sent out by the peripheral as soon as it receives the notification descriptor write request from the central. When using this library, I often find that this notification is received by the device and the library, but that it does not make it to my own code.

Specifically, I call getNotifications on the ClientBleGattCharacteristic object associated with the notify only characteristic. Often, before this function is able to return a Flow and my code is able to collect from it, the peripheral has already sent the initial value notification. The library gets this notification, logs it, and tries to emit it; however, it does not make it to my own code since it has not either received the returned Flow or been able to start collecting from it yet. The notifications field in the ClientBleGattCharacteristic object:

private val _notifications = MutableSharedFlow<DataByteArray>(extraBufferCapacity = 10, onBufferOverflow = BufferOverflow.DROP_OLDEST)

also does not keep any replay cache or expose a way to configure that so I can't go back to get the missed value.

For now, as a workaround, I've used reflection to collect from this private _notifications Flow until I know that the Flow I received from getNotifications has started to collect. Any help from the library on handling this type of situation would be much appreciated.