-
Notifications
You must be signed in to change notification settings - Fork 7.6k
BLE server connection callbacks being made when BLE client connects or disconnects #7115
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
How did you test it? Because from your code i see the server is started:
Also from your logs i dont see anything wrong, could you isolate the logs you think are important and to describe what you do and what you expect to see or not suppose to see? |
I apologize, when I seem to have misunderstood what it means to start the server, but regardless, In this section here I believe it to be what I am trying to discuss. My expectation is that when I use the BLEClient to connect to a server while I also have a BLEServer running on the same device, I receive only a client callback which would print "Client Connected ", but what I am getting is the server callback as well as denoted by the the server call back which would print " Connect". I also tested it with this exact sketch running on the device im viewing, and starting a BLE server with the defined name I am searching for so I have something to connect to. |
bump, I seem to have found somethin from chegewara, but the solution appears to be quite outdated, so it seems to have been an issue in the past. |
It is not outdated at all. I would use it by myself to debug the problems with BLE. |
I'm seeing the same behavior in a sketch that has both a BLEClient and a BLEServer defined. Server callbacks are being called on Client connect/disconnect events. |
@patrickleboutillier Yes I was experiencing this issue continuously using the arduino esp32 BLE library. Although not an optimal solution, I used a different library nimBLE for arduino, which fixed the issue with minimal required changes to the source code I was working with. I know this is not much of a help, just a band-aid fix since it does not deal with the issue, but it did fix the issue. |
I can confirm as well that I am confronted with the same behavior, very consistently and very reproducibly! see a code snippet: void server_Connection_Callbacks::onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param) {
// Get some connection parameters of the peer device.
char fullMacAddress[18] = {}; //
uint32_t count = pServer->getConnectedCount();
uint16_t ConnectionHandle = param->connect.conn_id;
uint8_t RemoteAddress[6];
memcpy(&RemoteAddress, param->connect.remote_bda, 6);
ConvertMacAddress(fullMacAddress, RemoteAddress, true); // true -> Native format!
DEBUG_PRINTF("Server onConnect Callback --> Conn cnt: [%d] Conn handle: [%d] Address: [%s]\n", count, ConnectionHandle, fullMacAddress);
// For some reason Server_Connection_Callbacks::onConnect is not only called for pServer but
// also called when a pClient is Connecting...???? Bug or Feature --> handle it to avoid inconsistencies....!!
if (memcmp(RemoteAddress, Trainer.PeerAddress, 6) == 0 ) { // Check for Trainer MAC address Notice: pClient_FTMS->getConnId() == 255
DEBUG_PRINTLN(">>> Client will Connect soon with Server device!");
return; // Let client Connect happen....
}
BLEDevice::stopAdvertising();
// Who has been exactly connected?
DEBUG_PRINTF("ESP32 Server connected to Client device with MAC Address: [%s] Handle: [%d]\n", fullMacAddress, param->connect.conn_id);
etcetera
void server_Connection_Callbacks::onDisconnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param) {
uint32_t count = pServer->getConnectedCount();
// Get some Disconnection parameters of the peer device.
uint16_t ConnectionHandle = param->connect.conn_id;
uint8_t Reason = param->disconnect.reason;
uint8_t RemoteAddress[6] = {};
memcpy(&RemoteAddress, param->connect.remote_bda, 6);
char fullMacAddress[18] = {}; //
ConvertMacAddress(fullMacAddress, RemoteAddress, true); // true -> Native format!
DEBUG_PRINTF("Server onDisconnect Callback --> Conn cnt: [%d] Conn handle: [%d] Address: [%s] Reason: [%d]\n", count, ConnectionHandle, fullMacAddress, Reason);
// For some reason Server_Connection_Callbacks::onDisconnect is not only called for pServer but
// also called when a pClient is disconnecting...???? Bug or Feature --> handle it to avoid inconsistencies....!!
if (memcmp(RemoteAddress, Trainer.PeerAddress, 6) == 0 ) { // Check for Trainer MAC address
DEBUG_PRINTLN(">>> Client will disconnect soon from Server device!");
return; // Let client disconnect happen....
}
if (Laptop.conn_handle == ConnectionHandle ) { // Laptop/Desktop is disconnected
etcetera see the debug_print output and compare with above code (notice that the pServer connection is meanwhile doing its work, and also reporting!)
|
I have tested this suggestion but I could NOT find any change in behavior during connect and/or disconnect! |
Board
Tiny Pico
Device Description
Just Tiny pico using usb power
Hardware Configuration
I have two other esp32 boards, one acting as a server and one acting as a client just to connect and disconnect from the one I am experiencing the issue I have.
Version
v2.0.3
IDE Name
Arduino IDE
Operating System
Windows 10
Flash frequency
80 MHz
PSRAM enabled
yes
Upload speed
921600
Description
I was given a task use the esp32 as both a server and a client to allow some device to connect to it, and as well to reach out to a server and connect to it. I attempted performing this using the BLE libraries in the arduino esp32.
If the server portion receives a connect, or disconnect, it functions as expected, only the server callbacks are made, but when the client portion connects, or disconnects, it performs the call back for both server and client meaning I can't really use the server callback as just a server callback.
After some more testing the Server doesn't even have to be started the callbacks just need to be set.
Sketch
Debug Message
Other Steps to Reproduce
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: