From d7eb4a0b982f7ca8a10ecf5db51394229f4ccc2b Mon Sep 17 00:00:00 2001 From: tastendruecker123 <111116980+tastendruecker123@users.noreply.github.com> Date: Mon, 17 Apr 2023 16:56:24 +0200 Subject: [PATCH] added option to reboot ahoy every 24 hours --- src/app.cpp | 8 ++++++++ src/config/settings.h | 4 ++++ src/web/RestApi.h | 1 + src/web/html/setup.html | 5 +++++ src/web/web.h | 1 + 5 files changed, 19 insertions(+) diff --git a/src/app.cpp b/src/app.cpp index d2d87f50..742b2fd2 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -193,6 +193,14 @@ void app::tickNtpUpdate(void) { uint32_t midTrig = gTimezone.toUTC(localTime - (localTime % 86400) + 86400); // next midnight local time onceAt(std::bind(&app::tickMidnight, this), midTrig, "midNi"); } + if (mConfig->sys.schedReboot) { + uint32_t localTime = gTimezone.toLocal(mTimestamp); + uint32_t rebootTrig = gTimezone.toUTC(localTime - (localTime % 86400) + 86410); // reboot 10 secs after midnght + if (rebootTrig <= mTimestamp) { //necessary for times other than midnight to prevent reboot loop + rebootTrig += 86400; + } + onceAt(std::bind(&app::tickReboot, this), rebootTrig, "midRe"); + } } nxtTrig = isOK ? 43200 : 60; // depending on NTP update success check again in 12 h or in 1 min diff --git a/src/config/settings.h b/src/config/settings.h index d04fdce5..c88565d4 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -64,6 +64,7 @@ typedef struct { char adminPwd[PWD_LEN]; uint16_t protectionMask; bool darkMode; + bool schedReboot; // wifi char stationSsid[SSID_LEN]; @@ -338,6 +339,7 @@ class settings { mCfg.sys.protectionMask = DEF_PROT_INDEX | DEF_PROT_LIVE | DEF_PROT_SERIAL | DEF_PROT_SETUP | DEF_PROT_UPDATE | DEF_PROT_SYSTEM | DEF_PROT_API | DEF_PROT_MQTT; mCfg.sys.darkMode = false; + mCfg.sys.schedReboot = true; // restore temp settings if(keepWifi) memcpy(&mCfg.sys, &tmp, sizeof(cfgSys_t)); @@ -409,6 +411,7 @@ class settings { obj[F("adm")] = mCfg.sys.adminPwd; obj[F("prot_mask")] = mCfg.sys.protectionMask; obj[F("dark")] = mCfg.sys.darkMode; + obj[F("reb")] = mCfg.sys.schedReboot; ah::ip2Char(mCfg.sys.ip.ip, buf); obj[F("ip")] = String(buf); ah::ip2Char(mCfg.sys.ip.mask, buf); obj[F("mask")] = String(buf); ah::ip2Char(mCfg.sys.ip.dns1, buf); obj[F("dns1")] = String(buf); @@ -421,6 +424,7 @@ class settings { getChar(obj, F("adm"), mCfg.sys.adminPwd, PWD_LEN); getVal(obj, F("prot_mask"), &mCfg.sys.protectionMask); getVal(obj, F("dark"), &mCfg.sys.darkMode); + getVal(obj, F("reb"), &mCfg.sys.schedReboot); if(obj.containsKey(F("ip"))) ah::ip2Arr(mCfg.sys.ip.ip, obj[F("ip")].as()); if(obj.containsKey(F("mask"))) ah::ip2Arr(mCfg.sys.ip.mask, obj[F("mask")].as()); if(obj.containsKey(F("dns1"))) ah::ip2Arr(mCfg.sys.ip.dns1, obj[F("dns1")].as()); diff --git a/src/web/RestApi.h b/src/web/RestApi.h index fde8c7a4..57bf7a7c 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -207,6 +207,7 @@ class RestApi { obj[F("ssid")] = mConfig->sys.stationSsid; obj[F("device_name")] = mConfig->sys.deviceName; obj[F("dark_mode")] = (bool)mConfig->sys.darkMode; + obj[F("sched_reboot")] = (bool)mConfig->sys.schedReboot; obj[F("mac")] = WiFi.macAddress(); obj[F("hostname")] = mConfig->sys.deviceName; diff --git a/src/web/html/setup.html b/src/web/html/setup.html index 77769fdd..cd3c5a5a 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -28,6 +28,10 @@
Device Name
+
+
Reboot Ahoy at midnight
+
+
Dark Mode
@@ -606,6 +610,7 @@ for(var i of [["device", "device_name"], ["ssid", "ssid"]]) document.getElementsByName(i[0])[0].value = obj[i[1]]; document.getElementsByName("darkMode")[0].checked = obj["dark_mode"]; + document.getElementsByName("schedReboot")[0].checked = obj["sched_reboot"]; e = document.getElementsByName("adminpwd")[0]; if(!obj["pwd_set"]) e.value = ""; diff --git a/src/web/web.h b/src/web/web.h index 056b9e7c..45138760 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -451,6 +451,7 @@ class Web { if (request->arg("device") != "") request->arg("device").toCharArray(mConfig->sys.deviceName, DEVNAME_LEN); mConfig->sys.darkMode = (request->arg("darkMode") == "on"); + mConfig->sys.schedReboot = (request->arg("schedReboot") == "on"); // protection if (request->arg("adminpwd") != "{PWD}") {