-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Wifi disconnection handler triggers but Wifi does not connect again #2174
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
Extra information: I noticed that my ESP8266 lost Wifi connection and did not reconnect. To be able to test this situation I tried with WiFi.disconnect(). Is this indeed a good test to simulate ESP8266 losing Wifi connection? |
As it was before, you should not do any lengthy operations from WiFi event callbacks. Certainly not run a loop waiting for the connection. You can set a flag in disconnect callback and then check the value of flag in your |
Thank you for the answer. A good note, I was not aware of the fact that ESP will automatically reconnect. Probably the issue I created is going to be resolved because of your suggestion. I will let you know what I changed and if it works after that. |
I changed the code as follows: introduced a variable disconnected which I set to 1 at init. When a disconnect is detected it is set to 1. The reconnect function then triggers. Now it is working. Tested it both ways:
|
For me it's working now. At least with a disconnection handler. |
I also took a look at the other suggestion: without any manual function it should reconnect. But then I do no see it reconnecting. Tonight I will do some more testing, to see if my conclusion is indeed right. |
Update: last night I got a real disconnection. But the connection did not recover. |
I took out the disconnection handler. Also took out the "kill wifi" function I created. And I tested what happened at a reboot of my router. That indeed was the case. So, I guess I just misunderstood some things and it appears to be working like a charm. Now I will keep an eye on real world disconnection and see what happens. But I suspect it will pick up Wifi again. |
It may be related. I spotted such behavior : if ESP set as AP is powered down and then powered up then client easily connect to it again.No problems. However if client is powered down during transmission to the server set on ESP module in AP mode then when powered is returned client seems to connect but got no response from server (timeout waiting for client.print from server) then after a few successful connections (but without data handshaking) it fails even to connect to the server, even with resetting module. The only way to reconnect both modules is to reset AP module then station module. What am I missing ? The IP address is the same , because server on AP module is not turned off it just seems to hang if client disconnects abruptly during communication. |
@igrr: the issue that I found in the beginning is working for me now:
Now I'm waiting on a real situation where Wifi is lost and reconnected again. Now boguslawb added an extra observation and possible issue. Should we split off that observation/issue? Then we close the issue I created after I see it working as expected. |
The issue @boguslawb mentions doesn't look related to this one. I'd venture to say that the behaviour is due to failure to check if client connection is still established. It is likely that the code was copied from one of example sketches and lacks sufficient error checking. |
I turned off my wifi access point for several minutes and turned it back on; the first time I did this, the ESP8266 reconnected automatically; the second time it did not and remained in the (6) disconnected status. Running a wifi scan shows the access point available, but it does not attempt to connect. Fortunately I have code that will reset automatically if wifi is lost for more than 30 minutes (and then it does connect properly), but this appears to be a genuine problem. |
I am using latest Git version.
Lately the usage of Wifi.onEvent() was changed, see WiFi event handling refactoring #2119
The function that I am using to connect Wifi is working at boot time of ESP8266.
Then when I make Wifi disconnect by calling WiFi.disconnect(), I can see that the connectWifi() is triggered. Till so far that is as expected.
But what I notice is that Wifi is not picking the connection again.
Am I doing something wrong in the connectWifi() function?
I have registered a disconnection handler.
mDisconnectHandler = WiFi.onStationModeDisconnected(&onDisconnected);
I have the following connectWifi function.
The text was updated successfully, but these errors were encountered: