From fbb187880728bb39024f80e1bf0776821935511a Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sat, 5 Mar 2022 19:08:35 +0100 Subject: [PATCH] fix timesync from RTC --- src/rtctime.cpp | 8 +++++++- src/timekeeper.cpp | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/rtctime.cpp b/src/rtctime.cpp index 7bbb4844..0de8e176 100644 --- a/src/rtctime.cpp +++ b/src/rtctime.cpp @@ -65,7 +65,13 @@ time_t get_rtctime(uint16_t *msec) { // if we have a RTC pulse, we calculate msec #ifdef RTC_INT - *msec = lastRTCpulse % 1000; + uint16_t ppsDiff = millis() - lastRTCpulse; + if (ppsDiff < 1000) + *msec = ppsDiff; + else { + ESP_LOGD(TAG, "no pulse from RTC"); + return 0; + } #endif return t; diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index 97c63064..ee0a4ed1 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -203,8 +203,10 @@ void timepulse_init(void) { #endif // get time if we don't have one - if (timeSource != _set) + if (timeSource != _set) { + delay(1000); // wait for first PPS time stamp to arrive setTimeSyncIRQ(); // init systime by RTC or GPS or LORA + } // start cyclic time sync timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ);