fix restore time after deepsleep
This commit is contained in:
parent
adb7f93944
commit
995cde6a67
@ -118,12 +118,6 @@ void setup() {
|
|||||||
// load device configuration from NVRAM and set runmode
|
// load device configuration from NVRAM and set runmode
|
||||||
do_after_reset();
|
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
|
// hash 6 byte device MAC to 4 byte clientID
|
||||||
uint8_t mac[6];
|
uint8_t mac[6];
|
||||||
esp_read_mac(mac, ESP_MAC_WIFI_STA);
|
esp_read_mac(mac, ESP_MAC_WIFI_STA);
|
||||||
|
@ -47,6 +47,12 @@ void do_after_reset(void) {
|
|||||||
// read (and initialize on first run) runtime settings from NVRAM
|
// read (and initialize on first run) runtime settings from NVRAM
|
||||||
loadConfig();
|
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)) {
|
switch (rtc_get_reset_reason(0)) {
|
||||||
|
|
||||||
case POWERON_RESET: // 0x01 Vbat power on reset
|
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
|
RTC_millis += sleep_time_ms; // increment system monotonic time
|
||||||
ESP_LOGI(TAG, "Time spent in deep sleep: %d ms", sleep_time_ms);
|
ESP_LOGI(TAG, "Time spent in deep sleep: %d ms", sleep_time_ms);
|
||||||
|
|
||||||
// set time
|
// restore time
|
||||||
setMyTime(RTC_time + sleep_time_ms / 1000, sleep_time_ms % 1000, _set);
|
setMyTime(RTC_time, sleep_time_ms, _set);
|
||||||
|
|
||||||
// set wakeup state, not if we have pending OTA update
|
// set wakeup state, not if we have pending OTA update
|
||||||
if (RTC_runmode == RUNMODE_SLEEP)
|
if (RTC_runmode == RUNMODE_SLEEP)
|
||||||
|
@ -180,8 +180,10 @@ void timepulse_start(void) {
|
|||||||
timerAlarmEnable(ppsIRQ);
|
timerAlarmEnable(ppsIRQ);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// start cyclic time sync
|
// get time if we don't have one
|
||||||
|
if (timeSource != _set)
|
||||||
setTimeSyncIRQ(); // init systime by RTC or GPS or LORA
|
setTimeSyncIRQ(); // init systime by RTC or GPS or LORA
|
||||||
|
// start cyclic time sync
|
||||||
timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ);
|
timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user