When developing on ESP32 devices running OpenThread, a key feature that I needed was the ability to set the transmission (TX) power of these devices.
Guidance on how to set and query the TX power of ESP32 Thread devices can be found in the documentations provided by OpenThread and Espressif. I wanted to write a quick guide that gathered the information provided by the documentations in a single place, along with providing references to a couple of examples.
Setting TX Power in Code
Most settings on ESP32 devices would typically be set using Kconfig
variables and configured using idf.py menuconfig
. However, there is no such Kconfig
configuration for the TX power.
According to ESP-Techpedia, the TX power must be set programmatically. One way to do so is using the otPlatRadioSetTransmitPower()
class method provided by OpenThread, which under the hood is a wrapper function for the esp_ieee802154_set_txpower()
function implemented in ESP-IDF. This makes sense since the ESP-Techpedia states that:
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
.
Similarly, if you want to get the TX power value that is currently set by the device, you use the otPlatRadioGetTransmitPower()
class method provided by OpenThread. ESP-IDF implements the method as a wrapper for their esp_ieee802154_get_txpower()
function.
Examples
The source code for the OpenThread CLI contains a great example on how to set and query the TX power in the implementation for the txpower
CLI command.
In addition, my ESP32 programming projects contain examples on how to use the OpenThread TX power class methods. One such example is in my project where I implement an ESP32-H2 Sleepy End Device (SED). In this project, I defined wrapper funtions on top of the otPlatRadio
TX power functions, and I use those functions to set and query the TX power of the SED.