BLE Client Disconnect Also Disconnects Server Connection

akolodner25
Posts: 27
Joined: Tue Nov 22, 2022 5:15 am

BLE Client Disconnect Also Disconnects Server Connection

Postby akolodner25 » Mon Mar 20, 2023 3:26 am

EDIT: see second reply for an update, some of the information here turns out to be incorrect.






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];
        }
    }
Last edited by akolodner25 on Wed Mar 22, 2023 3:06 am, edited 1 time in total.

akolodner25
Posts: 27
Joined: Tue Nov 22, 2022 5:15 am

Re: BLE Client Disconnect Disconnects All Connections

Postby akolodner25 » Wed Mar 22, 2023 2:54 am

Update: the issue is caused by the call to esp_ble_gattc_close. Manually calling esp_ble_gattc_close myself will cause the same effect: although I only call it once, to close a specific connection, all connections are closed. Here's the output:

Code: Select all

W (23841) BT_HCI: hci cmd send: disconnect: hdl 0x3, rsn:0x13
W (23841) BT_APPL: gattc_conn_cb: if=4 st=0 id=4 rsn=0x16
W (23842) BT_APPL: gattc_conn_cb: if=5 st=0 id=5 rsn=0x16
Device Disconnected!
W (23846) BT_HCI: hci cmd send: disconnect: hdl 0x1, rsn:0x13
W (23847) BT_APPL: gattc_conn_cb: if=4 st=0 id=516 rsn=0x16
W (23848) BT_APPL: gattc_conn_cb: if=5 st=0 id=517 rsn=0x16
Device Disconnected!
W (23854) BT_HCI: hcif disc complete: hdl 0x1, rsn 0x16
W (23870) BT_HCI: hcif disc complete: hdl 0x3, rsn 0x16
W (28840) BT_HCI: hci cmd send: disconnect: hdl 0x4, rsn:0x13
W (28841) BT_APPL: gattc_conn_cb: if=5 st=0 id=261 rsn=0x16

akolodner25
Posts: 27
Joined: Tue Nov 22, 2022 5:15 am

Re: BLE Client Disconnect Also Disconnects Server Connection

Postby akolodner25 » Wed Mar 22, 2023 3:07 am

Update: it turns out that actually, only the intended client connection is being closed, and the other clients stay connected. However, the server connection is definitely being closed.

novobs
Posts: 1
Joined: Thu Aug 10, 2023 6:03 pm

Re: BLE Client Disconnect Also Disconnects Server Connection

Postby novobs » Thu Aug 10, 2023 6:04 pm

hey mate, did you find any solution for this problem?

akolodner25
Posts: 27
Joined: Tue Nov 22, 2022 5:15 am

Re: BLE Client Disconnect Also Disconnects Server Connection

Postby akolodner25 » Mon Aug 14, 2023 7:32 pm

Nope. Still happening. Still no idea why. I've just been living with it for now. :cry:

Who is online

Users browsing this forum: No registered users and 164 guests