Skip to content

Commit e1b56fc

Browse files
authored
Fixes reading BLE Remote Descriptor (#6903)
1 parent 9ab8183 commit e1b56fc

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Diff for: libraries/BLE/src/BLERemoteDescriptor.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,26 @@ BLEUUID BLERemoteDescriptor::getUUID() {
5151

5252
void BLERemoteDescriptor::gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam) {
5353
switch(event) {
54+
// ESP_GATTC_READ_DESCR_EVT
55+
// This event indicates that the server has responded to the read request.
56+
//
57+
// read:
58+
// - esp_gatt_status_t status
59+
// - uint16_t conn_id
60+
// - uint16_t handle
61+
// - uint8_t* value
62+
// - uint16_t value_len
5463
case ESP_GATTC_READ_DESCR_EVT:
55-
if (evtParam->read.handle != getHandle())
56-
break;
64+
// If this event is not for us, then nothing further to do.
65+
if (evtParam->read.handle != getHandle()) break;
66+
// At this point, we have determined that the event is for us, so now we save the value
67+
if (evtParam->read.status == ESP_GATT_OK) {
68+
// it will read the cached value of the descriptor
69+
m_value = std::string((char*) evtParam->read.value, evtParam->read.value_len);
70+
} else {
71+
m_value = "";
72+
}
73+
// Unlock the semaphore to ensure that the requestor of the data can continue.
5774
m_semaphoreReadDescrEvt.give();
5875
break;
5976

0 commit comments

Comments
 (0)