n-able-Arduino icon indicating copy to clipboard operation
n-able-Arduino copied to clipboard

ESP32 becomes undiscoverable after disconnect from Flutter BLE client

Open alvarohurtadobo opened this issue 2 months ago • 1 comments

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.

alvarohurtadobo avatar Oct 01 '25 22:10 alvarohurtadobo

This is intended, it's up to the app to control advertising/scanning etc. and your solution is the correct one. If you want this to be automatic though you can enable that through calling NimBLEServer::advertiseOnDisconnect(true);

h2zero avatar Oct 07 '25 13:10 h2zero