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