Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean way to real, always working, auto-reconnect

I hope to open a question that is useful for the users of this shield.

Incipit: WiFi.setAutoReconnect(true); seems that not prevent 100% of disconnections.

I've tested a lot of shields (ESP12F, ESP01) and in some case i noted that the auto-reconnect does not work properly.

Fact:

  • I was unable to reproduce when the shield is connect to pc/debugger.
  • When did it happen, i try to execute a task depending on a botton press, eg:
 loop(){
     if (digitalRead... == HIGH) do_something()
 }

And the shield... do something! So, the shield was not frozen.

  • I try to reset (BOTH via HW and SW) and the shield immediately reconnect.

I read some other source and this behavior is often described (es. https://randomnerdtutorials.com/solved-reconnect-esp32-to-wifi/ ). Brief: try WiFi.reconnect(), if it does not work try ESP.restart().

Then, the question:

  1. Why does this happen? Is there a problem with the arduino libraries, or with the native expressif interface? Or is a well-known hardware problem unsolvable via SW?

  2. If indeed so, what techniques do you use to prevent disconnection? I have set a ticker every 30 minutes, which if it sees the card disconnected for more than a certain time, it restarts it. Eg.

void checkWifi() {
   if (lastPing + DELTA < millis()) ESP.restart();
}
ticker.attach(checkWifi, ...)

void loop() {
   if WiFi.isConnect() {
       lastPing = millis();
       ...
   }
}
  1. If there is nothing to do, what do you think of the restart technique? Is it risky to restart frequently, can it reduce the life of the device?

Thanks to anyone who wants to contribute or exchange impressions!

like image 898
Massimo Rebuglio Avatar asked Feb 02 '26 10:02

Massimo Rebuglio


1 Answers

After about 1 year, i share the answer i found:

  • there is no a 100% reliable way
  • use ESP32 if it is possible. ESP01..12 are in general less reliable.
  • use watchdogs and reset the shield if wifi does not reconnect for a certain times
like image 80
Massimo Rebuglio Avatar answered Feb 03 '26 22:02

Massimo Rebuglio