taks / esp32-nimble

A wrapper for the ESP32 NimBLE Bluetooth stack.
Apache License 2.0
118 stars 35 forks source link

Multiple connection to the BLE server #4

Closed nicolasfara closed 1 year ago

nicolasfara commented 1 year ago

Hi,

I need to connect multiple clients to the BLE server. Using your example code for the server, only one client at a time is connected. Is there a way to enable a multi-client connection?

Thank you!

taks commented 1 year ago

By starting advertising when a connection is established, it is possible to respond to scans even while connected. You can do it with the code below.

  let ble_device = BLEDevice::take();
  let server = ble_device.get_server();
  server.on_connect(|_| {
    ble_device.get_advertising().start();
  });
taks commented 1 year ago

By default the maximum number of connections is 3. If you want to change the maximum number of connections, please set CONFIG_BT_NIMBLE_MAX_CONNECTIONS in sdkconfig.defaults.

nicolasfara commented 1 year ago

Ohh, thank you, @taks!! I'll try it out this weekend!