Prevent reboot in offline mode

This commit is contained in:
Phat Nguyen
2024-03-16 08:50:43 +07:00
parent ea3e976232
commit 471448a0f1
2 changed files with 34 additions and 0 deletions

View File

@ -705,6 +705,7 @@ static void webServerInit(void);
static String getServerSyncData(bool localServer); static String getServerSyncData(bool localServer);
static void createMqttTask(void); static void createMqttTask(void);
static void factoryConfigReset(void); static void factoryConfigReset(void);
static void wdgFeedUpdate(void);
/** Init schedule */ /** Init schedule */
bool hasSensorS8 = true; bool hasSensorS8 = true;
@ -717,6 +718,8 @@ String mdnsModelName = "I-9PSL";
int getCO2FailCount = 0; int getCO2FailCount = 0;
uint32_t addToDashboardTime; uint32_t addToDashboardTime;
bool isAddToDashboard = true; bool isAddToDashboard = true;
bool offlineMode = false;
AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, displayAndLedBarUpdate); AgSchedule dispLedSchedule(DISP_UPDATE_INTERVAL, displayAndLedBarUpdate);
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
updateServerConfiguration); updateServerConfiguration);
@ -725,6 +728,7 @@ AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Update);
AgSchedule pmsSchedule(SENSOR_PM_UPDATE_INTERVAL, pmUpdate); AgSchedule pmsSchedule(SENSOR_PM_UPDATE_INTERVAL, pmUpdate);
AgSchedule tempHumSchedule(SENSOR_TEMP_HUM_UPDATE_INTERVAL, tempHumUpdate); AgSchedule tempHumSchedule(SENSOR_TEMP_HUM_UPDATE_INTERVAL, tempHumUpdate);
AgSchedule tvocSchedule(SENSOR_TVOC_UPDATE_INTERVAL, tvocUpdate); AgSchedule tvocSchedule(SENSOR_TVOC_UPDATE_INTERVAL, tvocUpdate);
AgSchedule wdgFeedSchedule(60000, wdgFeedUpdate);
void setup() { void setup() {
EEPROM.begin(512); EEPROM.begin(512);
@ -807,6 +811,8 @@ void setup() {
} else { } else {
ag.ledBar.setEnable(agServer.getLedBarMode() != UseLedBarOff); ag.ledBar.setEnable(agServer.getLedBarMode() != UseLedBarOff);
} }
} else {
offlineMode = true;
} }
/** Show display Warning up */ /** Show display Warning up */
@ -840,6 +846,10 @@ void loop() {
tvocSchedule.run(); tvocSchedule.run();
} }
if (offlineMode) {
wdgFeedSchedule.run();
}
/** Check for handle WiFi reconnect */ /** Check for handle WiFi reconnect */
updateWiFiConnect(); 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() { static void sendPing() {
JSONVar root; JSONVar root;
root["wifi"] = WiFi.RSSI(); root["wifi"] = WiFi.RSSI();

View File

@ -723,6 +723,7 @@ static void webServerInit(void);
static String getServerSyncData(bool localServer); static String getServerSyncData(bool localServer);
static void createMqttTask(void); static void createMqttTask(void);
static void factoryConfigReset(void); static void factoryConfigReset(void);
static void wdgFeedUpdate(void);
bool hasSensorS8 = true; bool hasSensorS8 = true;
bool hasSensorPMS1 = true; bool hasSensorPMS1 = true;
@ -731,12 +732,15 @@ bool hasSensorSGP = true;
uint32_t factoryBtnPressTime = 0; uint32_t factoryBtnPressTime = 0;
String mdnsModelName = ""; String mdnsModelName = "";
int getCO2FailCount = 0; int getCO2FailCount = 0;
bool offlineMode = false;
AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL, AgSchedule configSchedule(SERVER_CONFIG_UPDATE_INTERVAL,
updateServerConfiguration); updateServerConfiguration);
AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer); AgSchedule serverSchedule(SERVER_SYNC_INTERVAL, sendDataToServer);
AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Update); AgSchedule co2Schedule(SENSOR_CO2_UPDATE_INTERVAL, co2Update);
AgSchedule pmsSchedule(SENSOR_PM_UPDATE_INTERVAL, pmUpdate); AgSchedule pmsSchedule(SENSOR_PM_UPDATE_INTERVAL, pmUpdate);
AgSchedule tvocSchedule(SENSOR_TVOC_UPDATE_INTERVAL, tvocUpdate); AgSchedule tvocSchedule(SENSOR_TVOC_UPDATE_INTERVAL, tvocUpdate);
AgSchedule wdgFeedSchedule(60000, wdgFeedUpdate);
void setup() { void setup() {
EEPROM.begin(512); EEPROM.begin(512);
@ -775,6 +779,8 @@ void setup() {
ledSmHandler(APP_SM_WIFI_OK_SERVER_OK_SENSOR_CONFIG_FAILED); ledSmHandler(APP_SM_WIFI_OK_SERVER_OK_SENSOR_CONFIG_FAILED);
delay(DISPLAY_DELAY_SHOW_CONTENT_MS); delay(DISPLAY_DELAY_SHOW_CONTENT_MS);
} }
} else {
offlineMode = true;
} }
ledSmHandler(APP_SM_NORMAL); ledSmHandler(APP_SM_NORMAL);
@ -809,6 +815,10 @@ void loop() {
if (hasSensorPMS2) { if (hasSensorPMS2) {
ag.pms5003t_2.handle(); ag.pms5003t_2.handle();
} }
if (offlineMode) {
wdgFeedSchedule.run();
}
} }
void sendPing() { 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, static void mqtt_event_handler(void *handler_args, esp_event_base_t base,
int32_t event_id, void *event_data) { int32_t event_id, void *event_data) {
esp_mqtt_event_handle_t event = (esp_mqtt_event_handle_t)event_data; esp_mqtt_event_handle_t event = (esp_mqtt_event_handle_t)event_data;