Skip to content

WiFi.waitForConnectResult() takes up to 1 hour to return #4309

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

Closed
Raphyyy opened this issue Feb 6, 2018 · 4 comments · Fixed by #5371
Closed

WiFi.waitForConnectResult() takes up to 1 hour to return #4309

Raphyyy opened this issue Feb 6, 2018 · 4 comments · Fixed by #5371

Comments

@Raphyyy
Copy link

Raphyyy commented Feb 6, 2018

Hardware: ESP12E
Core Version: Latest master

Hi,

I noticed since the 2.4.0 (even the latest) I get random network disconnection. Not that hard to handle. But in few case, I get WiFi.waitForConnectResult() taking up to 1 hour to return the result :

Code :

Serial.printf(F("Connecting to %s with key %s...\n"), conf.SSID, conf.WKEY);
WiFi.begin(conf.SSID, conf.WKEY);
delay(50);

if (WiFi.waitForConnectResult() == WL_CONNECTED)
{
	Serial.println(F("WiFi connected"));
	return true;
}

Serial monitor :

[06/02/18 - 01:34:15:776] Connecting to *** with key ***...

[06/02/18 - 02:20:21:509] WiFi connected
[06/02/18 - 06:26:26:208] Connecting to *** with key ***...

[06/02/18 - 06:45:57:847] WiFi connected

It could takes 1 minute or 5 minutes or in that case 45 minutes to return status code.
I have others ESP8266 with same code that are able to connect and send data during those disconnection.
This problem doesn't appear at the beggining. In that case, the problem appears after 10 hours of running with no problems.

Thank you

@tablatronix
Copy link
Contributor

I have noticed this as well, not sure what changed, but waitForConnectResult() just sits in the loop after begin() and nothing happens, not sure whats going on.

@tablatronix
Copy link
Contributor

tablatronix commented Feb 13, 2018

I just noticed if autoreconnect is false waitForConnectResult just sits there, because there is nothing happening, wifi is doing nothing just stays disconnected.

@minida28
Copy link

minida28 commented Jun 2, 2018

I observed the same behavior (setting autoreconnect to false will cause waitForConnectResult just sits forever and nothing happened).

So what is the real use of WiFi.waitForConnectResult() ? Can I safely omit it?
I usually put it after begin(), I am just following example sketchs I found on the net.

Also there are already callbacks available to monitor wifi status such as WiFiEventStationModeConnected, WiFiEventStationModeGotIP or WiFiEventStationModeDisconnected.

@devyte
Copy link
Collaborator

devyte commented Jul 13, 2018

A timeout is needed in here:

while(status() == WL_DISCONNECTED) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants