Skip to content

Use NTP as primary time source and connection handler as fallback #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/utility/time/TimeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,24 +279,24 @@ bool TimeServiceClass::connected()
unsigned long TimeServiceClass::getRemoteTime()
{
if(connected()) {
/* At first try to see if a valid time can be obtained
* using the network time available via the connection
* handler.
*/
unsigned long const connection_time = _con_hdl->getTime();
if(isTimeValid(connection_time)) {
return connection_time;
}

#ifndef __AVR__
/* If no valid network time is available try to obtain the
* time via NTP next.
/* At first try to obtain a valid time via NTP.
* This is the most reliable time source and it will
* ensure a correct behaviour of the library.
*/
unsigned long const ntp_time = NTPUtils::getTime(_con_hdl->getUDP());
if(isTimeValid(ntp_time)) {
return ntp_time;
}
#endif

/* As fallback if NTP request fails try to obtain the
* network time using the connection handler.
*/
unsigned long const connection_time = _con_hdl->getTime();
if(isTimeValid(connection_time)) {
return connection_time;
}
}

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