-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Fixing BLE GATT Characteristic notification and Characteristic Descriptor read #4464
Fixing BLE GATT Characteristic notification and Characteristic Descriptor read #4464
Conversation
…ions When registering a notification on a characteristic, the 2902 descriptor (CCCD) value is set to 1 (or 2 for indication). According to the BLUETOOTH CORE SPECIFICATION Version 5.2, Revision Date 2019-12-31, section 4.12.3 "Write Characteristic Descriptors" (page 1588), the characteristic descriptor write must expect a response. Currently, the descriptor write is performed without expecting a reponse, which prevents the notification to be functional with some BLE stacks. This commit modify the write to expect the response. Signed-off-by: Jimmy Durand Wesolowski <[email protected]>
This commits prevents a permanent wait when calling BLERemoteDescriptor readValue function, on the m_semaphoreReadDescrEvt semaphore. ESP32 BLE stack calls to remote characteristic - notification, - value read - value write and remote characteristic descriptor - value read are asynchronous. When such a call is performed by this library, a semaphore is taken prior to the BLE stack read or write operation, and waited on after it. Releasing the semaphore is done by the characteristic event handling function (gattClientEventHandler), when the appropriate event is received. However, the characteristic descriptor events are discarded, and the value read semaphore is never released. This commits forwards the GATT client events from the remote characteristic down to their remote characteristic descriptor, and implements their event handling. Adding a semaphore for the remote characteristic descriptor value write will be done in a separate commit. Signed-off-by: Jimmy Durand Wesolowski <[email protected]>
This adds a semaphore to characteristic descriptor value write, to mimic the value read function, and to ensure completion of the operation before we carry on. Signed-off-by: Jimmy Durand Wesolowski <[email protected]>
@@ -468,7 +475,7 @@ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback, | |||
if(!notifications) val[0] = 0x02; | |||
BLERemoteDescriptor* desc = getDescriptor(BLEUUID((uint16_t)0x2902)); | |||
if (desc != nullptr) | |||
desc->writeValue(val, 2); | |||
desc->writeValue(val, 2, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason to response await here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave the details in the commit that introduces the change. For convenience, the commit message is:
When registering a notification on a characteristic, the 2902 descriptor
(CCCD) value is set to 1 (or 2 for indication).
According to the BLUETOOTH CORE SPECIFICATION Version 5.2, Revision Date
2019-12-31, section 4.12.3 "Write Characteristic Descriptors" (page 1588),
the characteristic descriptor write must expect a response.
Currently, the descriptor write is performed without expecting a reponse,
which prevents the notification to be functional with some BLE stacks.
This commit modify the write to expect the response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks.
Commit aproved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
These commits fix some issues with GATT Characteristic and Characteristic Descriptor issues.