mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-05 04:01:41 +02:00
improved scheduler #483
refactored NTP generate bin.gz only for ESP8285 fix calcSunrise calculation
This commit is contained in:
parent
a9e4429f9f
commit
183b9b35f6
6 changed files with 43 additions and 38 deletions
14
src/app.cpp
14
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue