Hello i want to check Wifi Status but i dont quite understand why the compiler throws me errors
if (WiFi.getMode() == "WIFI_MODE_AP") {
wlanConnected = false
} else if (WiFi.getMode() == "WIFI_MODE_STA") {
wlanConnected = true
}
Double "==" error
no match for 'operator==' (operand types are 'wifi_mode_t' and 'const char [14]')
Single "=" error
lvalue required as left operand of assignment
Im probably missing something easy here ...
wlanConnected = false
Missing semicolons for a start
Ah true, i missed it, but same problem with semicolons
Post your complete sketch and error message following the advice in How to get the best out of this forum
is a full sketch nessecary here? the snippet has nothing todo with the remaining code, i think the if statement itself isnt quite right
its just a "lonely" function i call once in loop (for testing)
#include <WiFi.h>
void CheckWifiStatus() {
if (WiFi.getMode() = "WIFI_MODE_STA") {
wlanConnected = false;
} else if (WiFi.getMode() = "WIFI_MODE_STA") {
wlanConnected = true;
}
}
What data type does (WiFi.getMode() return ?
Try printing the value
WIFI_MODE_STA and WIFI_MODE_STA look suspiciously like consts or #defines rather than strings
You seem to be right, its #defines , how do i check them correctly?
Ah well the return values are 2 for ap mode and 1 for sta mode as it seems
void CheckWifiStatus() {
if (WiFi.getMode() == 2) {
wlanConnected = false;
} else if (WiFi.getMode() == 1) {
wlanConnected = true;
}
}
works as expected, thanks alot
To make the code more explicit you can use the #defined values. Just don't put them in quotes
system
Closed
10
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.