rtctime.cpp: bugfix time sync at device startup

This commit is contained in:
Klaus K Wilting 2019-01-26 13:44:16 +01:00
parent c05edbc2f3
commit edf5310d81

View File

@ -97,14 +97,16 @@ time_t get_rtctime(void) {
} // get_rtctime() } // get_rtctime()
void sync_rtctime(void) { void sync_rtctime(void) {
if (timeStatus() != timeSet) { if (timeStatus() != timeSet) { // do we need time sync?
ESP_LOGE(TAG, "Unable to sync with the RTC"); time_t t = get_rtctime();
} else { if (t) { // do we have valid time by RTC?
time_t t = now();
setTime(t); setTime(t);
ESP_LOGI(TAG, "RTC has set system time to %02d/%02d/%d %02d:%02d:%02d", ESP_LOGI(TAG, "RTC has set system time to %02d/%02d/%d %02d:%02d:%02d",
month(t), day(t), year(t), hour(t), minute(t), second(t)); month(t), day(t), year(t), hour(t), minute(t), second(t));
} else
ESP_LOGE(TAG, "RTC has no confident time, not synced");
} }
#ifdef TIME_SYNC_INTERVAL_RTC #ifdef TIME_SYNC_INTERVAL_RTC
setSyncProvider(&get_rtctime); setSyncProvider(&get_rtctime);
setSyncInterval(TIME_SYNC_INTERVAL_RTC); setSyncInterval(TIME_SYNC_INTERVAL_RTC);