Skip to content

Add proper APIs to stop advertising, disconnect, and restart BLE services #314

@smart-fun

Description

@smart-fun

My use case requires full control over the BLE lifecycle:

  • When a device is connected, I need to stop advertising.
  • When the user requests it, the device should be able to disconnect cleanly.
  • Later, the user should be able to restart advertising and allow a new connection.

I could not find any way to achieve this with the current API.

I tried calling NimBLE APIs directly, but ESP32-BLE-Gamepad automatically reconnects the device as soon as I disconnect it. Also, BleGamepad::end() does not stop the server, does not stop advertising, and does not disconnect the client.

Here is a minimal example of what I attempted:

if (bleGamepad.isConnected()) {
    NimBLEServer* server = NimBLEDevice::getServer();
    if (server) {
        NimBLEAdvertising* advertising = server->getAdvertising();
        if (advertising) {
            advertising->stop();
        }
        NimBLEConnInfo connInfo = bleGamepad.getPeerInfo();
        server->disconnect(connInfo, BLE_ERR_REM_USER_CONN_TERM);
    }
}
bleGamepad.end();

Thank you.

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