From 471448a0f1c9dac2e016eb3318236573923ee19c Mon Sep 17 00:00:00 2001 From: Phat Nguyen Date: Sat, 16 Mar 2024 08:50:43 +0700 Subject: [PATCH] Prevent reboot in offline mode --- examples/ONE/ONE.ino | 17 +++++++++++++++++ examples/Open_Air/Open_Air.ino | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/examples/ONE/ONE.ino b/examples/ONE/ONE.ino index 5622076..a2fe1e4 100644 --- a/examples/ONE/ONE.ino +++ b/examples/ONE/ONE.ino @@ -705,6 +705,7 @@ static void webServerInit(void); static String getServerSyncData(bool localServer); static void createMqttTask(void); static void factoryConfigReset(void); +static void wdgFeedUpdate(void); /** Init schedule */ bool hasSensorS8 = true; @@ -717,6 +718,8 @@ String mdnsModelName = "I-9PSL"; int getCO2FailCount = 0; uint32_t addToDashboardTime; bool isAddToDashboard = true; +bool offlineMode = false; + AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, displayAndLedBarUpdate); AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, updateServerConfiguration); @@ -725,6 +728,7 @@ AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Update); AgSchedule pmsSchedule(SENSOR_PM_UPDATE_INTERVAL, pmUpdate); AgSchedule tempHumSchedule(SENSOR_TEMP_HUM_UPDATE_INTERVAL, tempHumUpdate); AgSchedule tvocSchedule(SENSOR_TVOC_UPDATE_INTERVAL, tvocUpdate); +AgSchedule wdgFeedSchedule(60000, wdgFeedUpdate); void setup() { EEPROM.begin(512); @@ -807,6 +811,8 @@ void setup() { } else { ag.ledBar.setEnable(agServer.getLedBarMode() != UseLedBarOff); } + } else { + offlineMode = true; } /** Show display Warning up */ @@ -840,6 +846,10 @@ void loop() { tvocSchedule.run(); } + if (offlineMode) { + wdgFeedSchedule.run(); + } + /** Check for handle WiFi reconnect */ updateWiFiConnect(); @@ -1253,6 +1263,13 @@ static void factoryConfigReset(void) { } } +static void wdgFeedUpdate(void) { + ag.watchdog.reset(); + Serial.println(); + Serial.println("External watchdog feed"); + Serial.println(); +} + static void sendPing() { JSONVar root; root["wifi"] = WiFi.RSSI(); diff --git a/examples/Open_Air/Open_Air.ino b/examples/Open_Air/Open_Air.ino index e39da41..1145563 100644 --- a/examples/Open_Air/Open_Air.ino +++ b/examples/Open_Air/Open_Air.ino @@ -723,6 +723,7 @@ static void webServerInit(void); static String getServerSyncData(bool localServer); static void createMqttTask(void); static void factoryConfigReset(void); +static void wdgFeedUpdate(void); bool hasSensorS8 = true; bool hasSensorPMS1 = true; @@ -731,12 +732,15 @@ bool hasSensorSGP = true; uint32_t factoryBtnPressTime = 0; String mdnsModelName = ""; int getCO2FailCount = 0; +bool offlineMode = false; + AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, updateServerConfiguration); AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer); AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Update); AgSchedule pmsSchedule(SENSOR_PM_UPDATE_INTERVAL, pmUpdate); AgSchedule tvocSchedule(SENSOR_TVOC_UPDATE_INTERVAL, tvocUpdate); +AgSchedule wdgFeedSchedule(60000, wdgFeedUpdate); void setup() { EEPROM.begin(512); @@ -775,6 +779,8 @@ void setup() { ledSmHandler(APP_SM_WIFI_OK_SERVER_OK_SENSOR_CONFIG_FAILED); delay(DISPLAY_DELAY_SHOW_CONTENT_MS); } + } else { + offlineMode = true; } ledSmHandler(APP_SM_NORMAL); @@ -809,6 +815,10 @@ void loop() { if (hasSensorPMS2) { ag.pms5003t_2.handle(); } + + if (offlineMode) { + wdgFeedSchedule.run(); + } } void sendPing() { @@ -1819,6 +1829,13 @@ static void factoryConfigReset(void) { } } +static void wdgFeedUpdate(void) { + ag.watchdog.reset(); + Serial.println(); + Serial.println("External watchdog feed"); + Serial.println(); +} + static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) { esp_mqtt_event_handle_t event = (esp_mqtt_event_handle_t)event_data;