@@ -1029,7 +1029,7 @@ void setupMQTT() {
10291029
10301030 if (cnt_parameters_backup) {
10311031 // this was the first attempt to connect to a new server and it succeeded
1032- Log.notice (F (" MQTT connection successful" CR));
1032+ Log.notice (F (" MQTT connection parameters %d successful" CR), cnt_index );
10331033 cnt_parameters_array[cnt_index].validConnection = true ;
10341034 readCntParameters (cnt_index);
10351035
@@ -1754,6 +1754,7 @@ void setupTLS(int index) {
17541754
17551755/*
17561756 Reboot for Reason Codes
1757+ 0 - Erase and Restart
17571758 1 - Repeated MQTT Connection Failure
17581759 2 - Repeated WiFi Connection Failure
17591760 3 - Failed WiFiManager configuration portal
@@ -1863,7 +1864,7 @@ void blockingWaitForReset() {
18631864 Log.trace (F (" Trigger button Pressed" CR));
18641865 delay (3000 ); // reset delay hold
18651866 if (digitalRead (TRIGGER_GPIO) == LOW) {
1866- Log.trace (F (" Button Held" CR));
1867+ Log.notice (F (" Button Held" CR));
18671868// Switching off the relay during reset or failsafe operations
18681869# ifdef ZactuatorONOFF
18691870 uint8_t level = digitalRead (ACTUATOR_ONOFF_GPIO);
@@ -1877,7 +1878,10 @@ void blockingWaitForReset() {
18771878 Log.trace (F (" mounted file system" CR));
18781879 if (SPIFFS.exists (" /config.json" )) {
18791880 Log.notice (F (" Erasing ESP Config, restarting" CR));
1880- setupWiFiManager (true );
1881+ erase (true );
1882+ } else {
1883+ Log.notice (F (" Erasing ESP Config, without restart" CR));
1884+ erase (false );
18811885 }
18821886 }
18831887 delay (30000 );
@@ -1887,6 +1891,7 @@ void blockingWaitForReset() {
18871891 failSafeMode = true ;
18881892 setupWiFiManager (false );
18891893 }
1894+ ESPRestart (5 );
18901895 }
18911896 }
18921897 }
@@ -2114,8 +2119,9 @@ bool loadConfigFromFlash() {
21142119 strcat (key, index_suffix);
21152120 if (json.containsKey (key)) {
21162121 cnt_parameters_array[i].validConnection = json[key].as <bool >();
2117- } else {
2118- // For backward compatibility, if valid_cnt is not found, we assume the connection is valid
2122+ } else if (i == CNT_DEFAULT_INDEX) {
2123+ // For backward compatibility, if valid_cnt is not found, we assume the connection is valid for CNT_DEFAULT_INDEX
2124+ Log.warning (F (" valid_cnt not found, assuming connection is valid" CR));
21192125 cnt_parameters_array[i].validConnection = true ;
21202126 }
21212127 }
@@ -2170,7 +2176,7 @@ void setupWiFiManager(bool reset_settings) {
21702176 WiFi.mode (WIFI_STA);
21712177
21722178 if (reset_settings)
2173- eraseAndRestart ( );
2179+ erase ( true );
21742180
21752181# ifdef USE_MAC_AS_GATEWAY_NAME
21762182 String s = WiFi.macAddress ();
@@ -2374,9 +2380,6 @@ void setup_ethernet_esp32() {
23742380# endif
23752381 if (ethBeginSuccess) {
23762382 Log.notice (F (" Ethernet started" CR));
2377- Log.notice (F (" OpenMQTTGateway MAC: %s" CR), ETH.macAddress ().c_str ());
2378- Log.notice (F (" OpenMQTTGateway IP: %s" CR), ETH.localIP ().toString ().c_str ());
2379- Log.notice (F (" OpenMQTTGateway link speed: %d Mbps" CR), ETH.linkSpeed ());
23802383 while (!ethConnected && failure_number_ntwk <= maxConnectionRetryNetwork) {
23812384 delay (500 );
23822385 Log.notice (F (" ." CR));
@@ -2398,9 +2401,9 @@ void WiFiEvent(WiFiEvent_t event) {
23982401 Log.notice (F (" Ethernet Connected" CR));
23992402 break ;
24002403 case ARDUINO_EVENT_ETH_GOT_IP:
2401- Log.trace (F (" OpenMQTTGateway MAC: %s" CR), ETH.macAddress ().c_str ());
2402- Log.trace (F (" OpenMQTTGateway IP: %s" CR), ETH.localIP ().toString ().c_str ());
2403- Log.trace (F (" OpenMQTTGateway link speed: %d Mbps" CR), ETH.linkSpeed ());
2404+ Log.notice (F (" OpenMQTTGateway Ethernet MAC: %s" CR), ETH.macAddress ().c_str ());
2405+ Log.notice (F (" OpenMQTTGateway Ethernet IP: %s" CR), ETH.localIP ().toString ().c_str ());
2406+ Log.notice (F (" OpenMQTTGateway Ethernet link speed: %d Mbps" CR), ETH.linkSpeed ());
24042407 gatewayState = GatewayState::NTWK_CONNECTED;
24052408 ethConnected = true ;
24062409 break ;
@@ -2725,7 +2728,7 @@ float intTemperatureRead() {
27252728/*
27262729 Erase flash and restart the ESP
27272730*/
2728- void eraseAndRestart ( ) {
2731+ void erase ( bool restart ) {
27292732 Log.trace (F (" Formatting requested, result: %d" CR), SPIFFS.format ());
27302733
27312734#if defined(ESP8266)
@@ -2734,12 +2737,11 @@ void eraseAndRestart() {
27342737 wifiManager.resetSettings ();
27352738# endif
27362739 delay (5000 );
2737- ESP.reset ();
27382740#else
2739- // esp_task_wdt_delete(NULL);
27402741 nvs_flash_erase ();
2741- ESP.restart ();
27422742#endif
2743+ if (restart)
2744+ ESPRestart (0 );
27432745}
27442746
27452747String stateMeasures () {
0 commit comments