khoih-prog / ESP_WiFiManager

This is an ESP32 / ESP8266 WiFi Connection Manager with fallback web configuration portal. Use this library for configuring ESP32 (including ESP32-S2 and ESP32-C3), ESP8266 modules' WiFi, etc. Credentials at runtime. You can also specify static DNS servers, personalized HostName, fixed or random AP WiFi channel. With examples supporting ArduinoJson
MIT License
371 stars 97 forks source link

Avoiding reboot when WiFi is lost. #79

Closed cultur98 closed 2 years ago

cultur98 commented 2 years ago

First of all, thanks for this wonderful software. I use it in various ESP32 projects with great joy. The ESP32_FSWebServer_DRD example is the base for my applications. One of my applications seems to crash the WiFi connection every now and then. Definitely not something which is caused by the ESP_WiFiManager

I and up running in here (line 417 in ESP32_FSWebServer_DRD.ino)

  while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) )
  {
    status = WiFi.status();

    if ( status == WL_CONNECTED )
      break;
    else
      delay(WIFI_MULTI_CONNECT_WAITING_MS);
  }

Which later on causes my ESP32 to reboot.

So I exchanged status = WiFi.status(); by status = wifiMulti.run(); which im my case avoids the reboot and recovers the WiFi connection.

Maybe this is something you can consider as an improvement for the future.

khoih-prog commented 2 years ago

Hi,

That's is just an example to show you how to use the library and it's not expected to be used unchanged for all use-cases.

The reboot is optional at

https://github.com/khoih-prog/ESP_WiFiManager/blob/f72b36fac8a7efccaa7f3aad25448a3865656206/examples/ESP32_FSWebServer_DRD/ESP32_FSWebServer_DRD.ino#L440-L444

Just remove / comment those lines if you don't want the reset for your use case.