@@ -509,36 +509,39 @@ void wifiSetup()
509
509
510
510
WiFi.setScanMethod (WIFI_ALL_CHANNEL_SCAN);
511
511
wifiReconnect ();
512
- WiFi.setAutoReconnect (true ); // done in wifiEvery5Seconds
512
+ WiFi.setAutoReconnect (false ); // done in wifiEvery5Seconds
513
513
LOG_TRACE (TAG_WIFI, F (D_WIFI_CONNECTING_TO), wifiSsid);
514
514
}
515
515
#endif
516
516
}
517
517
518
518
bool wifiEvery5Seconds ()
519
519
{
520
+ static uint8_t disconnectionPeriod = 0 ; // WiFi disconnection period counter
521
+
520
522
#if defined(STM32F4xx)
521
- if (wifiShowAP ()) { // no ssid is set yet wait for user on-screen input
522
- return false ;
523
- }
523
+ if (wifiShowAP ()) { // no ssid is set yet wait for user on-screen input
524
+ return false ;
525
+ }
524
526
#else
525
- if (WiFi.getMode () == WIFI_AP || WiFi.getMode () == WIFI_AP_STA) {
526
- LOG_DEBUG (TAG_WIFI, F (" 5sec mode AP %d" ), WiFi.getMode ());
527
- return false ;
528
- }
527
+ if (WiFi.getMode () == WIFI_AP || WiFi.getMode () == WIFI_AP_STA) {
528
+ LOG_DEBUG (TAG_WIFI, F (" 5sec mode AP %d" ), WiFi.getMode ());
529
+ return false ;
530
+ }
529
531
#endif
530
532
531
- if (WiFi.status () == WL_CONNECTED && WiFi.localIP () > 0 ) {
532
- return true ;
533
- }
534
-
535
- // Issue #919 : Reconnects happens to quickly
536
- // if(wifiEnabled) {
537
- // LOG_WARNING(TAG_WIFI, F("No Connection... retry %d"), network_reconnect_counter);
538
- // wifiReconnect();
539
- // }
540
-
541
- return false ;
533
+ if (WiFi.status () == WL_CONNECTED && WiFi.localIP () > 0 ) {
534
+ disconnectionPeriod = 0 ; // Reset the counter if connection was established
535
+ return true ;
536
+ }
537
+
538
+ if (WiFi.status () != WL_CONNECTED) { // If WiFi disconnected...
539
+ if (++disconnectionPeriod >= 6 ) { // If 30 seconds have passed since the disconnection...
540
+ disconnectionPeriod = 0 ; // Restart timeout period
541
+ wifiReconnect (); // Reconnect to WiFi
542
+ }
543
+ }
544
+ return false ;
542
545
}
543
546
544
547
bool wifiValidateSsid (const char * ssid, const char * pass)
0 commit comments