Bluetooth LE Connection Parameters
The Bluetooth LE connection parameters are a set of values that tell the Bluetooth hardware how it should maintain the GATT connection. These parameters are very important in GATT communication because they control how fast your communication is and how much power your device needs. Usually, you do not need to change them because a device you connect to has been optimized by its vendor to work in an optimal way. But sometimes, you may need to change the connection parameters to, for example, increase the data transfer rate.
Before Windows 11, there was no way to do this. Fortunately, Microsoft added this feature, and when your application runs on Windows 11, you can change the current connection parameters for Bluetooth LE GATT communication. If you need to change the connection parameters on Windows versions before Windows 11, you can always use the BLED112 Bluetooth USB dongle.
What Are The Connection Parameters
The connection parameters affect the power consumption, the data transfer speed, and the stability of the connection. The parameters are exchanged when the central and peripheral initially connect. It is always the central that actually sets the connection parameters used, but the peripheral can send a connection parameter update request that the central can then accept or reject. The three different parameters are:
Connection Interval
The connection interval determines how often the central will ask for data from the peripheral. When the peripheral requests an update, it supplies a maximum and a minimum wanted interval. The connection interval must be between 7.5ms and 4s. The connection interval time has an inverse effect on the data throughput of the BLE connection, as shown in the following equation:
DataThroughput = (8 * BytesPerPacket * PacketsPerInterval * 1000) / ConnectionInterval
To save power, we need to change the connection interval to a much longer period when we know the connection is going to be in an idle state for a period of time.
Slave Latency
By setting a non-zero slave latency, the peripheral can choose not to answer when the central asks for data up to the slave latency number of times. However, if the peripheral has data to send, it can choose to send data at any time. This enables a peripheral to stay sleeping for a longer time if it doesn't have data to send but still send data fast if needed. Furthermore, slave latency can be applied to help the peripheral (slave) device to further reduce power consumption. This parameter is helpful to avoid changing connection parameters frequently to achieve both high-speed data transfer and low power consumption during idle.
Connection Supervision Timeout
This timeout determines the timeout from the last data exchange until a link is considered lost. The central will not try to reconnect before the timeout has passed, so if you have a device that goes in and out of range often and you need to notice when that happens, it might make sense to have a short timeout.
Effective Connection Interval
The effective connection interval is equal to the amount of time between two connection events, assuming that the slave skips the maximum number of possible events if slave latency is allowed (the effective connection interval is equal to the actual connection interval if slave latency is set to 0).
The slave latency value represents the maximum number of events that can be skipped. This number can range from a minimum value of 0 (meaning that no connection events can be skipped) to a maximum of 499. The maximum value must not make the effective connection interval (see the following formula) greater than 16s. The interval can be calculated using the following formula:
Effective Connection Interval = (Connection Interval) * (1 + [Slave Latency])
Consider the following example:
- Connection Interval: 80 (100ms)
- Slave Latency: 4
- Effective Connection Interval: 100ms * (1 + 4) = 500ms
When no data is being sent from the slave to the master, the slave transmits during a connection event once every 500ms.
Connection Parameter Considerations
In many applications, the slave skips the maximum number of connection events. Consider the effective connection interval when selecting or requesting connection parameters. Selecting the correct group of connection parameters plays an important role in the power optimization of the Bluetooth Low Energy device. The following list gives a general summary of the trade-offs in connection parameter settings.
Reducing the connection interval
- Increases the power consumption for both devices.
- Increases the throughput in both directions.
- Reduces the time for sending data in either direction.
Increasing the connection interval
- Reduces the power consumption for both devices.
- Reduces the throughput in both directions.
- Increases the time for sending data in either direction.
Reducing the slave latency (or setting it to zero)
- Increases the power consumption for the peripheral device.
- Reduces the time for the peripheral device to receive the data sent from a central device.
Increasing the slave latency
- Reduces power consumption for the peripheral during periods when the peripheral has no data to send to the central device.
- Increases the time for the peripheral device to receive the data sent from the central device.
Setting Connection Parameters
If your application uses the standard Microsoft UWP Bluetooth LE API and runs on Windows 11, it can set predefined Bluetooth LE connection parameters using the API. The predefined connection parameters are:
- Balanced
The balanced set of connection parameters, offering a balance between throughput and power usage. - Power Optimized
The more power-efficient set of connection parameters. Optimized for power usage at the expense of throughput. Also allows for more simultaneous connections to other Bluetooth devices. - Throughput Optimized
The more aggressive set of connection parameters, optimized for faster throughput at the expense of power usage. Also reduces the number of simultaneous connections that can be made to other Bluetooth devices.
However, there are two problems: the UWP API to change the connection parameters is available only on Windows 11, and you cannot set any custom values. And this is the case when you need the Bluetooth Framework. The Bluetooth Framework allows you to change the Bluetooth LE connection parameters on any Windows version with the BLED112 USB Bluetooth dongle. Also, with the Bluetooth Framework, you can set any custom connection parameter values. Additionally, the Bluetooth Framework provides a method to read the currently used Bluetooth LE connection parameters, and an event that is called when the connection parameters change.
To test this feature run the GattClient sample application from the Bluetooth Framework package. The sample application shows how you can set predefined or custom Bluetooth LE connection parameters.