Open sleven79 opened 5 years ago
Hmm, unfortunately, the simple change that I proposed in the pull request has not been considered for the latest release of the extension. The bug is still alive.
@sleven79 There are a lot of changes in #27 that seem beyond the solution you've proposed here. If you want to clean up that PR to update the descriptor accordingly, that would be fine. We may want to balance the number of calls to RegisterForX(service, characteristic) and UnregisterForValues(service, characteristic) so that we only reset the notification flag once all existing registrations have been unwound.
Note that there is no call to "gatt.writeDescriptor()" in the "unsubscribe" function called by the "UnregisterForValues" function of the BluetoothLE extension. This means that while the callback gets disabled and the App Inventor app does not receive any notifications from the BLE device any more, the BLE device still generates notifications in the background. The notification bit in the corresponding CCCD on the BLE device has not been cleared.
This is probably not the intended behavior. As BLE devices often try to save power wherever possible, being able to disable notifications on the device is important.
Note that the call to "gatt.writeDescriptor()" is used as expected in the "subscribe" function called by the "RegisterForX" functions of the BluetoothLE extension. Notifications are enabled by a write request to the corresponding CCCD.
I suggest to review the internals of the "unsubscribe" function and to include a call to "gatt.writeDescriptor()" such as to disable the notification bit in the CCCD.