@@ -637,9 +637,14 @@ bool beginWiFi()
637
637
return false ;
638
638
}
639
639
640
+ logger.log (F (" [WiFi] SSID found, begin connection attempt" ), Logger::DEBUG);
641
+ WiFi.persistent (false ); // 2.2.0 Exception (3): #1997
642
+ WiFi.disconnect (true );
643
+ // Begin wifi after disconnecting, to solve a weird bug reported at
644
+ // https://github.com/esp8266/Arduino/issues/1997#issuecomment-436673828
640
645
WiFi.mode (WIFI_STA);
641
- WiFi.begin (ssid. c_str () , pass. c_str () );
642
- return true ;
646
+ WiFi.begin (ssid, pass);
647
+ return true ;
643
648
}
644
649
645
650
bool reconnectWiFi (bool force)
@@ -808,15 +813,31 @@ void setup()
808
813
// first things first ...
809
814
// forces a closed relay,
810
815
// this guarantees an equal working when a user turns the light on
811
- p_var = new GlobalVar ();
812
- auto &logger = p_var->logger ;
813
- logger.log (" [setup] initialize and close the relays" );
814
816
pinMode (pins_arr, OUTPUT);
815
817
digitalWrite (pins_arr, HIGH);
816
818
817
819
// start serial session
818
820
Serial.begin (115200 );
819
- Serial.println ();
821
+ Serial.println (" [setup] setup workspace" );
822
+ p_var = new GlobalVar ();
823
+ auto &logger = p_var->logger ;
824
+ logger.log (" [setup] initialize and close the relays done!" );
825
+
826
+ // if a crash occurs, then do not immediately try to restart,
827
+ // otherwise the releys are flickering all the time
828
+ rst_info *reset_info = ESP.getResetInfoPtr ();
829
+ switch (reset_info ? reset_info->reason : rst_reason::REASON_DEFAULT_RST) {
830
+ case rst_reason::REASON_WDT_RST:
831
+ case rst_reason::REASON_EXCEPTION_RST:
832
+ case rst_reason::REASON_SOFT_WDT_RST:
833
+ logger.log (" [setup] exceptional reset occurred: " + ESP.getResetReason () + " , I'm going to sleep ... " );
834
+ while (true ) {
835
+ delay (1000 );
836
+ }
837
+ break ;
838
+ default :
839
+ break ;
840
+ }
820
841
821
842
// update boot count
822
843
DynamicJsonBuffer jsonBuffer;
0 commit comments