Skip to content
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

BLE Server keeps notify subscriber after client disconnection #718

Open
chall3ng3r opened this issue Sep 9, 2024 · 2 comments
Open

BLE Server keeps notify subscriber after client disconnection #718

chall3ng3r opened this issue Sep 9, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@chall3ng3r
Copy link

I am working with a Flutter based Android app which connects to ESP32 via NimBLE-Arduino.

I've noticed that if the mobile app disconnects from ESP32, the notify subscription is kept by the ESP32. When same mobile app client connects back, the subscriber count is shown as one, which is incorrect as the mobile client have not yet sent the request to notify from the new connection.

On ESP32, I have a check if subscriber count is one, then update the value and call notify. Which starts immediately, but the mobile app never receives these until I subscribe > unsubscribe > subscribe from the mobile app. After this, I start getting the notifications.

I have the callback set for disconnect event on ESP32, but I am not able to find a way in NimBLE lib to unsubscribe disconnected client from all notify subscriptions.

Let me know if there's a way to manually unsubscribe clients when they disconnect from server on ESP32.

Thanks.

void notifyUpdate()
{
    // check if there is a connection
    if (pServer && pServer->getConnectedCount() == 0)
    {
        return;
    }

    // check if there is a subscribed client << this is automatically one when client reconnects
    if (pCharacteristic1->getSubscribedCount() > 0)
    {
        // update data
        pCharacteristic1->setValue(123);

        // notify client
        pCharacteristic1->notify(true); << client never get these if it reconnects
    }
}
@h2zero
Copy link
Owner

h2zero commented Sep 15, 2024

Is your phone bonded to the esp32?

@chall3ng3r
Copy link
Author

Yes, phone is bonded to ESP32.

@h2zero h2zero added the bug Something isn't working label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants