fix timesync from RTC

This commit is contained in:
cyberman54 2022-03-05 19:08:35 +01:00
parent f74f103e80
commit fbb1878807
2 changed files with 10 additions and 2 deletions

View File

@ -65,7 +65,13 @@ time_t get_rtctime(uint16_t *msec) {
// if we have a RTC pulse, we calculate msec // if we have a RTC pulse, we calculate msec
#ifdef RTC_INT #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 #endif
return t; return t;

View File

@ -203,8 +203,10 @@ void timepulse_init(void) {
#endif #endif
// get time if we don't have one // 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 setTimeSyncIRQ(); // init systime by RTC or GPS or LORA
}
// start cyclic time sync // start cyclic time sync
timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ); timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ);