diff --git a/src/main.cpp b/src/main.cpp index 1cb3e3fa..82587c23 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -118,12 +118,6 @@ void setup() { // load device configuration from NVRAM and set runmode do_after_reset(); - // set time zone to user value from paxcounter.conf -#ifdef TIME_SYNC_TIMEZONE - myTZ.setPosix(TIME_SYNC_TIMEZONE); - ESP_LOGD(TAG, "Timezone set to %s", myTZ.getPosix().c_str()); -#endif - // hash 6 byte device MAC to 4 byte clientID uint8_t mac[6]; esp_read_mac(mac, ESP_MAC_WIFI_STA); diff --git a/src/reset.cpp b/src/reset.cpp index f63a8454..7827b80a 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -47,6 +47,12 @@ void do_after_reset(void) { // read (and initialize on first run) runtime settings from NVRAM loadConfig(); + // set time zone to user value from paxcounter.conf +#ifdef TIME_SYNC_TIMEZONE + myTZ.setPosix(TIME_SYNC_TIMEZONE); + ESP_LOGD(TAG, "Timezone set to %s", myTZ.getPosix().c_str()); +#endif + switch (rtc_get_reset_reason(0)) { case POWERON_RESET: // 0x01 Vbat power on reset @@ -69,8 +75,8 @@ void do_after_reset(void) { RTC_millis += sleep_time_ms; // increment system monotonic time ESP_LOGI(TAG, "Time spent in deep sleep: %d ms", sleep_time_ms); - // set time - setMyTime(RTC_time + sleep_time_ms / 1000, sleep_time_ms % 1000, _set); + // restore time + setMyTime(RTC_time, sleep_time_ms, _set); // set wakeup state, not if we have pending OTA update if (RTC_runmode == RUNMODE_SLEEP) diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index a30f94c1..b1512bb8 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -180,8 +180,10 @@ void timepulse_start(void) { timerAlarmEnable(ppsIRQ); #endif + // get time if we don't have one + if (timeSource != _set) + setTimeSyncIRQ(); // init systime by RTC or GPS or LORA // start cyclic time sync - setTimeSyncIRQ(); // init systime by RTC or GPS or LORA timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ); }