Skip to content

BLEServer.h callback onDisconnect() missing esp_ble_gatts_cb_param_t parameter #6008

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

Closed
pabloandresm opened this issue Dec 11, 2021 · 7 comments · Fixed by #7559
Closed

BLEServer.h callback onDisconnect() missing esp_ble_gatts_cb_param_t parameter #6008

pabloandresm opened this issue Dec 11, 2021 · 7 comments · Fixed by #7559
Labels
Area: BT&Wifi BT & Wifi related issues Status: Needs investigation We need to do some research before taking next steps on this issue

Comments

@pabloandresm
Copy link

pabloandresm commented Dec 11, 2021

The BLEServer.h defines callbacks for connection and disconnection.

For the connect, there are 2 virtual methods, 1 without and 1 with esp_ble_gatts_cb_param_t.

For the disconnect, there is only 1 virtual method, without that parameter.

At least for coherency, there should be an onDisconnect() with that parameter. This parameter it is even in the comments!!! and it is missing in the code.

That parameter is useful for example to know the client that disconnects.

This fix wouldn't even impact the code already written, as it is an extra virtual method.

Look at the comment of the missing parameter esp_ble_gatts_cb_param_t:

class BLEServerCallbacks {
public:
virtual ~BLEServerCallbacks() {};
/**
* @brief Handle a new client connection.
*
* When a new client connects, we are invoked.
*
* @param [in] pServer A reference to the %BLE server that received the client connection.
/
virtual void onConnect(BLEServer
pServer);
virtual void onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t param);
/
*
* @brief Handle an existing client disconnection.
*
* When an existing client disconnects, we are invoked.
*
* @param [in] pServer A reference to the %BLE server that received the existing client disconnection. <--- HERE!!!
/
virtual void onDisconnect(BLEServer
pServer);
}; // BLEServerCallbacks

@VojtechBartoska VojtechBartoska added the Area: BT&Wifi BT & Wifi related issues label Dec 13, 2021
@bear24rw
Copy link

bear24rw commented Apr 5, 2022

Has there been any movement on this? I have the same issue.

@bear24rw
Copy link

bear24rw commented Apr 5, 2022

Here is a patch that resolve this issue I believe:

diff --git a/libraries/BLE/src/BLEServer.cpp b/libraries/BLE/src/BLEServer.cpp
index 7f156eff..f9f7d451 100644
--- a/libraries/BLE/src/BLEServer.cpp
+++ b/libraries/BLE/src/BLEServer.cpp
@@ -207,6 +207,7 @@ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t
 		case ESP_GATTS_DISCONNECT_EVT: {
 			if (m_pServerCallbacks != nullptr) {         // If we have callbacks, call now.
 				m_pServerCallbacks->onDisconnect(this);
+				m_pServerCallbacks->onDisconnect(this, param);
 			}
             if(m_connId == ESP_GATT_IF_NONE) {
                 return;
@@ -374,6 +375,12 @@ void BLEServerCallbacks::onDisconnect(BLEServer* pServer) {
 	log_d("BLEServerCallbacks", "<< onDisconnect()");
 } // onDisconnect
 
+void BLEServerCallbacks::onDisconnect(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) {
+	log_d("BLEServerCallbacks", ">> onDisconnect(): Default");
+	log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str());
+	log_d("BLEServerCallbacks", "<< onDisconnect()");
+} // onDisconnect
+
 void BLEServerCallbacks::onMtuChanged(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) {
 	log_d("BLEServerCallbacks", ">> onMtuChanged(): Default");
 	log_d("BLEServerCallbacks", "Device: %s MTU: %d", BLEDevice::toString().c_str(), param->mtu.mtu);
diff --git a/libraries/BLE/src/BLEServer.h b/libraries/BLE/src/BLEServer.h
index f3ca5be6..804e1457 100644
--- a/libraries/BLE/src/BLEServer.h
+++ b/libraries/BLE/src/BLEServer.h
@@ -134,6 +134,7 @@ public:
 	 * @param [in] pServer A reference to the %BLE server that received the existing client disconnection.
 	 */
 	virtual void onDisconnect(BLEServer* pServer);
+	virtual void onDisconnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param);
 
 	/**
 	 * @brief Handle a new client connection.

@VojtechBartoska VojtechBartoska added Status: Needs investigation We need to do some research before taking next steps on this issue Resolution: Awaiting response Waiting for response of author and removed Status: Needs investigation We need to do some research before taking next steps on this issue labels Apr 6, 2022
@VojtechBartoska
Copy link
Contributor

Hello @bear24rw, did you test this on v2.0.3-rc1?

@bear24rw
Copy link

@VojtechBartoska I have only tested with v2.0.0

@VojtechBartoska
Copy link
Contributor

ok, are you able to retest it on v2.0.3-rc1? Thanks

@bear24rw
Copy link

@VojtechBartoska I have just tested the patch on 2.0.3-RC1

    class ServerCallbacks : public BLEServerCallbacks {
        void onConnect(BLEServer* server)
        {
            Serial.println("ble: onConnect");
        };

        void onDisconnect(BLEServer* server, esp_ble_gatts_cb_param_t* param)
        {
            Serial.printf("ble: onDisconnect (%s)", BLEUtils::gattCloseReasonToString(param->disconnect.reason).c_str());
        }
    };

@VojtechBartoska VojtechBartoska added Status: Needs investigation We need to do some research before taking next steps on this issue and removed Resolution: Awaiting response Waiting for response of author labels Apr 13, 2022
@bear24rw
Copy link

Has there been any movement on this? This patch would be helpful to debug some disconnect issues on my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Status: Needs investigation We need to do some research before taking next steps on this issue
Projects
3 participants