From 8a237059fdbb3788b49e33387b5fd36018231367 Mon Sep 17 00:00:00 2001 From: Ray Jones Date: Sun, 1 Sep 2019 17:35:12 +1000 Subject: [PATCH] Added JSON driven watchdog --- src/Afterburner.cpp | 19 +++++++++++++++++++ src/Utility/BTC_JSON.cpp | 3 +++ src/Utility/NVStorage.cpp | 8 ++++---- src/Utility/NVStorage.h | 2 +- src/Utility/helpers.h | 1 + 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Afterburner.cpp b/src/Afterburner.cpp index 2c3cf16..2b25fb5 100644 --- a/src/Afterburner.cpp +++ b/src/Afterburner.cpp @@ -215,6 +215,7 @@ bool bBTconnected = false; long BootTime; hw_timer_t *watchdogTimer = NULL; +hw_timer_t *JSONwatchdog = NULL; //////////////////////////////////////////////////////////////////////////////////////////////////////// // Bluetooth instantiation @@ -455,6 +456,11 @@ void setup() { timerAlarmEnable(watchdogTimer); //enable interrupt #endif + JSONwatchdog = timerBegin(1, 80, true); + timerAlarmWrite(JSONwatchdog, 60000000, false); //set time in uS must be fed within this time or reboot + timerAttachInterrupt(JSONwatchdog, &interruptReboot, true); + timerAlarmDisable(JSONwatchdog); //disable interrupt for now + FilteredSamples.ipVolts.setRounding(0.1); FilteredSamples.GlowAmps.setRounding(0.01); FilteredSamples.GlowVolts.setRounding(0.1); @@ -1611,6 +1617,19 @@ void feedWatchdog() timerAlarmWrite(watchdogTimer, 15000000, false); //set time in uS must be fed within this time or reboot } +void doJSONwatchdog(int topup) +{ + if(topup) { + timerWrite(JSONwatchdog, 0); //reset timer (feed watchdog) + uint64_t deathtime = topup * 1000000; + timerAlarmWrite(JSONwatchdog, deathtime, false); //set time in uS must be fed within this time or reboot + timerAlarmEnable(JSONwatchdog); //enable interrupt + } + else { + timerAlarmDisable(JSONwatchdog); //disable interrupt + } +} + void doStreaming() { diff --git a/src/Utility/BTC_JSON.cpp b/src/Utility/BTC_JSON.cpp index a59d428..453aafe 100644 --- a/src/Utility/BTC_JSON.cpp +++ b/src/Utility/BTC_JSON.cpp @@ -144,6 +144,9 @@ void interpretJsonCommand(char* pLine) if(it->value.as() == 8861) saveNV(); } + else if(strcmp("Watchdog", it->key) == 0) { + doJSONwatchdog(it->value.as()); + } else if(strcmp("DateTime", it->key) == 0) { setDateTime(it->value.as()); bTriggerDateTime = true; diff --git a/src/Utility/NVStorage.cpp b/src/Utility/NVStorage.cpp index 1507cac..0a72478 100644 --- a/src/Utility/NVStorage.cpp +++ b/src/Utility/NVStorage.cpp @@ -426,11 +426,11 @@ sMQTTparams::load() // **** MAX LENGTH is 15 for names **** preferences.begin("mqtt", false); validatedLoad("enabled", enabled, 0, u8inBounds, 0, 1); - validatedLoad("port", port, 0, u16inBounds, 0, 0xffff); + validatedLoad("port", port, 1883, u16inBounds, 0, 0xffff); validatedLoad("qos", qos, 0, u8inBounds, 0, 2); - validatedLoad("host", host, 127, "hostIP"); - validatedLoad("username", username, 31, "username"); - validatedLoad("password", password, 31, "password"); + validatedLoad("host", host, 127, ""); + validatedLoad("username", username, 31, ""); + validatedLoad("password", password, 31, ""); validatedLoad("topic", topic, 31, "Afterburner"); preferences.end(); } diff --git a/src/Utility/NVStorage.h b/src/Utility/NVStorage.h index b802b23..67665a7 100644 --- a/src/Utility/NVStorage.h +++ b/src/Utility/NVStorage.h @@ -223,7 +223,7 @@ struct sMQTTparams : public CESP32_NVStorage { char topic[32]; void init() { enabled = false; - port = 1234; + port = 1883; qos = 0; memset(host, 0, 128); memset(username, 0, 32); diff --git a/src/Utility/helpers.h b/src/Utility/helpers.h index d1287f4..4cab4c0 100644 --- a/src/Utility/helpers.h +++ b/src/Utility/helpers.h @@ -86,6 +86,7 @@ extern float getGlowVolts(); extern float getGlowCurrent(); extern float getFanSpeed(); extern int sysUptime(); +extern void doJSONwatchdog(int topup); void setSSID(const char* name); void setAPpassword(const char* name);