Unable to change ESP32-S2 Power

Hi,
I’m using ESP32-S2 evkit and I’m trying to change the TX power using the command:
WiFi.setTxPower(70);

I get an error message:
exit status 1
invalid conversion from ‘int’ to ‘wifi_power_t’ [-fpermissive]

This is my code:


#include <SPI.h>
#include <WiFi.h>

Serial.begin(115200);

char ssid[] = "SSID1"
char pass[] = "PASS1";
void setup()
{
 
 WiFi.mode(WIFI_STA);
 delay(100);
 WiFi.begin(ssid, pass);
 delay(5000);
 }

void loop()
 {
  delay(1000);
  if (WiFi.status() != WL_CONNECTED) 
  {
    WiFi.disconnect();
    delay(1000);
    WiFi.begin(ssid, pass);
    delay(5000); // Allowing connection to be established, before reconnecting
  }
  else 
  {
    WiFi.setTxPower(70);
    int a = WiFi.getTxPower();
    Serial.print("TX power:");
    Serial.println(a);
   
    delay(2000);
  }
}

Please advise, Thanks!

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below and post a complete sketch that illustrates the problem

Perhaps doing an internet search on the words “esp32 wifi set power” would provide clues like this clue using the words esp32 wifi set power ?

Thanks, but I couldn’t find an answer to my questions, since the recomendation was to use the command I’ve used and another command that did not work (esp_wifi_set_max_tx_power)

The ESP32-S2 core for Arduino (which is produced by Espressif) appears to have undergone changes recently.

Best to raise an issue directly with Espressif.

I have raised one issue recently, the Servo\PWM commands dont seem to work properly and really only Espressif can fix that sort of stuff.

WiFi.h for the ESP32 has many #include statements

#include "WiFiGeneric.h"

If you look in that file you will see this enum for wifi_power_t

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;

If you substitute one of the enum values in the .setTxPower( ) the code will compile without error.

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "SSID1";
char pass[] = "PASS1";

void setup()
{
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  delay(100);
  WiFi.begin(ssid, pass);
  delay(5000);
}

void loop()
{
  delay(1000);
  if (WiFi.status() != WL_CONNECTED)
  {
    WiFi.disconnect();
    delay(1000);
    WiFi.begin(ssid, pass);
    delay(5000); // Allowing connection to be established, before reconnecting
  }
  else
  {
    //WiFi.setTxPower(70);
    WiFi.setTxPower(WIFI_POWER_18_5dBm);
    //WIFI_POWER_18_5dBm = 74
    int a = WiFi.getTxPower();
    Serial.print("TX power:");
    Serial.println(a);

    delay(2000);
  }
}

I am using the 2.0.0 alpha1 development release core through the board manager which includes the S2 and S3 in the master.

Great, problem solved.
I replaced the int value with the enum “WIFI_POWER_18_5_dBm” and now it is working!
Thanks!