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!
1 Like
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
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
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 ?
Idahowalker:
“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)
srnet
May 6, 2021, 1:54pm
5
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.
cattledog:
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;
Great, problem solved.
I replaced the int value with the enum "WIFI_POWER_18_5_dBm" and now it is working!
Thanks!
system
Closed
September 6, 2021, 9:02am
8
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.