-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bluetooth Client Characteristic Configuration Descriptor Persistence #160
Comments
My "hack" to work around this involves using the Nordic That shows what I mean by "retrieving the value from the stack" (using |
@bsiever I have experimented with using sd_ble_gatts_value_get() instead of caching the value after a write. On reconnection, the flags read from sd_ble_gatts_value_get() get set before the connection is ready. The member variable CCCD is not quite just a copy of the stack value. It remembers that the client has written to the CCCD since reset. Solely using the stack value causes a problem in the Bluetooth UART service. It starts sending before the connection is ready, encounters a BLE error it doesn't expect, and gets stuck because it doesn't get the confirmation for the packet it thinks it has sent. This occurs on every reboot so it never works a second time. This is really a bug in the UART service, but confirms you're right to be cautious! Maybe a safe way to improve the situation is to allow individual services to turn on direct access to the stack values, or perhaps add an optional mode parameter to specify checking the member variable and/or stack values. Should the characteristic base class handle waiting for the connection to be ready, or should that be left to the individual service? |
@martinwork It's been a while since I looked into this. I think the part that breaks the standard is that the cccds are not restored following a reset. Being retained between connections is ok. Isn't nearly any change to the values in the BLE stack mostly dependent on |
Description of the problem:
The bluetooth specs require the Client Characteristic Configuration Descriptor (CCCD) be persistent across connections for bonded devices (see here). The underlying Nordic stack manages persistence, but this is not propagated back to the CODAL layer on re-connects.
For example,
MicroBitBLEChar
objects' internal states (theircccd
's), so notifications from CODAL won't propagate due to internal state checks (like this).Possible solution
The easiest update may be:
cccd
ivar inMicroBitBLEChar
to be a boolean that indicates a CCCD exists for the characteristic (currently it is a shadow copy of the expected meaning of the CCCD).cccdNotify()
andcccdIndicate()
predicates to retrieve the actual CCCD value from the stack (first check thecccd
ivar to see if there is a CCCD for this characteristic).Concerns
Existing Bluetooth apps/features would need additional testing following this change. It's likely that all current BLE apps/services for the micro:bit are implemented to automatically reset CCCDs of interest on connection rather than rely on the specified behavior, so impact is probably (hopefully) minimal.
Justification
The micro:bit should conform to Bluetooth specifications for compatibility with non-custom services. For example, some Android and Windows devices expect the values to persist for BLE Human Interface Devices. Failure to re-enable them correctly prevents micro:bit services from working correctly on reconnects (workarounds are possible to overcome this).
The text was updated successfully, but these errors were encountered: