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

Reconnect to wifi #26

Closed
Turbox35 opened this issue Jun 14, 2024 · 8 comments · Fixed by #32
Closed

Reconnect to wifi #26

Turbox35 opened this issue Jun 14, 2024 · 8 comments · Fixed by #32
Labels
bug Something isn't working

Comments

@Turbox35
Copy link

I have an issue about wifi. Indeed, after an firmware update of my router I discovered that the ESP32 didn't reconnect. I have to reboot it to see it again on the network.
I made additionals test, each time I reset my wifi or reboot my router, the ESP32 didn't reconnect.
I have a lot of devices at home (with some esp) and this is the only one with this behaviour.
How is implemented the strategy when the device lost the wifi connexion ?

@tspopp
Copy link
Owner

tspopp commented Jun 14, 2024

Well, this one is interesting. I thought I fixed automatic WiFi reconnect in b21f532

Back then I've found several examples, which suggested doing it this way. Since I've never observed any issues, I thought it just works 🤷‍♂️ Will look into this, as soon I have time.

@tspopp tspopp added the bug Something isn't working label Jun 14, 2024
@tspopp
Copy link
Owner

tspopp commented Jun 18, 2024

I tried to recreate the issue yesterday: I've been playing around with a WiFi hotspot created using my Android phone. The esp is always reconnecting in case WiFi hotspot is disabled and reenabled.

Maybe it is due to the network topology or router, but it is strange, since the auto reconnect behavior seems to be the default arduino esp32 behavior anyway 🤷‍♂️ What kind of router are you using?

Do you use the latest platform framework libraries? Maybe a pio pkg update before building helps? If there has been an issue in the arduino framework, a pkg update might resolve it...

@Turbox35
Copy link
Author

Hello @tspopp ,
Thanks for your help.
On my side, I made additionals tests.

If I restart WiFi on my router, it succeeds to reconnect. If I reboot my router, it fails to reconnect. I see nothing on router logs.
For the difference between both WiFi restarting is the time without WiFi, as it takes 20s for WiFi restart and more than 1min for the router reboot.

I have reflashed the esp after an pio pkg update but it changes nothing.

@kopierschnitte
Copy link

kopierschnitte commented Aug 17, 2024

Well, unfortunately, I can confirm the behaviour. Today, I needed to reconfigure my Ubiquiti stuff and this caused a WiFi downtime of about 30s. Every device reconnected, even plenty of ESP32s (WLED, e.g.) but the AquaMQTT didn't.

Although, my console told me, it was still connected but didn't receive an IP.

According to https://esp32.com/viewtopic.php?f=19&t=39116 it could be a problem that the WiFi.setAutoReconnect function doesn't work if the station gets "properly" disconnected (AP sending a disconnect message). It only seems to work if the loss of WiFi appears suddenly and uncontrolled.

One suggests that you could actively monitor the WiFi events and act accordingly. Maybe by introducing a loop or even doing a complete reboot after x sec of no connectivity?

@tspopp
Copy link
Owner

tspopp commented Aug 17, 2024

Hm, I hoped they address such issues within the official esp32 framework libraries and I don't need an individual hack in a loop to check for WiFi connectivity. Reboot is not an option, we would loose any configuration previously made through MQTT since previous configuration is currently not stored/restored.

I will try re-creating this issue as soon as I have some spare time. I really want to make sure the fix will address the issue and does not cause any other side effects..

@tspopp
Copy link
Owner

tspopp commented Aug 19, 2024

I was not able to reproduce the issue, but I basically followed the advice do not trust the auto reconnect routine, just as proposed by @kopierschnitte. Therefore I added something customized which is basically sequentially checking for the WiFi connection and attempting a hard reconnect if something is wrong. I've tested this using an Android Hotspot and it was always reconnecting fine. I hope this will finally address this issue.

I will close this issue as soon as I've merged the PR, but you may feel free to reopen it in case it re-occurs.

@Turbox35
Copy link
Author

Thanks, I have updated the Arduino with the new code, I will inform you if the problem is solved.

@Turbox35
Copy link
Author

Turbox35 commented Sep 9, 2024

Hello,
After a reboot of the rooter, the arduino is still alive on the network. So, it seems solved.
Thanks a lot and have a nice day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants