Open tablatronix opened 4 years ago
I will look into wm as the cause of this issue, since it is occurring on both platforms
I already linked it in #979 but just to have it here again. I don't think it's bug in WifiManager but in the SDK: https://github.com/espressif/arduino-esp32/issues/2501 (nevertheless one that the WifiManager can work around)
BTW I also suspect the router model to be important for this: In my case it's a Fritz!Box 6490.
I’ve been having issues with both the ESP8266 and the ESP32 using v2.x.x of WiFiManager but notably the problem goes away on v0.1.5 on my ESP8266, so it might be worth having a look at what changed inside the autoConnect function?
I agree it’s probably true that WiFi routers also play a part in this, in my case I’m using a Ubiquity nanoHD access point (with two APs, one downstairs, broadcasting on the same SSID). Maybe that has something to do with it?
I confirm also that OpenMQTTGateway users were complaining about this issue with Ubiquity routers.
One difference is we used to always disconnect,
//trying to fix connection in progress hanging
ETS_UART_INTR_DISABLE();
wifi_station_disconnect();
ETS_UART_INTR_ENABLE();
But that adds 2 second startup time
This was removed in dev and made optional
// clean connect, always disconnect before connecting
void setCleanConnect(bool enable); // default false
I have also encountered issues where waitforconresult timesout and never connects ( which takes forever )
A couple things to try that might be causing a race condition.
Try adding this delay and log to this function
bool WiFiManager::wifiConnectDefault(){
bool ret = false;
DEBUG_WM(F("Connecting to SAVED AP:"),WiFi_SSID(true));
DEBUG_WM(DEBUG_DEV,F("Using Password:"),WiFi_psk(true));
ret = WiFi_enableSTA(true,storeSTAmode);
// add these 2 lines
delay(500); // <-- DELAY
DEBUG_WM(DEBUG_DEV,"Mode after delay: "+getModeString(WiFi.getMode())); // <-- LOG
if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi enableSta failed");
ret = WiFi.begin();
if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi begin failed");
return ret;
}
Another thing to try
Remove the sta, begin will do this by itself also
bool WiFiManager::wifiConnectDefault(){
bool ret = false;
DEBUG_WM(F("Connecting to SAVED AP:"),WiFi_SSID(true));
DEBUG_WM(DEBUG_DEV,F("Using Password:"),WiFi_psk(true));
// ret = WiFi_enableSTA(true,storeSTAmode); // <-- REMOVE
// if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi enableSta failed");
ret = WiFi.begin();
if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi begin failed");
return ret;
Also time how long waitforconnectresult takes, I have been meaning to add some debugging there for timing it. Does it take long when it fails?
I have the same issue. Sometimes, totally not reproducible for me (I'm sorry), I even get a crash which seems to be related to this. This happens now as long as I erase the flash and flash the image again.
*WM: [3] setupConfigPortal
*WM: [1] Starting Web Portal
*WM: [3] dns server started with ip: 10.0.1.1
*WM: [2] HTTP server started
*WM: [2] WiFi Scan completed in 2308 ms
*WM: [2] Config Portal Running, blocking, waiting for clients...
Guru Meditation Error: Core 0 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x00000000 PS : 0x00060e30 A0 : 0x80157969 A1 : 0x3ffb4f00
A2 : 0x3ffda6a0 A3 : 0x3ffdae1c A4 : 0x3ffda134 A5 : 0x3ffda8d4
A6 : 0x260d000a A7 : 0x300d000a A8 : 0x8015780c A9 : 0x3ffb4ec0
A10 : 0x3ffda6b0 A11 : 0x3ffdae1c A12 : 0x3ffb4f0c A13 : 0x00000044
A14 : 0x00000001 A15 : 0x00000006 SAR : 0x00000010 EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000 LBEG : 0x4000c349 LEND : 0x4000c36b LCOUNT : 0x00000000
Backtrace: 0x00000000:0x3ffb4f00 0x40157966:0x3ffb4f40 0x40164e71:0x3ffb4f60 0x40169e79:0x3ffb4fa0 0x4016f116:0x3ffb4fc0 0x4015836f:0x3ffb4fe0 0x40088b9d:0x3ffb5010
I have been looking into this issue here https://github.com/espressif/arduino-esp32/issues/2501
And made a PR here for workaround via autoreconnect bugfix https://github.com/espressif/arduino-esp32/pull/6113
I also have an open issue with IDF against the actual cause under review
MY PR was merged, but if you need a solution without a patch
I added a test solution to wm, hardcoded, no setter. I can add a define or setter if its useful
bool _aggresiveReconn = false; // use an agrressive reconnect strategy, WILL delay conxs
// on some conn failure modes will add delays and many retries to work around esp and ap bugs, ie, anti de-auth protections
This adds esp32 event handler for auth fail, and bumps reconnects up and adds delays, I have connect everytime, and my conx time goes to 5s unfortunately until this issue is also fixed in IDF that is what we have..
I have not worked on this issue or tested if it exists in esp8266, I will check that next
Theres seems to be 2 conditions here with different failures, this one for reauth timeout/retry there is also a 4 way handshake timeout or assoc failure which is possibly a different issue
is there a workaround for this one? I tried the _aggressiveReconn = true fix and it connects but gives me an IP = 0.0.0.0
Hmm it shouldnt do you have logs?
here's the output from the serial port:
mounting FS... mounted file system reading config file opened config file {"mqtt_server":"Dffssff","mqtt_port":"8083","api_token":"YOUR_API_T"} parsed json wm:[2] Added Parameter: server wm:[2] Added Parameter: port wm:[2] Added Parameter: apikey wm:[1] AutoConnect wm:[2] ESP32 event handler enabled wm:[2] Connecting as wifi client... wm:[2] setSTAConfig static ip not set, skipping wm:[1] Connecting to SAVED AP: embeddex_2.4GHz wm:[1] connectTimeout not set, ESP waitForConnectResult... E (5966) wifi:Association refused temporarily, comeback time 1048 mSec wm:[2] [EVENT] WIFI_REASON: 203 wm:[2] [EVENT] WIFI_REASON: AUTH FAIL wm:[2] Connection result: WL_CONNECT_FAILED wm:[1] Connect Wifi, ATTEMPT # 2 of 5 wm:[1] Connecting to SAVED AP: embeddex_2.4GHz E (9614) wifi:sta is connecting, return error wm:[1] connectTimeout not set, ESP waitForConnectResult... wm:[2] Connection result: WL_CONNECT_FAILED wm:[1] Connect Wifi, ATTEMPT # 3 of 5 wm:[1] Connecting to SAVED AP: embeddex_2.4GHz wm:[1] connectTimeout not set, ESP waitForConnectResult... wm:[2] Connection result: WL_CONNECTED wm:[1] AutoConnect: SUCCESS wm:[2] Connected in 7782 ms *wm:[1] STA IP Address: connected...yeey :) The values in the file are: mqtt_server : Dffssff mqtt_port : 8083 api_token : YOUR_API_T local ip 0.0.0.0
hmm, that is odd, I may have seen this reported elsewhere, or as a different bug... can you turn on esp debug level 5 or is that all its logging ?
What eps lib version , might want to try updating it , i think I recall a bug like this, ill try to test later
I updated the ESP core version, it seems that it fixed it...
Yeah I couldn't find the issue, but i specifically recall seeing a IDF bug with failing to set ip
I updated the ESP core version, it seems that it fixed it...
I'm still experiencing this issue with ESP core version 3.0.2 (via arduino board manager) on an ESP-12E wm version 2.0.13-beta (via arduino library manager)
Is there a different combination of core and library versions where this works?
Can you provide logs with esp debugging on ?
The esp core should be retrying these connections itself now.
Also seeing this on ESP32 (ESP8266 works fine with same code and on latest WiFiManager commit) - AP mode works, I can choose a network. The saved credentials are then tried but no IP is received and the log says:
*wm:[1] AutoConnect
*wm:[2] Setting Hostnames: ***
*wm:[2] Setting WiFi hostname
[ 164][V][WiFiGeneric.cpp:341] _arduino_event_cb(): STA Stopped
[ 166][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 3 - STA_STOP
[ 185][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
*wm:[2] ESP32 event handler enabled
*wm:[ 190][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
[2] [ 191][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
Connecting as wifi client...
*wm:[2] setSTAConfig static ip not set, skipping
*wm:[1] Connect Wifi, ATTEMPT # 1 of 5
*wm:[1] Connecting to SAVED AP: **
[ 1715][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
*wm:[2] 10000 ms timeout, waiting for connect...
*wm:[2] .
(...)
*wm:[2] .
[ 3973][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: **, BSSID: *:*:*:*:*:*, Reason: 2
[ 3974][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[ 3981][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 2 - AUTH_EXPIRE
[ 3987][D][WiFiGeneric.cpp:966] _eventCallback(): WiFi Reconnect Running
After the last retry, is also shows these lines:
E (61517) wifi:sta is connecting, return error
[ 48003][E][WiFiSTA.cpp:317] begin(): connect failed! 0x3007
I've tried this on multiple devices - some very rare times it did connect but pretty much all of the time it does not. It also does not matter if I set WPA + WPA2, WPA2 only or no auth on the router.
Ok this is a slightly different issue, have you tried the aggressive recon mod above?
It's already included by default, but also tried setting it to false
oh yeah lol
Can you provide logs with esp debugging on ?
The esp core should be retrying these connections itself now.
Hm... While messing around trying to get debug output to work, i discovered that the ESP module is an ESP-12 and not an ESP-12E .. changed this and the issue seems to have vanished... (never got debug output to work)
There has been several issues with problems with wifi not connecting. But after restarts it works. Or every other restart it fails
Sometimes there are errors like wrong password, or ap not found
This issue is for investigating this to find some common issue.
I suspect it is a race condition or router issue with certain SDKs etc. It could also be a simple bug like autoconnect is connecting while esp is auto-connecting and it hangs. Or set sta is not returning fast enough and is asynchronous, there has been proof of this and issues by me created in esp libs.