Page 1 of 1

ESP32 set WiFi power problems

Posted: Mon Sep 18, 2023 11:21 am
by JMcC_ESP
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:h:m:s)
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

Re: ESP32 set WiFi power problems

Posted: Tue Sep 19, 2023 1:58 am
by lbernstone
https://docs.espressif.com/projects/esp ... wer6int8_t
The values are a bit off, but those ranges are somewhat subject to phy specific calibration.
My guess as to why it is setting it low is that when it first starts, it ignores restrictions and sets it to 78, but if you manually set it, it follows the country code restrictions.

Re: ESP32 set WiFi power problems

Posted: Tue Sep 19, 2023 9:25 am
by JMcC_ESP
Well that sounds plausible but my code does not set any country related stuff and the device is in AP mode only, so how would it know where it is? My phone connects to it on the device network, so I guess its possible that the phone somehow communicates country info, but even that does not seem right as the setting will be at 78 until I try to set power to any value. Maybe something happens at compile time bsased on the computer locale?

I tried looking into the country thing, but did not get far yet. These device is supposed to default to CN on boot. Do you know of a way to query this? I might then be able verify if this is being somehow changed automatically.

Now this possible opens another can of worms in so far as if the device defaults to CN on boot, then its possible that a very large number of devices are being operated outside China without the appropriate WiFi settings & power levels for the juristiction in which they are being operated. I don't recall ever seeing code examples that explictly set the country in which the device operates.

There is supposed to be a way of triggering an RF calibration. Anyone know something about that?

Thanks for that link, I'll check it out,

J

Re: ESP32 set WiFi power problems

Posted: Tue Sep 19, 2023 8:24 pm
by lbernstone
Why query it. Change it to what you want.
https://docs.espressif.com/projects/esp ... y_codePKcb

Re: ESP32 set WiFi power problems

Posted: Wed Sep 20, 2023 12:15 pm
by JMcC_ESP
Well I just wanted to confirm that it changes when I set it. I'm still at the stage of figuring out what works if you know what I mean.

Thanks,

J