diff --git a/scripts/getVersion.py b/scripts/getVersion.py index ffcc2714..f7c825ce 100644 --- a/scripts/getVersion.py +++ b/scripts/getVersion.py @@ -56,19 +56,16 @@ def readVersion(path, infile): src = path + ".pio/build/esp8266-release/firmware.bin" dst = path + "firmware/" + versionout os.rename(src, dst) - gzip_bin(dst, dst + ".gz") versionout = version[:-1] + "_esp8266_nokia5110_" + sha + ".bin" src = path + ".pio/build/esp8266-nokia5110/firmware.bin" dst = path + "firmware/" + versionout os.rename(src, dst) - gzip_bin(dst, dst + ".gz") versionout = version[:-1] + "_esp8266_ssd1306_" + sha + ".bin" src = path + ".pio/build/esp8266-ssd1306/firmware.bin" dst = path + "firmware/" + versionout os.rename(src, dst) - gzip_bin(dst, dst + ".gz") versionout = version[:-1] + "_esp8285_" + sha + ".bin" src = path + ".pio/build/esp8285-release/firmware.bin" @@ -80,19 +77,16 @@ def readVersion(path, infile): src = path + ".pio/build/esp32-wroom32-release/firmware.bin" dst = path + "firmware/" + versionout os.rename(src, dst) - gzip_bin(dst, dst + ".gz") versionout = version[:-1] + "_esp32_nokia5110_" + sha + ".bin" src = path + ".pio/build/esp32-wroom32-nokia5110/firmware.bin" dst = path + "firmware/" + versionout os.rename(src, dst) - gzip_bin(dst, dst + ".gz") versionout = version[:-1] + "_esp32_ssd1306_" + sha + ".bin" src = path + ".pio/build/esp32-wroom32-ssd1306/firmware.bin" dst = path + "firmware/" + versionout os.rename(src, dst) - gzip_bin(dst, dst + ".gz") # other ESP32 bin files src = path + ".pio/build/esp32-wroom32-release/" diff --git a/src/app.cpp b/src/app.cpp index 7b7c6e0e..96b2e83e 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -33,10 +33,9 @@ void app::setup() { everySec(std::bind(&app::tickSecond, this)); - everyMin(std::bind(&app::tickMinute, this)); - every12h(std::bind(&app::tickNtpUpdate, this)); every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval); #if !defined(AP_ONLY) + once(std::bind(&app::tickNtpUpdate), 2); if((mConfig->sun.lat) && (mConfig->sun.lon)) { mCalculatedTimezoneOffset = (int8_t)((mConfig->sun.lon >= 0 ? mConfig->sun.lon + 7.5 : mConfig->sun.lon - 7.5) / 15) * 3600; once(std::bind(&app::tickCalcSunrise, this), 5); @@ -131,6 +130,15 @@ void app::loop(void) { mMqtt.loop(); } +//----------------------------------------------------------------------------- +void app::tickNtpUpdate(void) { + uint32_t nxtTrig = 5; // default: check again in 5 sec + if (mWifi.getNtpTime()) + nxtTrig = 43200; // check again in 12 h + once(std::bind(&app::tickNtpUpdate, this), nxtTrig); +} + + //----------------------------------------------------------------------------- void app::tickCalcSunrise(void) { if (0 == mTimestamp) { @@ -139,7 +147,7 @@ void app::tickCalcSunrise(void) { } ah::calculateSunriseSunset(mTimestamp, mCalculatedTimezoneOffset, mConfig->sun.lat, mConfig->sun.lon, &mSunrise, &mSunset); - uint32_t nxtTrig = mTimestamp - (mTimestamp % 86400) + 86400; // next midnight + uint32_t nxtTrig = mTimestamp - ((mTimestamp + 1000) % 86400) + 86400; // next midnight onceAt(std::bind(&app::tickCalcSunrise, this), nxtTrig); if (mConfig->mqtt.broker[0] > 0) { once(std::bind(&PubMqttType::tickerSun, &mMqtt), 1); diff --git a/src/app.h b/src/app.h index e494cf91..d29e6402 100644 --- a/src/app.h +++ b/src/app.h @@ -143,15 +143,7 @@ class app : public ah::Scheduler { } } - void tickMinute(void) { - if(0 == mTimestamp) { - mUpdateNtp = true; - } - } - - void tickNtpUpdate(void) { - mUpdateNtp = true; - } + void tickNtpUpdate(void); void tickCalcSunrise(void); void tickSend(void); diff --git a/src/defines.h b/src/defines.h index d223d764..866c4296 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 5 -#define VERSION_PATCH 50 +#define VERSION_PATCH 51 //------------------------------------- typedef struct { diff --git a/src/utils/scheduler.h b/src/utils/scheduler.h index d10b56fd..52cdc2b4 100644 --- a/src/utils/scheduler.h +++ b/src/utils/scheduler.h @@ -48,20 +48,28 @@ namespace ah { void loop(void) { mMillis = millis(); mDiff = mMillis - mPrevMillis; - if(mDiff >= 1000) { - if(mMillis < mPrevMillis) { // overflow - mPrevMillis = mMillis; - return; + if (mDiff < 1000) + return; + + mDiffSeconds = 1; + if (mDiff < 2000) + mPrevMillis += 1000; + else { + if (mMillis < mPrevMillis) { // overflow + mDiff = mMillis; + if (mDiff < 1000) + return; } mDiffSeconds = mDiff / 1000; - mDiffFraq = mDiff % 1000; - mPrevMillis += (mDiffSeconds * 1000) - mDiffFraq; - checkEvery(); - checkAt(); - mUptime += mDiffSeconds; - if(0 != mTimestamp) - mTimestamp += mDiffSeconds; + mPrevMillis += (mDiffSeconds * 1000); } + + mUptime += mDiffSeconds; + if(0 != mTimestamp) + mTimestamp += mDiffSeconds; + checkEvery(); + checkAt(); + } void once(scdCb c, uint32_t timeout) { mStack.add(c, timeout, 0); } @@ -105,6 +113,7 @@ namespace ah { if(expired) { (p->d.c)(); + yield(); if(0 == p->d.reload) p = mStack.rem(p); else { @@ -122,6 +131,7 @@ namespace ah { while(NULL != p) { if((p->d.timestamp) <= mTimestamp) { (p->d.c)(); + yield(); p = mStackAt.rem(p); } else @@ -134,7 +144,6 @@ namespace ah { uint32_t mMillis, mPrevMillis, mDiff; uint32_t mUptime; uint8_t mDiffSeconds; - uint16_t mDiffFraq; }; } diff --git a/src/wifi/ahoywifi.cpp b/src/wifi/ahoywifi.cpp index c8a10412..1ccede08 100644 --- a/src/wifi/ahoywifi.cpp +++ b/src/wifi/ahoywifi.cpp @@ -115,9 +115,11 @@ void ahoywifi::setupStation(void) { //----------------------------------------------------------------------------- -void ahoywifi::getNtpTime(void) { +bool ahoywifi::getNtpTime(void) { //DPRINTLN(DBG_VERBOSE, F("wifi::getNtpTime")); - time_t date = 0; + if(!mConnected) + return false; + IPAddress timeServer; uint8_t buf[NTP_PACKET_SIZE]; uint8_t retry = 0; @@ -138,16 +140,16 @@ void ahoywifi::getNtpTime(void) { secsSince1900 |= (buf[42] << 8); secsSince1900 |= (buf[43] ); - date = secsSince1900 - 2208988800UL; // UTC time - break; + *mUtcTimestamp = secsSince1900 - 2208988800UL; // UTC time + DPRINTLN(DBG_INFO, F("[NTP]: ") + ah::getDateTimeStr(*mUtcTimestamp) + F(" UTC")); + return true; } else delay(10); } } - *mUtcTimestamp = date; - - DPRINTLN(DBG_INFO, "[NTP]: " + ah::getDateTimeStr(*mUtcTimestamp) + " UTC"); + DPRINTLN(DBG_INFO, F("[NTP]: getNtpTime failed")); + return false; }