Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 05de017

Browse files
romansavrulinme-no-dev
authored andcommitted
BLE Library onRead Callback fix and Client disconnect feature (#2913)
* BLEServer::disconnect() * Invoke Read callback first, to make data update possible before read
1 parent e1548e9 commit 05de017

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

‎libraries/BLE/src/BLECharacteristic.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ void BLECharacteristic::handleGATTServerEvent(
378378
}
379379
} else { // read.is_long == false
380380

381+
if (m_pCallbacks != nullptr) { // If is.long is false then this is the first (or only) request to read data, so invoke the callback
382+
m_pCallbacks->onRead(this); // Invoke the read callback.
383+
}
384+
381385
std::string value = m_value.getValue();
382386

383387
if (value.length() + 1 > maxOffset) {
@@ -392,10 +396,6 @@ void BLECharacteristic::handleGATTServerEvent(
392396
rsp.attr_value.offset = 0;
393397
memcpy(rsp.attr_value.value, value.data(), rsp.attr_value.len);
394398
}
395-
396-
if (m_pCallbacks != nullptr) { // If is.long is false then this is the first (or only) request to read data, so invoke the callback
397-
m_pCallbacks->onRead(this); // Invoke the read callback.
398-
}
399399
}
400400
rsp.attr_value.handle = param->read.handle;
401401
rsp.attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE;

‎libraries/BLE/src/BLEServer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,9 @@ void BLEServer::updateConnParams(esp_bd_addr_t remote_bda, uint16_t minInterval,
412412
conn_params.timeout = timeout; // timeout = 400*10ms = 4000ms
413413
esp_ble_gap_update_conn_params(&conn_params);
414414
}
415+
416+
void BLEServer::disconnect(uint16_t connId) {
417+
esp_ble_gatts_close(m_gatts_if, connId);
418+
}
419+
415420
#endif // CONFIG_BT_ENABLED

‎libraries/BLE/src/BLEServer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class BLEServer {
7272
BLEService* getServiceByUUID(const char* uuid);
7373
BLEService* getServiceByUUID(BLEUUID uuid);
7474
bool connect(BLEAddress address);
75+
void disconnect(uint16_t connId);
7576
uint16_t m_appId;
7677
void updateConnParams(esp_bd_addr_t remote_bda, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout);
7778

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /