Performance Optimization
Transmit Power
Both esp_ble_tx_power_set
and esp_ble_tx_power_set_enhanced
can be used to set the transmission power. It is recommended to use the esp_ble_tx_power_set_enhanced
function, as it supports a more granular range of power. Different chips support different power ranges, which can be defined in the corresponding macros in the esp_bt.h
file.
Power Consumption Optimization
How to optimize power consumption:
- Use low power mode
Use the
Auto Sleep
mode to allow the RF and CPU to enter low power mode when idle.
- Use an external crystal oscillator
Using an external 32.768 kHz crystal can provide a more stable clock source.
Helps to improve timing accuracy in low power mode
Reduce the power consumption of the internal RC oscillator
- Choose appropriate connection parameters
Connection Interval: Choose an appropriate time interval based on application requirements. A longer interval can reduce power consumption.
Slave Latency: Allows the slave device to skip a certain number of connection events, further reducing power consumption.
Supervision Timeout: Set a reasonable timeout period to avoid unnecessary reconnections.
Use a larger MTU size to reduce the number of data transfers
- Other optimization suggestions
Design packet sizes reasonably to avoid fragmented transmission.
Use notifications (Notification) instead of indications (Indication) where possible.
Utilize the power management features of ESP32, such as dynamic frequency adjustment
Appropriately reduce transmit power
Typical power consumption data:
Chip |
Max Current |
Modem Sleep |
Light Sleep (Main XTAL) |
Light Sleep (32KHz XTAL) |
---|---|---|---|---|
ESP32 |
231 mA |
14.1 mA |
X |
1.9 mA |
ESP32C3 |
262 mA |
12 mA |
2.3 mA |
140 uA |
ESP32S3 |
240 mA |
17.9 mA |
3.3 mA |
230 uA |
ESP32C6 |
240 mA |
22 mA |
3.3 mA |
34 uA |
ESP32H2 |
82 mA |
16.0 mA |
4.0 mA |
24 uA |
ESP32C2 |
130 mA |
18.0 mA |
2.5 mA |
169 uA |
Reference example: BLE Low Power Example
Transmission Rate Optimization
BLE 5.0 and above versions support multiple physical layers: - LE 1M UNCODED PHY: Bit transmission rate is 1M bit/s (Physical layer used by BLE 4.2) - LE 2M UNCODED PHY: Bit transmission rate is 2M bit/s - LE CODED PHY: Used for long-distance communication, bit transmission rate is 125 K bit/s or 500 K bit/s
Factors affecting the actual transmission rate:
- Protocol layer encapsulation overhead
Data needs to be encapsulated layer by layer from the ATT layer to the LL layer.
A protocol header (Header) is added to each layer.
The Preamble of LE 1M UNCODED PHY is 1 byte
The Preamble of LE 2M UNCODED PHY is 2 bytes
- Data Length Extension (DLE)
BLE 4.0/4.1: Maximum ATT Payload is 20 bytes
BLE 4.2/5.0: Supports DLE, maximum ATT Payload can reach 244 bytes
It is recommended to configure DLE to its maximum value to improve the utilization rate of single packet data.
- Inter-Frame Space (T_IFS)
The distance between two air packets on the same data channel is 150 us.
This is a fixed time consumption
- Connection event and connection interval
In each connection event, both parties need to complete a packet transmission and reception once.
Even if there is no data, an empty packet still needs to be sent.
A connection event can include multiple packet interactions
The number of packets is related to the size of the connection interval
Optimization suggestions:
- Application layer packet sending method
Use
write command
instead ofwrite request
Use
Notify
instead ofIndication
- Connection interval optimization
Adjust packet size to increase packet fill rate during connection events.
Adjust the connection interval appropriately to send more data packets in a single connection event.
- Use 2M PHY
NimBLE uses the
ble_gap_set_prefered_le_phy
function to set the physical layer for a specific connection, and theble_gap_set_prefered_default_le_phy
function to set the default physical layer.Bluedroid uses the
esp_ble_gap_set_preferred_phy
function to set the physical layer of a specific connection, and uses theesp_ble_gap_set_preferred_default_phy
function to set the default physical layer.
Reference examples