ESP32 (WROOM-32) WiFi power strangeness

Hi,

This is long, but trying to give complete info.
I'm using an ESP32-WROOM-32 module and I'm need to change the WiFi TX power setting. I'm using commands like:
WiFi.setTxPower(WIFI_POWER_15dBm);

The commands are invoked by operating a slider on a webserver page running on the device. The paramaters governing the power value are setout in a file called WiFiGeneric.h as follows:

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;

The slider on the webpage has a minimum value of 0 and a maximum value of 11. In my code I read that slider value as shown in the code fragement below and use it in a switch statement with the aim of being able to set all valid power values easily:

  server.on("/slider", HTTP_GET, [](AsyncWebServerRequest* request) {
    String inputMessage;
    // GET input1 value on <ESP_IP>/slider?value=<inputMessage>
    if (request->hasParam(PARAM_INPUT)) {
      inputMessage = request->getParam(PARAM_INPUT)->value();
      sliderValue = inputMessage;
      Serial.print("sliderValue=");
      Serial.println(sliderValue);
      Serial.print("sliderValueToInt=");
      Serial.println(sliderValue.toInt());
      Serial.print("Set TX Power Value=");
      switch (sliderValue.toInt()) {
        case 0: // set lowest power
          Serial.println(WIFI_POWER_MINUS_1dBm);
          Serial.print("Set power status=");
          Serial.println(WiFi.setTxPower(WIFI_POWER_MINUS_1dBm));
          break;
        case 1:
          Serial.println(WIFI_POWER_2dBm);
          Serial.print("Set power status=");
          Serial.println(WiFi.setTxPower(WIFI_POWER_2dBm));
          break;
        case 2:
          Serial.println(WIFI_POWER_5dBm);
          Serial.print("Set power status=");
          Serial.println(WiFi.setTxPower(WIFI_POWER_5dBm));
          break;
        case 3:
          Serial.println(WIFI_POWER_7dBm);
          Serial.print("Set power status=");
          Serial.println(WiFi.setTxPower(WIFI_POWER_7dBm));
          break;
        case 4:
          Serial.println(WIFI_POWER_8_5dBm);
          Serial.print("Set power status=");
          Serial.println(WiFi.setTxPower(WIFI_POWER_8_5dBm));
          break;
        case 5:
          Serial.println(WIFI_POWER_11dBm);
          Serial.print("Set power status=");
          Serial.println(WiFi.setTxPower(WIFI_POWER_11dBm));
          break;
        case 6:
          Serial.println(WIFI_POWER_13dBm);
          Serial.print("Set power status=");
          Serial.println(WiFi.setTxPower(WIFI_POWER_13dBm));
          break;
        case 7:
          Serial.println(WIFI_POWER_15dBm);
          Serial.print("Set power status=");
          Serial.println(WiFi.setTxPower(WIFI_POWER_15dBm));
          break;
        case 8:
          Serial.println(WIFI_POWER_17dBm);
          Serial.print("Set power status=");
          Serial.println(WiFi.setTxPower(WIFI_POWER_17dBm));
          break;
        case 9:
          Serial.println(WIFI_POWER_18_5dBm);
          Serial.print("Set power status=");
          Serial.println(WiFi.setTxPower(WIFI_POWER_18_5dBm));
          break;
        case 10:
          Serial.println(WIFI_POWER_19dBm);
          Serial.print("Set power status=");
          Serial.println(WiFi.setTxPower(WIFI_POWER_19dBm));
          break;
        case 11: // set highest power
          Serial.println(WIFI_POWER_19_5dBm);
          Serial.print("Set power status=");
          Serial.println(WiFi.setTxPower(WIFI_POWER_19_5dBm));
          break;
      }
      delay(1000);
      int a = WiFi.getTxPower();
      Serial.print("Get TX Power value:");
      Serial.println(a);
      Serial.print("ESP Module RSSI: ");
      Serial.print(WiFi.RSSI());
      Serial.println("dBm");
    } 
    else {
      inputMessage = "No message sent";
    }
    request->send(200, "text/plain", "OK");
  });

Starting with the slider at 11 and going down in steps of -1 to position 0, I get the following debug output. After the call to setTxPower, I read back using getTxPower, a few values returned are not as set and in slider position 0, the call to set the TX power seems to fail.

sliderValue=11
sliderValueToInt=11
Set TX Power Value=78
Set power status=1 * a 1 here indicates the setTxPower call executed OK (I think)
Get TX Power value:78
ESP Module RSSI: -53dBm

sliderValue=10
sliderValueToInt=10
Set TX Power Value=76
Set power status=1
Get TX Power value:72 * should be 76????
ESP Module RSSI: -53dBm

sliderValue=9
sliderValueToInt=9
Set TX Power Value=74
Set power status=1
Get TX Power value:72 * should be 74????
ESP Module RSSI: -53dBm

sliderValue=8
sliderValueToInt=8
Set TX Power Value=68
Set power status=1
Get TX Power value:66 * should be 66????
ESP Module RSSI: -52dBm

sliderValue=7
sliderValueToInt=7
Set TX Power Value=60
Set power status=1
Get TX Power value:60
ESP Module RSSI: -54dBm

sliderValue=6
sliderValueToInt=6
Set TX Power Value=52
Set power status=1
Get TX Power value:52
ESP Module RSSI: -54dBm

sliderValue=5
sliderValueToInt=5
Set TX Power Value=44
Set power status=1
Get TX Power value:44
ESP Module RSSI: -54dBm

sliderValue=4
sliderValueToInt=4
Set TX Power Value=34
Set power status=1
Get TX Power value:34
ESP Module RSSI: -52dBm

sliderValue=3
sliderValueToInt=3
Set TX Power Value=28
Set power status=1
Get TX Power value:28
ESP Module RSSI: -53dBm

sliderValue=2
sliderValueToInt=2
Set TX Power Value=20
Set power status=1
Get TX Power value:20
ESP Module RSSI: -53dBm

sliderValue=1
sliderValueToInt=1
Set TX Power Value=8
Set power status=1
Get TX Power value:8
ESP Module RSSI: -53dBm

sliderValue=0
sliderValueToInt=0
Set TX Power Value=-4
Set power status=0 * seems the setTxPower call failed????
Get TX Power value:8 * no change from slider at 1 position, this value is whatever the previously set value was
ESP Module RSSI: -52dBm

Hoping someone has an idea whats going on here, I sure don't. Likely I'm doing something stupid! (maybe its a 1D10T error).

Thanks for any info,

J

Try setting the power value locally (not through the browser) then reading it back as a first step.
Try setting the power value outside of the print statement as a second step.

I just inserted a number of setTxPower calls at the end of my setup routine with the same debug stuff as I used initially. The results are exactly the same unfortunately. I had already called the setTxPower routine outside print statements. I had only put those in when things were not working as expected.

It was worth a shot just to decouple from the webserver stuff somewhat, thanks for the suggestion!

J

Some WiFi radios can only be set to specific discrete levels. -1dBm might not be supported, and therefore, the setTxPower function may be failing.

Any idea where to find info on that? The only info on powers I've found so far is that enum.

Thanks,

J

The first place to check would be the documentation for the WiFi chipset you are using. Manufacturers often specify what power levels can be set and how to do it.

I got these power levels from the espressif documentation on github for the arduino core
arduino-esp32/libraries/WiFi/src/WiFiGeneric.h
So I think you had them correct.

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;

Yep, thats where I got those. I've done some testing with 8 different modules now and had strange results. All modules were setup as AP & test code simply checks power values after setting each level, outputting the results to the serial console. No device connected to the AP.

Calling getTxPower() after a reset gives a value of 78 for all modules (WIFI_POWER_19_5dBm) in all cases. However for most modules tested, calling setTxPower(WIFI_POWER_19_5dBm) does not necessarily mean that a subsequent call to getTxPower() will return 78, for most modules it does not. Also, setting all the values in the enum in sequence and then calling getTxPower() returns a different number than expected for some of the other power settings. See a test output below from one module.

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 0x400805e4System 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
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

One of the worst modules tested was a 38 pin Devkit V1 with ESP32-WROOM32 (test output above). One of those had very low maximum powers after a call to setTxPower() (15dBm if we take the numbers in the enum as good!). The other Devkit V1 I tested was good.

Running my test code which simply checks power values after setting each level, I noticed many of the ESP32-CAM modules also had low maximum powers after a call to setTxPower() as well as differing power values after subsequesent resets/powerons.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.