ESP Wireless Transmission Power Configuration
This guide introduces how to set up the transmission power (TX Power) for Wi-Fi, BLE, Classic Bluetooth, Thread, and Zigbee in ESP-IDF.
Wi-Fi TX Power
In ESP-IDF, the Wi-Fi transmission power can be set using the esp_wifi_set_max_tx_power function. The unit of transmission power is 0.25 dBm, so the value passed is four times the actual power. For example, when setting to 20 dBm, the value should be 80.
#include "esp_wifi.h"
void set_wifi_tx_power() {
int8_t max_tx_power = 80; // 20 dBm
esp_wifi_set_max_tx_power(max_tx_power);
}
If you want to use the default maximum power, you can also configure the maximum Wi-Fi transmit power in menuconfig.
- menuconfig path:
Component config -> PHY -> Max WiFi TX power (dBm)
BLE TX Power
The BLE transmission power in ESP-IDF can be manually adjusted through the esp_ble_tx_power_set function. This function allows for setting different transmission powers for different types of transmission, such as broadcasting, scanning, and connection modes. The BLE power levels of different ESP chips may not necessarily be the same. For instance, in the case of ESP32, the power level range of BLE is from ESP_PWR_LVL_N12 to ESP_PWR_LVL_P9.
The following example shows how to set the default transmit power of BLE to the maximum 9 dBm using ESP32:
#include "esp_gap_ble_api.h"
void set_ble_tx_power() {
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, ESP_PWR_LVL_P9); // Set maximum 9 dBm power
}
Example of ESP32 BLE Transmission Power Levels:
ESP_PWR_LVL_N12: -12 dBm
ESP_PWR_LVL_N9: -9 dBm
ESP_PWR_LVL_N6: -6 dBm
ESP_PWR_LVL_N3: -3 dBm
ESP_PWR_LVL_P0: 0 dBm
ESP_PWR_LVL_P3: 3 dBm
ESP_PWR_LVL_P6: 6 dBm
ESP_PWR_LVL_P9: 9 dBm (maximum power)
Examples of Some BLE Transmit Power Types:
ESP_BLE_PWR_TYPE_CONN_HDL0: Transmit power of the first connection
ESP_BLE_PWR_TYPE_CONN_HDL1: Transmit power of the second connection
ESP_BLE_PWR_TYPE_ADV: Transmit power of broadcasting
ESP_BLE_PWR_TYPE_SCAN: Transmit power of scanning
ESP_BLE_PWR_TYPE_DEFAULT: Default transmit power
Some ESP chips can also configure the maximum BLE transmit power in menuconfig.
- menuconfig path:
Component config → Bluetooth → Controller Options → BLE default Tx power level
In addition, for the new generation of ESP chips that support BLE (such as ESP32-C2, ESP32-C5, ESP32-C6, ESP32-H2), it is recommended to use the esp_ble_tx_power_set_enhanced API to adjust the BLE transmit power.
Classic Bluetooth TX Power
The transmission power of Classic Bluetooth can be set through the esp_bredr_tx_power_set API, sharing the same setting method with BLE. In Classic Bluetooth, the transmission power is mainly used under the ESP_BT_PWR_TYPE_DEFAULT mode.
Here is an example:
#include "esp_bt.h"
void set_classic_bt_tx_power() {
esp_bredr_tx_power_set(ESP_PWR_LVL_N0, ESP_PWR_LVL_P3);
}
Thread TX Power
If developing based on Thread, it is recommended to adjust the transmit power of Thread through the openthread API otPlatRadioSetTransmitPower.
If developing directly based on the 802.15.4 MAC driver, it is recommended to adjust the transmission power of Thread through esp_ieee802154_set_txpower.
Zigbee TX Power
If developing based on Zigbee, it is recommended to adjust the transmission power of Zigbee through esp_zb_set_tx_power.
Notes
Wi-Fi and BLE transmission power: When adjusting the transmission power of Wi-Fi and BLE using esp_wifi_set_max_tx_power and esp_ble_tx_power_set, it may be necessary to balance according to application requirements, as they share some hardware resources.
Limitations of Menuconfig settings: ESP_PHY_MAX_WIFI_TX_POWER can only control the maximum transmission power of Wi-Fi, and has no direct impact on the transmission power of BLE and Classic Bluetooth.