From 7c7fd098c09aec02d5cdffd632af62afce54c425 Mon Sep 17 00:00:00 2001 From: William Ferguson Date: Sun, 24 Mar 2019 18:33:17 +1000 Subject: [PATCH] Ability to explicitly disconnect a client. --- src/BLEServer.cpp | 15 +++++++++++++++ src/BLEServer.h | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/src/BLEServer.cpp b/src/BLEServer.cpp index 6a780aa..fe57ec1 100644 --- a/src/BLEServer.cpp +++ b/src/BLEServer.cpp @@ -135,6 +135,21 @@ uint32_t BLEServer::getConnectedCount() { } // getConnectedCount +/** + * @brief Disconnect Client + * + * Force a client to disconnect + */ +void BLEServer::disconnectClient() { + ESP_LOGD(LOG_TAG, ">> disconnectClient()"); + esp_err_t errRc = ::esp_ble_gatts_close(getGattsIf(), getConnId()); + if (errRc != ESP_OK) { + ESP_LOGE(LOG_TAG, "esp_ble_gatts_close: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + ESP_LOGD(LOG_TAG, "<< disconnectClient()"); +} + uint16_t BLEServer::getGattsIf() { return m_gatts_if; } diff --git a/src/BLEServer.h b/src/BLEServer.h index d39d8bf..617af09 100644 --- a/src/BLEServer.h +++ b/src/BLEServer.h @@ -63,6 +63,14 @@ class BLEServiceMap { class BLEServer { public: uint32_t getConnectedCount(); + + /** + * @brief Disconnect Client + * + * Force a client to disconnect + */ + void disconnectClient(); + BLEService* createService(const char* uuid); BLEService* createService(BLEUUID uuid, uint32_t numHandles=15, uint8_t inst_id=0); BLEAdvertising* getAdvertising();