@@ -141,6 +141,7 @@ unsigned long TimeServiceClass::getTime()
141
141
unsigned long const current_tick = millis ();
142
142
bool const is_ntp_sync_timeout = (current_tick - _last_sync_tick) > _sync_interval_ms;
143
143
if (!_is_rtc_configured || is_ntp_sync_timeout) {
144
+ /* Try to sync time from NTP or connection handler */
144
145
sync ();
145
146
}
146
147
@@ -173,13 +174,13 @@ bool TimeServiceClass::sync()
173
174
#if defined(HAS_NOTECARD) || defined(HAS_TCP)
174
175
utc = getRemoteTime ();
175
176
#elif defined(HAS_LORA)
176
- /* Just keep incrementing stored RTC value*/
177
+ /* Just keep incrementing stored RTC value starting from EPOCH_AT_COMPILE_TIME */
177
178
utc = getRTC ();
178
179
#endif
179
180
}
180
181
181
182
if (isTimeValid (utc)) {
182
- DEBUG_DEBUG (" TimeServiceClass::%s Drift: %d RTC value: %u" , __FUNCTION__, getRTC () - utc, utc);
183
+ DEBUG_DEBUG (" TimeServiceClass::%s done. Drift: %d RTC value: %u" , __FUNCTION__, getRTC () - utc, utc);
183
184
setRTC (utc);
184
185
_last_sync_tick = millis ();
185
186
_is_rtc_configured = true ;
@@ -307,6 +308,7 @@ unsigned long TimeServiceClass::getRemoteTime()
307
308
return ntp_time;
308
309
}
309
310
}
311
+ DEBUG_WARNING (" TimeServiceClass::%s cannot get time from NTP, fallback on connection handler" , __FUNCTION__);
310
312
#endif /* HAS_TCP */
311
313
312
314
/* As fallback if NTP request fails try to obtain the
@@ -316,6 +318,7 @@ unsigned long TimeServiceClass::getRemoteTime()
316
318
if (isTimeValid (connection_time)) {
317
319
return connection_time;
318
320
}
321
+ DEBUG_WARNING (" TimeServiceClass::%s cannot get time from connection handler" , __FUNCTION__);
319
322
}
320
323
321
324
/* Return known invalid value because we are not connected */
0 commit comments