-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Comments
Has there been any movement on this? I have the same issue. |
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. |
Hello @bear24rw, did you test this on v2.0.3-rc1? |
@VojtechBartoska I have only tested with |
ok, are you able to retest it on v2.0.3-rc1? Thanks |
@VojtechBartoska I have just tested the patch on 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());
}
}; |
Has there been any movement on this? This patch would be helpful to debug some disconnect issues on my project. |
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
The text was updated successfully, but these errors were encountered: