@@ -140,6 +140,7 @@ unsigned long TimeServiceClass::getTime()
140
140
unsigned long const current_tick = millis ();
141
141
bool const is_ntp_sync_timeout = (current_tick - _last_sync_tick) > _sync_interval_ms;
142
142
if (!_is_rtc_configured || is_ntp_sync_timeout) {
143
+ /* Try to sync time from NTP or connection handler */
143
144
sync ();
144
145
}
145
146
@@ -173,13 +174,13 @@ bool TimeServiceClass::sync()
173
174
utc = getRemoteTime ();
174
175
#endif
175
176
#ifdef 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 ;
@@ -306,6 +307,7 @@ unsigned long TimeServiceClass::getRemoteTime()
306
307
return ntp_time;
307
308
}
308
309
}
310
+ DEBUG_WARNING (" TimeServiceClass::%s cannot get time from NTP, fallback on connection handler" , __FUNCTION__);
309
311
310
312
/* As fallback if NTP request fails try to obtain the
311
313
* network time using the connection handler.
@@ -314,6 +316,7 @@ unsigned long TimeServiceClass::getRemoteTime()
314
316
if (isTimeValid (connection_time)) {
315
317
return connection_time;
316
318
}
319
+ DEBUG_WARNING (" TimeServiceClass::%s cannot get time from connection handler" , __FUNCTION__);
317
320
}
318
321
319
322
/* Return known invalid value because we are not connected */
0 commit comments