[SYS] Refactor ESPrestart (#1625)
This commit is contained in:
1 parent
db32df90b8
commit
177fb97715
3 files changed
+26
-29
No files matched your search
+1
-1
@@ -111,7 +111,7 @@ void btScanWDG() {
|
|||||||
scanCount != 0 &&
|
scanCount != 0 &&
|
||||||
(now - lastBtScan > BTConfig.BLEinterval)) {
|
(now - lastBtScan > BTConfig.BLEinterval)) {
|
||||||
Log.error(F("BLE Scan watchdog triggered at : %ds" CR), lastBtScan / 1000);
|
Log.error(F("BLE Scan watchdog triggered at : %ds" CR), lastBtScan / 1000);
|
||||||
watchdogReboot(4);
|
ESPRestart(4);
|
||||||
} else {
|
} else {
|
||||||
previousBtScanCount = scanCount;
|
previousBtScanCount = scanCount;
|
||||||
lastBtScan = now;
|
lastBtScan = now;
|
||||||
|
|||||||
+1
-1
@@ -430,7 +430,7 @@ void handleRoot() {
|
|||||||
|
|
||||||
delay(2000); // Wait for web page to be sent before
|
delay(2000); // Wait for web page to be sent before
|
||||||
|
|
||||||
ESPRestart();
|
ESPRestart(5);
|
||||||
} else {
|
} else {
|
||||||
// WEBUI_TRACE_LOG(F("Arguments %s" CR), message);
|
// WEBUI_TRACE_LOG(F("Arguments %s" CR), message);
|
||||||
server.send(200, "text/plain", "00:14:36.767 RSL: RESULT = {\"Topic\":\"topic\"}");
|
server.send(200, "text/plain", "00:14:36.767 RSL: RESULT = {\"Topic\":\"topic\"}");
|
||||||
|
|||||||
+24
-27
@@ -677,7 +677,7 @@ void connectMQTT() {
|
|||||||
#endif
|
#endif
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
watchdogReboot(1);
|
ESPRestart(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1111,7 +1111,7 @@ void setOTA() {
|
|||||||
ErrorIndicatorOFF();
|
ErrorIndicatorOFF();
|
||||||
SendReceiveIndicatorOFF();
|
SendReceiveIndicatorOFF();
|
||||||
lpDisplayPrint("OTA done");
|
lpDisplayPrint("OTA done");
|
||||||
ESPRestart();
|
ESPRestart(6);
|
||||||
});
|
});
|
||||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||||
Log.trace(F("Progress: %u%%\r" CR), (progress / (total / 100)));
|
Log.trace(F("Progress: %u%%\r" CR), (progress / (total / 100)));
|
||||||
@@ -1132,7 +1132,7 @@ void setOTA() {
|
|||||||
Log.error(F("Receive Failed" CR));
|
Log.error(F("Receive Failed" CR));
|
||||||
else if (error == OTA_END_ERROR)
|
else if (error == OTA_END_ERROR)
|
||||||
Log.error(F("End Failed" CR));
|
Log.error(F("End Failed" CR));
|
||||||
ESPRestart();
|
ESPRestart(6);
|
||||||
});
|
});
|
||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
}
|
}
|
||||||
@@ -1186,7 +1186,18 @@ void setupTLS(bool self_signed, uint8_t index) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ESPRestart() {
|
/*
|
||||||
|
Reboot for Reason Codes
|
||||||
|
1 - Repeated MQTT Connection Failure
|
||||||
|
2 - Repeated WiFi Connection Failure
|
||||||
|
3 - Failed WiFiManager configuration portal
|
||||||
|
4 - BLE Scan watchdog
|
||||||
|
5 - User requested reboot
|
||||||
|
6 - OTA Update
|
||||||
|
7 - Parameters changed
|
||||||
|
*/
|
||||||
|
void ESPRestart(byte reason) {
|
||||||
|
Log.warning(F("Rebooting for reason code %d" CR), reason);
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
@@ -1229,12 +1240,12 @@ void setup_wifi() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (failure_number_ntwk > maxRetryWatchDog) {
|
if (failure_number_ntwk > maxRetryWatchDog) {
|
||||||
watchdogReboot(2);
|
ESPRestart(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# else
|
# else
|
||||||
if (failure_number_ntwk > maxRetryWatchDog) {
|
if (failure_number_ntwk > maxRetryWatchDog) {
|
||||||
watchdogReboot(2);
|
ESPRestart(2);
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
@@ -1478,9 +1489,8 @@ void setup_wifimanager(bool reset_settings) {
|
|||||||
esp_wifi_set_config(WIFI_IF_AP, &conf);
|
esp_wifi_set_config(WIFI_IF_AP, &conf);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
//reset and try again
|
//restart and try again
|
||||||
watchdogReboot(3);
|
ESPRestart(3);
|
||||||
delay(5000);
|
|
||||||
}
|
}
|
||||||
InfoIndicatorOFF();
|
InfoIndicatorOFF();
|
||||||
ErrorIndicatorOFF();
|
ErrorIndicatorOFF();
|
||||||
@@ -2371,14 +2381,14 @@ void MQTTHttpsFWUpdate(char* topicOri, JsonObject& HttpsFwUpdateData) {
|
|||||||
# ifndef ESPWifiManualSetup
|
# ifndef ESPWifiManualSetup
|
||||||
saveMqttConfig();
|
saveMqttConfig();
|
||||||
# endif
|
# endif
|
||||||
ESPRestart();
|
ESPRestart(6);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SendReceiveIndicatorOFF();
|
SendReceiveIndicatorOFF();
|
||||||
ErrorIndicatorOFF();
|
ErrorIndicatorOFF();
|
||||||
|
|
||||||
ESPRestart();
|
ESPRestart(6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2392,7 +2402,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
const char* cmd = SYSdata["cmd"];
|
const char* cmd = SYSdata["cmd"];
|
||||||
Log.notice(F("Command: %s" CR), cmd);
|
Log.notice(F("Command: %s" CR), cmd);
|
||||||
if (strstr(cmd, restartCmd) != NULL) { //restart
|
if (strstr(cmd, restartCmd) != NULL) { //restart
|
||||||
ESPRestart();
|
ESPRestart(5);
|
||||||
} else if (strstr(cmd, eraseCmd) != NULL) { //erase and restart
|
} else if (strstr(cmd, eraseCmd) != NULL) { //erase and restart
|
||||||
# ifndef ESPWifiManualSetup
|
# ifndef ESPWifiManualSetup
|
||||||
setup_wifimanager(true);
|
setup_wifimanager(true);
|
||||||
@@ -2426,7 +2436,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
setESP32WifiPorotocolTxPower();
|
setESP32WifiPorotocolTxPower();
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
ESPRestart();
|
ESPRestart(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disconnectClient = false; // Trigger client.disconnet if a user/password change doesn't
|
bool disconnectClient = false; // Trigger client.disconnet if a user/password change doesn't
|
||||||
@@ -2535,7 +2545,7 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
}
|
}
|
||||||
connectMQTT();
|
connectMQTT();
|
||||||
}
|
}
|
||||||
ESPRestart();
|
ESPRestart(7);
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
@@ -2590,16 +2600,3 @@ String toString(uint32_t input) {
|
|||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
Reboot for repeated connection issues
|
|
||||||
Reason Codes
|
|
||||||
1 - Repeated MQTT Connection Failure
|
|
||||||
2 - Repeated WiFi Connection Failure
|
|
||||||
3 - Failed WiFiManager configuration portal
|
|
||||||
4 - BLE Scan watchdog
|
|
||||||
*/
|
|
||||||
void watchdogReboot(byte reason) {
|
|
||||||
Log.warning(F("Rebooting for reason code %d" CR), reason);
|
|
||||||
ESPRestart();
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user