ESP32 set WiFi power problems
Posted: Mon Sep 18, 2023 11:21 am
I posted this query on the arduino forums (https://forum.arduino.cc/t/esp32-wroom- ... ss/1167585), but although a few people kindly responded, I'm still stuck. Hoping there might be more people here who are using the ESP32 and can either tell me what I'm missing or confirm if there is an issue with the libraries. Basically the problem is that I need to be able to set the WiFi TX power on ESP32 devices. The available settings according to the enum below (taken from WiFiGeneric.h) are:
typedef enum {
WIFI_POWER_19_5dBm = 78,// 19.5dBm
WIFI_POWER_19dBm = 76,// 19dBm
WIFI_POWER_18_5dBm = 74,// 18.5dBm
WIFI_POWER_17dBm = 68,// 17dBm
WIFI_POWER_15dBm = 60,// 15dBm
WIFI_POWER_13dBm = 52,// 13dBm
WIFI_POWER_11dBm = 44,// 11dBm
WIFI_POWER_8_5dBm = 34,// 8.5dBm
WIFI_POWER_7dBm = 28,// 7dBm
WIFI_POWER_5dBm = 20,// 5dBm
WIFI_POWER_2dBm = 8,// 2dBm
WIFI_POWER_MINUS_1dBm = -4// -1dBm
} wifi_power_t;
According to what I've read, the ESP32 will default to maximum WiFi TX power after a reset or power on. That means that when you query the setting using getTxPower(), you should get a value of 78. That indeed is the case for 8 devices I tested. However if you then set the power to maximum using setTxPower(WIFI_POWER_19_5dBm) and then query it using getTxPower(), for 7 out of the 8 devices the value returned is less than 78 (one device returns 59!).
Also setTxPower(WIFI_POWER_MINUS_1dBm) does not work at all, the call returns 0 and querying with getTxPower() returns whatever value was set before trying to change it.
I wrote some test code to try to figure out what is going on, below is the output for the worst device in the batch. None of the 8 devices returned all of the values set, but some were better than others. The code sets up the device as an AP, calls getTxPower(), sends the result to serial, calls setTxPower(WIFI_POWER_19_5dBm), then getTxPower() again and sends the result to serial. Then it sets each power in that enum in turn, queries it and prints the results of that query. No device is connected to the ESP on WiFi.
This post is already too long, but I'll post that test code if someone wants to try it.
I should also note that readback values returned when running the code can be slightly different after a reset which seems odd.
Thanks for any insights,
J
_____________________________________________________________________________________________
setTxPower test results for ESP-WROOM-32 Devkit V1 Module board (38 pin)#1
ets Jul 29 2019 12:21:46
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DOUT, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13260
load:0x40080400,len:3028
entry 0x400805e4
System up: 0:00:00:00 (d:hs)
Freq: 240 MHz
MCU temperature : 53 C
Heap: 338740, free: 313368, min free: 308000, max block: 110580
Chip Info Model: 1
Chip Info Features: 50
Chip Info Cores: 2
Chip Info Revision: 3
Setting AP (Access Point)…
AP IP address: 192.168.4.1
Startup TX Power value: 78
Startup SetTxPower(WIFI_POWER_19_5dBm) returned: OK
Set TX Power value After Startup: 59
Set TX Power| Set Call Status | Set | Readback
-1.0 dBm | Not OK | -4 | 78
2.0 dBm | OK | 8 | 1
5.0 dBm | OK | 20 | 15
7.0 dBm | OK | 28 | 25
8.5 dBm | OK | 34 | 33
11.0 dBm | OK | 44 | 41
13.0 dBm | OK | 52 | 47
15.0 dBm | OK | 60 | 59
17.0 dBm | OK | 68 | 59
18.5 dBm | OK | 74 | 59
19.0 dBm | OK | 76 | 59
19.5 dBm | OK | 78 | 59
typedef enum {
WIFI_POWER_19_5dBm = 78,// 19.5dBm
WIFI_POWER_19dBm = 76,// 19dBm
WIFI_POWER_18_5dBm = 74,// 18.5dBm
WIFI_POWER_17dBm = 68,// 17dBm
WIFI_POWER_15dBm = 60,// 15dBm
WIFI_POWER_13dBm = 52,// 13dBm
WIFI_POWER_11dBm = 44,// 11dBm
WIFI_POWER_8_5dBm = 34,// 8.5dBm
WIFI_POWER_7dBm = 28,// 7dBm
WIFI_POWER_5dBm = 20,// 5dBm
WIFI_POWER_2dBm = 8,// 2dBm
WIFI_POWER_MINUS_1dBm = -4// -1dBm
} wifi_power_t;
According to what I've read, the ESP32 will default to maximum WiFi TX power after a reset or power on. That means that when you query the setting using getTxPower(), you should get a value of 78. That indeed is the case for 8 devices I tested. However if you then set the power to maximum using setTxPower(WIFI_POWER_19_5dBm) and then query it using getTxPower(), for 7 out of the 8 devices the value returned is less than 78 (one device returns 59!).
Also setTxPower(WIFI_POWER_MINUS_1dBm) does not work at all, the call returns 0 and querying with getTxPower() returns whatever value was set before trying to change it.
I wrote some test code to try to figure out what is going on, below is the output for the worst device in the batch. None of the 8 devices returned all of the values set, but some were better than others. The code sets up the device as an AP, calls getTxPower(), sends the result to serial, calls setTxPower(WIFI_POWER_19_5dBm), then getTxPower() again and sends the result to serial. Then it sets each power in that enum in turn, queries it and prints the results of that query. No device is connected to the ESP on WiFi.
This post is already too long, but I'll post that test code if someone wants to try it.
I should also note that readback values returned when running the code can be slightly different after a reset which seems odd.
Thanks for any insights,
J
_____________________________________________________________________________________________
setTxPower test results for ESP-WROOM-32 Devkit V1 Module board (38 pin)#1
ets Jul 29 2019 12:21:46
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DOUT, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13260
load:0x40080400,len:3028
entry 0x400805e4
System up: 0:00:00:00 (d:hs)
Freq: 240 MHz
MCU temperature : 53 C
Heap: 338740, free: 313368, min free: 308000, max block: 110580
Chip Info Model: 1
Chip Info Features: 50
Chip Info Cores: 2
Chip Info Revision: 3
Setting AP (Access Point)…
AP IP address: 192.168.4.1
Startup TX Power value: 78
Startup SetTxPower(WIFI_POWER_19_5dBm) returned: OK
Set TX Power value After Startup: 59
Set TX Power| Set Call Status | Set | Readback
-1.0 dBm | Not OK | -4 | 78
2.0 dBm | OK | 8 | 1
5.0 dBm | OK | 20 | 15
7.0 dBm | OK | 28 | 25
8.5 dBm | OK | 34 | 33
11.0 dBm | OK | 44 | 41
13.0 dBm | OK | 52 | 47
15.0 dBm | OK | 60 | 59
17.0 dBm | OK | 68 | 59
18.5 dBm | OK | 74 | 59
19.0 dBm | OK | 76 | 59
19.5 dBm | OK | 78 | 59