Massimo Rebuglio
Massimo Rebuglio

Reputation: 341

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:

 loop(){
     if (digitalRead... == HIGH) do_something()
 }

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

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!

Upvotes: 4

Views: 1213

Answers (1)

Massimo Rebuglio
Massimo Rebuglio

Reputation: 341

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

Upvotes: 1

Related Questions