Multi-Peripheral Topology#
Introduction#
Silicon Labs Bluetooth stack supports simultaneous connection to multiple peripherals, with a maximum number of 32 peripherals. This page describes handling multiple connections in your Bluetooth application.
Establishing Multiple Connections#
A new connection (toward an advertising Bluetooth device) can be initiated with the sl_bt_connection_open command. This command starts a high-priority scan to find the next advertisement of the peer device and sends a connection request after the advertisement. If successful, a sl_bt_evt_connection_opened event is generated by the stack. After this, a second connection can be initiated with sl_bt_connection_open, while the first one is automatically kept alive.
Note that you cannot issue multiple sl_bt_connection_open commands immediately after each other even if you know all Bluetooth addresses you want to connect to. You always have to wait for the sl_bt_evt_connection_opened event to arrive before initiating a new connection. It is even better if you wait until the sl_bt_evt_connection_parameters event because at that moment the connection can be considered stable. To discover the GATT database of the remote device, do so before issuing the second sl_bt_connection_open command.
By default, four simultaneous connections are enabled in the stack. To increase the number of supported connections, go to the configuration of the Bluetooth Core software component and increase the Maximum number of connections:
Saving Connection Handles#
When a connection is opened, the stack returns a connection handle. Later, this handle can be used to differentiate between simultaneous connections. All connection-related commands require a connection handle and all connection-related events provide a connection handle. It is therefore important that you save the connection handles for future use, e.g., in a global variable.
struct {
bd_addr device_address;
uint8_t address_type;
uint8_t connection_handle;
} connections[8];
uint8_t live_connections = 0;
//...
case sl_bt_evt_connection_opened_id:
connections[live_connections].device_address = evt->data.evt_connection_opened.address;
connections[live_connections].address_type = evt->data.evt_connection_opened.address_type;
connections[live_connections].connection_handle = evt->data.evt_connection_opened.connection;
live_connections++;
break;
Reading/Writing the Database of Multiple Peripherals#
Unlike connection i