Server versus Client Connect and Disconnect Callbacks
-
- Posts: 15
- Joined: Sun Dec 16, 2018 4:06 am
Server versus Client Connect and Disconnect Callbacks
I have an Adafruit Huzzah32 device. I am writing an app that both acts as a peripheral to allow a mobile app to connect to it and at the same time is able to connect to a device to get data from it.
I have the code all working. It includes setting up server callbacks by creating my own class derived from BLEServerCallbacks that is then passed to pServer->setCallbacks(new BTServerCallbacks());
I also have a class derived from BLEClientCallbacks that is passed to pClient->setClientCallbacks(new MyClientCallback());
I am testing just having my device connect to the sensor device to gather data.
The problem I am having is that the onConnected and onDisconnected callbacks is BOTH classes gets called when I connect to and disconnect from the sensor device.
Can anyone explain how to fix this? I do certain things based on whether I am connecting/disconnecting with the sensor versus connecting/disconnecting with a mobile app to me.
I have the code all working. It includes setting up server callbacks by creating my own class derived from BLEServerCallbacks that is then passed to pServer->setCallbacks(new BTServerCallbacks());
I also have a class derived from BLEClientCallbacks that is passed to pClient->setClientCallbacks(new MyClientCallback());
I am testing just having my device connect to the sensor device to gather data.
The problem I am having is that the onConnected and onDisconnected callbacks is BOTH classes gets called when I connect to and disconnect from the sensor device.
Can anyone explain how to fix this? I do certain things based on whether I am connecting/disconnecting with the sensor versus connecting/disconnecting with a mobile app to me.
Re: Server versus Client Connect and Disconnect Callbacks
Recently I saw few similar questions and looks like it is bug in library. I will try to check it when i have some time.
-
- Posts: 15
- Joined: Sun Dec 16, 2018 4:06 am
Re: Server versus Client Connect and Disconnect Callbacks
I have a little more information for you. I added a log output to both the server and client disconnect where the event is coming in and they both get fired.
If you can point me to somewhere I might be able to look to solve this I am happy to dig into it. It is rather important and I know you are busy, so anything I can do to help please let me know.
If you can point me to somewhere I might be able to look to solve this I am happy to dig into it. It is rather important and I know you are busy, so anything I can do to help please let me know.
Re: Server versus Client Connect and Disconnect Callbacks
You can add in your code callbacks that will be triggered on every bluedroid event unchanged. This way you can try to see if original (not Kolbans library) disconnect events are triggered for gattc and gatts and see what parameters are passed, especially gattc_if/gatts_if and param->conn_id:
https://github.com/nkolban/esp32-snippe ... .h#L60-L62
With such data we can find if and how its possible to fix it.
https://github.com/nkolban/esp32-snippe ... .h#L60-L62
With such data we can find if and how its possible to fix it.
-
- Posts: 15
- Joined: Sun Dec 16, 2018 4:06 am
Re: Server versus Client Connect and Disconnect Callbacks
So I added the following code:
When I disconnect the device I am connected to here is the output:
Keep in mind that even though I have the device set up to connect to an app as a peripheral, at the point this is happening I have not connected the app. My device is only connected to my device as a central.
So disconnecting should only signal the client disconnect, not the server (as best I understand this).
Please let me know if there are other things I can test to get more information.
Also one thing that I noticed is that the seems to have the name of the esp_gatt_if parameter named wrong. Is it supposed to be gattc_if or gatts_if?
Not a big deal, just pointing it out.
Let me know what else I can do to help figure this out.
Code: Select all
void my_gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gatts_cb_param_t* param)
{
Serial.print("server: esp_gatts_cb_event_t ");
Serial.print(event);
Serial.print(" esp_gatt_if_t ");
Serial.print(gattc_if);
if (param == NULL)
Serial.println("");
else
{
Serial.print(" conn_id ");
Serial.println(param->disconnect.conn_id);
}
}
void my_gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* param)
{
Serial.print("client: esp_gattc_cb_event_t ");
Serial.print(event);
Serial.print(" esp_gatt_if_t ");
Serial.print(gattc_if);
if (param == NULL)
Serial.println("");
else
{
Serial.print(" conn_id ");
Serial.println(param->disconnect.conn_id);
}
}
...
BLEDevice::setCustomGattsHandler(my_gatts_event_handler);
BLEDevice::setCustomGattcHandler(my_gattc_event_handler);
Code: Select all
server: esp_gatts_cb_event_t 15 esp_gatt_if_t 4 conn_id 0
client: esp_gattc_cb_event_t 41 esp_gatt_if_t 5 conn_id 0
client: esp_gattc_cb_event_t 5 esp_gatt_if_t 5 conn_id 0
client: esp_gattc_cb_event_t 1 esp_gatt_if_t 5
So disconnecting should only signal the client disconnect, not the server (as best I understand this).
Please let me know if there are other things I can test to get more information.
Also one thing that I noticed is that the
Code: Select all
gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gatts_cb_param_t* param)
Not a big deal, just pointing it out.
Let me know what else I can do to help figure this out.
-
- Posts: 15
- Joined: Sun Dec 16, 2018 4:06 am
Re: Server versus Client Connect and Disconnect Callbacks
I just saw your reply. Not getting emails for some reason.
Anyway, I am not sure what you want me to try. You just show 2 files that are very different. What do you mean by "try to add here" "this same code"? I don't see anything highlighted to add or move from one file to the other.
Anyway, I am not sure what you want me to try. You just show 2 files that are very different. What do you mean by "try to add here" "this same code"? I don't see anything highlighted to add or move from one file to the other.
Re: Server versus Client Connect and Disconnect Callbacks
Hi,tony@shatalmic.com wrote: ↑Tue Sep 17, 2019 8:24 pmI just saw your reply. Not getting emails for some reason.
Anyway, I am not sure what you want me to try. You just show 2 files that are very different. What do you mean by "try to add here" "this same code"? I don't see anything highlighted to add or move from one file to the other.
Sorry it should have been link with 2 lines, 194-195:
https://github.com/nkolban/esp32-snippe ... #L194-L195
And use it here:
https://github.com/nkolban/esp32-snippe ... r.cpp#L215
-
- Posts: 15
- Joined: Sun Dec 16, 2018 4:06 am
Re: Server versus Client Connect and Disconnect Callbacks
Thank you. I will give that a try.
Who is online
Users browsing this forum: No registered users and 47 guests