Skip to content
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

CONNECTION PROBLEMS, restart, or every other restart #1067

Open
tablatronix opened this issue May 25, 2020 · 25 comments
Open

CONNECTION PROBLEMS, restart, or every other restart #1067

tablatronix opened this issue May 25, 2020 · 25 comments
Labels
Discussion Further Discussion ongoing ESP32 Esp 32 related issue Upstream/Dependancy Issue exists outside of this lib

Comments

@tablatronix
Copy link
Collaborator

tablatronix commented May 25, 2020

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.

@tablatronix
Copy link
Collaborator Author

I will look into wm as the cause of this issue, since it is occurring on both platforms

@TheNitek
Copy link

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: espressif/arduino-esp32#2501 (nevertheless one that the WifiManager can work around)

@TheNitek
Copy link

BTW I also suspect the router model to be important for this: In my case it's a Fritz!Box 6490.

@alfo
Copy link

alfo commented May 25, 2020

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?

@1technophile
Copy link

I confirm also that OpenMQTTGateway users were complaining about this issue with Ubiquity routers.

@tablatronix
Copy link
Collaborator Author

tablatronix commented May 26, 2020

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 )

@tablatronix
Copy link
Collaborator Author

tablatronix commented May 26, 2020

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?

@thewavelength
Copy link

thewavelength commented Aug 18, 2020

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

@tablatronix tablatronix added Upstream/Dependancy Issue exists outside of this lib and removed bug Validated BUG labels Aug 21, 2021
@tablatronix
Copy link
Collaborator Author

I have been looking into this issue here
espressif/arduino-esp32#2501

And made a PR here for workaround via autoreconnect bugfix
espressif/arduino-esp32#6113

I also have an open issue with IDF against the actual cause under review

@tablatronix
Copy link
Collaborator Author

tablatronix commented Jan 24, 2022

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

@tablatronix
Copy link
Collaborator Author

tablatronix commented Jun 17, 2022

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

@dddhhhrrr
Copy link

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

@tablatronix
Copy link
Collaborator Author

Hmm it shouldnt do you have logs?

@dddhhhrrr
Copy link

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

@tablatronix
Copy link
Collaborator Author

tablatronix commented Jun 21, 2022

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 ?

@tablatronix
Copy link
Collaborator Author

tablatronix commented Jun 21, 2022

What eps lib version , might want to try updating it , i think I recall a bug like this, ill try to test later

@dddhhhrrr
Copy link

I updated the ESP core version, it seems that it fixed it...

@tablatronix
Copy link
Collaborator Author

tablatronix commented Jun 22, 2022

Yeah I couldn't find the issue, but i specifically recall seeing a IDF bug with failing to set ip

@tablatronix tablatronix added the ESP32 Esp 32 related issue label Aug 11, 2022
@Robotto
Copy link

Robotto commented Oct 14, 2022

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?

@tablatronix
Copy link
Collaborator Author

Can you provide logs with esp debugging on ?

The esp core should be retrying these connections itself now.

@kjyv
Copy link

kjyv commented Oct 21, 2022

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.

@tablatronix
Copy link
Collaborator Author

Ok this is a slightly different issue, have you tried the aggressive recon mod above?

@kjyv
Copy link

kjyv commented Oct 22, 2022

It's already included by default, but also tried setting it to false

@tablatronix
Copy link
Collaborator Author

oh yeah lol

@Robotto
Copy link

Robotto commented Oct 23, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Further Discussion ongoing ESP32 Esp 32 related issue Upstream/Dependancy Issue exists outside of this lib
Projects
None yet
Development

No branches or pull requests

8 participants