Skip to content

ESP32 becomes undiscoverable after disconnect from Flutter BLE client #83

@alvarohurtadobo

Description

@alvarohurtadobo

Description:
When running on ESP32 using PlatformIO or Arduino IDE, if a Flutter client using flutter_reactive_ble connects and then disconnects, the ESP32 enters an unstable state. In this state, the device is no longer discoverable until the board is reset.

Temporary Solution:
Adding the following override in the server callbacks resolves the issue by restarting advertising:

class MyServerCallbacks : public NimBLEServerCallbacks {
  void onDisconnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo, int reason) override {
    Serial.println("Client disconnected, restarting advertising...");
    pServer->startAdvertising();
  }
};

This forces the device to restart the advertising service and become discoverable again.

Steps to Reproduce:
1. Run the ESP32 using PlatformIO or Arduino IDE.
2. Connect from a Flutter app using flutter_reactive_ble.
3. Disconnect the Flutter client.
4. Observe that the ESP32 is no longer discoverable nor from flutter nor any other BLE scanner.

Expected Behavior:
The ESP32 should automatically restart advertising and remain discoverable after a disconnect.

Notes:
With some guidance, I could help provide a proper fix if you think this is worth including in the library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions