NTP: Network Time Protocol

https://en.m.wikipedia.org/wiki/Network_Time_Protocol

Client API

using NtpTimeResultDelegate = Delegate<void(NtpClient &client, time_t ntpTime)>
NTP_PORT
NTP_PACKET_SIZE
NTP_VERSION
NTP_MODE_CLIENT
NTP_MODE_SERVER
NTP_DEFAULT_SERVER
NTP_DEFAULT_AUTOQUERY_SECONDS
NTP_MIN_AUTOQUERY_SECONDS

Minimum autoquery interval.

NTP_CONNECTION_TIMEOUT_MS

Time to retry query when network connection unavailable.

NTP_RESPONSE_TIMEOUT_MS

Time to wait before retrying NTP query.

class NtpClient : protected UdpConnection
#include <NtpClient.h>

NTP client class.

Public Functions

inline NtpClient()

Instantiates NTP client object.

inline NtpClient(NtpTimeResultDelegate onTimeReceivedCb)

Instantiates NTP client object.

Parameters:

onTimeReceivedCb – Callback delegate to be called when NTP time result is received

NtpClient(const String &reqServer, unsigned reqIntervalSeconds, NtpTimeResultDelegate onTimeReceivedCb = nullptr)

Instantiates NTP client object.

Parameters:
  • reqServer – IP address or hostname of NTP server; nullptr to use default server

  • reqIntervalSeconds – Quantity of seconds between NTP requests

  • onTimeReceivedCb – Callback delegate to be called when NTP time result is received (Default: None)

void requestTime()

Request time from NTP server.

Note

Instigates request. Result is handled by NTP result handler function if defined

inline void setNtpServer(const String &server)

Set the NTP server.

Parameters:

server – IP address or hostname of NTP server

void setAutoQuery(bool autoQuery)

Enable / disable periodic query.

Parameters:

autoQuery – True to enable periodic query of NTP server

void setAutoQueryInterval(unsigned seconds)

Set query period.

Parameters:

seconds – Period in seconds between periodic queries

inline void setAutoUpdateSystemClock(bool autoUpdateClock)

Enable / disable update of system clock.

Parameters:

autoUpdateClock – True to update system clock with NTP result.