Skip to content

Commit 2b00404

Browse files
authored
Merge pull request #324 from pennam/get_remote_time
Use NTP as primary time source and connection handler as fallback
2 parents 42e5dcd + 91e9d26 commit 2b00404

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/utility/time/TimeService.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,24 +279,24 @@ bool TimeServiceClass::connected()
279279
unsigned long TimeServiceClass::getRemoteTime()
280280
{
281281
if(connected()) {
282-
/* At first try to see if a valid time can be obtained
283-
* using the network time available via the connection
284-
* handler.
285-
*/
286-
unsigned long const connection_time = _con_hdl->getTime();
287-
if(isTimeValid(connection_time)) {
288-
return connection_time;
289-
}
290-
291282
#ifndef __AVR__
292-
/* If no valid network time is available try to obtain the
293-
* time via NTP next.
283+
/* At first try to obtain a valid time via NTP.
284+
* This is the most reliable time source and it will
285+
* ensure a correct behaviour of the library.
294286
*/
295287
unsigned long const ntp_time = NTPUtils::getTime(_con_hdl->getUDP());
296288
if(isTimeValid(ntp_time)) {
297289
return ntp_time;
298290
}
299291
#endif
292+
293+
/* As fallback if NTP request fails try to obtain the
294+
* network time using the connection handler.
295+
*/
296+
unsigned long const connection_time = _con_hdl->getTime();
297+
if(isTimeValid(connection_time)) {
298+
return connection_time;
299+
}
300300
}
301301

302302
/* Return the epoch timestamp at compile time as a last

0 commit comments

Comments
 (0)