I have a device which is connecting as a client to multiple peripherals, and can also act as a server which one peripheral will connect to. I want to close all of the client connections, but when I call BLEClient::disconnect() on the first one, it instantly disconnects all peripherals, including the one connected to the server. The subsequent calls to close the other client connections don't raise errors, but don't seem to have any effect.
I checked to make sure that each connection has a different Gattc If and connection ID, but I don't actually know what those do. All I know is that they're definitely different connections, so why can't I end one without disconnecting all other devices?
(Note that the peripheral that connects to the server can freely connect and disconnect without causing any issues, but if it's connected when a client disconnects, it is forcibly disconnected)
Here is the code I use to close the client connections:
Code: Select all
if (lengthOfDevices > -1) { // If any devices have been connected to,
for (int i = 0; i < lengthOfDevices; ++i) { // for each client,
if (clients[i] != nullptr) { // if the client exists,
if (clients[i]->isConnected()) {
clients[i]->disconnect(); // disconnect it
vTaskDelay(50 / portTICK_PERIOD_MS); // Give time for each disconnect to occur
printfln("Disconnected device %d", i);
}
}
//delete clients[i]; // Delete the client (if it's nullptr, C++ ignores it) // FIXME - Clients leaked due to persistent error messages when calling client destructor, some semaphore refuses to be released
delete devices[i];
}
}