-
Notifications
You must be signed in to change notification settings - Fork 7.6k
printDiag still reporting wrong mode #3707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
WiFi.getMode() returns an enum and not a bitmask. Zero is the enum value for station. If you test for equality rather than bit mask it should work as you expect. |
"WiFi.getMode() returns an enum and not a bitmask" I wish I knew what that meant, but please don't bother trying to explain it. The code uses the same technique as the library itself uses, so let's skip that part of the discussion. The bitmask test works perfectly - the problem is that printDiag reports a value when getMode() returns 0 for the same thing. Testing for equality of e.g. STA doesn't work when more than 1 bit is set as in when its STA+AP - & with the bitmask is the only way to check an individual state e.g just STA or just AP. While that may be an interesting learning experience fro some, its irrelevant to the problem. |
The library does NOT use bitmasks: https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/src/WiFi.cpp#L50-L60
getMode() and printDiag() share one common call, esp_wifi_get_mode. But there are additional checks in getMode() that will result in the value of WIFI_MODE_NULL (zero) being returned, those being related to wifi not initialized. Otherwise the two should be returning the same values.
It works just fine to test for equality since the wifi_mode_t enum defines a type for STA+AP. |
"please don't bother trying to explain it" as your comments are not helpful as well as being plain wrong, yet you persist anyway. I was trying to be polite . "Otherwise the two should be returning the same values" EXACTLY! They don't. So unless you know why, all else it smoke and mirrors. As for bitmasks you are simply talking nonsense - please stop it, it is helping nobody - here's just one snippet of the dozens of times is is used. If you don't know the answer to the problem, please don't comment. And if you don't know the difference between a bitmask and an enum, certainly don't comment. /**
* will force a disconnect an then start reconnecting to AP
* @return ok
*/
bool WiFiSTAClass::reconnect()
{
if(WiFi.getMode() & WIFI_MODE_STA) {
if(esp_wifi_disconnect() == ESP_OK) {
return esp_wifi_connect() == ESP_OK;
}
}
return false;
}
/**
* Disconnect from the network
* @param wifioff
* @return one value of wl_status_t enum
*/
bool WiFiSTAClass::disconnect(bool wifioff, bool eraseap)
{
wifi_config_t conf;
if(WiFi.getMode() & WIFI_MODE_STA){
if(eraseap){
memset(&conf, 0, sizeof(wifi_config_t));
if(esp_wifi_set_config(WIFI_IF_STA, &conf)){
|
@philbowles I won't get into a debate about who is being helpful or bitmasks further, suffice to say we are both right and both wrong. However, WIFI_MODE_NULL is INVALID as far as esp_wifi_set_mode() is concerned and will silently be ignored/dropped by the API. This is why printDiag() is showing STA as it is the last mode that was set via esp_wifi_set_mode(). WiFi.getMode() will return WIFI_MODE_NULL (0) if you call disconnect(true, true) since it shuts off the WiFi driver, you can see this here. These two reasons are why you see different results. |
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
Hardware:
Board: ESP32 Dev Module
Core Installation version: 1.0.4
IDE name: Arduino IDE 1.8.10
Flash Frequency: 80Mhz
PSRAM enabled: NO
Upload Speed: 921600
Computer OS: Windows 10
getMode() returns 0, yet printDiag reports STA - this is just plain WRONG! Do getMode and printDiag retrieve the REAL value of mode from different places? What is going on here - it has been happening for a long time #1306
The text was updated successfully, but these errors were encountered: