diff --git a/src/app.cpp b/src/app.cpp index 20e47e7b..10e60c92 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -19,6 +19,7 @@ void app::setup(uint32_t timeout) { yield(); addListener(EVERY_SEC, std::bind(&app::uptimeTick, this)); + addListener(EVERY_MIN, std::bind(&app::minuteTick, this)); addListener(EVERY_12H, std::bind(&app::ntpUpdateTick, this)); resetSystem(); diff --git a/src/app.h b/src/app.h index e614d89a..0d5b49cb 100644 --- a/src/app.h +++ b/src/app.h @@ -155,6 +155,8 @@ class app : public ah::Scheduler { ESP.restart(); } + + if (mUpdateNtp) { mUpdateNtp = false; mUtcTimestamp = mWifi->getNtpTime(); @@ -162,6 +164,13 @@ class app : public ah::Scheduler { } } + void minuteTick(void) { + if(0 == mUtcTimestamp) { + if(!mWifi->getApActive()) + mUpdateNtp = true; + } + } + void ntpUpdateTick(void) { if (!mWifi->getApActive()) mUpdateNtp = true; diff --git a/src/config/settings.h b/src/config/settings.h index ea864ede..376dea09 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -245,13 +245,18 @@ class settings { private: void loadDefaults(bool wifi = true) { DPRINTLN(DBG_INFO, F("loadDefaults")); - - memset(&mCfg, 0, sizeof(settings_t)); if(wifi) { snprintf(mCfg.sys.stationSsid, SSID_LEN, FB_WIFI_SSID); snprintf(mCfg.sys.stationPwd, PWD_LEN, FB_WIFI_PWD); - snprintf(mCfg.sys.deviceName, DEVNAME_LEN, DEF_DEVICE_NAME); } + else { + cfgSys_t tmp; + memset(&tmp.adminPwd, 0, PWD_LEN); + memcpy(&tmp, &mCfg.sys, sizeof(cfgSys_t)); + memset(&mCfg, 0, sizeof(settings_t)); + memcpy(&mCfg.sys, &tmp, sizeof(cfgSys_t)); + } + snprintf(mCfg.sys.deviceName, DEVNAME_LEN, DEF_DEVICE_NAME); mCfg.nrf.sendInterval = SEND_INTERVAL; mCfg.nrf.maxRetransPerPyld = DEF_MAX_RETRANS_PER_PYLD; diff --git a/src/defines.h b/src/defines.h index 1c2e5d23..36949daf 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 5 -#define VERSION_PATCH 39 +#define VERSION_PATCH 40 //------------------------------------- typedef struct {