NtpClient Class Reference
NTP client class. More...
#include <NtpClient.h>
Inheritance diagram for NtpClient:
Collaboration diagram for NtpClient:
Public Member Functions | |
NtpClient () | |
Instantiates NTP client object. More... | |
NtpClient (NtpTimeResultDelegate onTimeReceivedCb) | |
Instantiates NTP client object. More... | |
NtpClient (const String &reqServer, unsigned reqIntervalSeconds, NtpTimeResultDelegate onTimeReceivedCb=nullptr) | |
Instantiates NTP client object. More... | |
void | requestTime () |
Request time from NTP server. More... | |
void | setNtpServer (const String &server) |
Set the NTP server. More... | |
void | setAutoQuery (bool autoQuery) |
Enable / disable periodic query. More... | |
void | setAutoQueryInterval (unsigned seconds) |
Set query period. More... | |
void | setAutoUpdateSystemClock (bool autoUpdateClock) |
Enable / disable update of system clock. More... | |
Protected Member Functions | |
void | onReceive (pbuf *buf, IpAddress remoteIP, uint16_t remotePort) override |
Handle UDP message reception. More... | |
void | internalRequestTime (IpAddress serverIp) |
Send time request to NTP server. More... | |
void | startTimer (uint32_t milliseconds) |
Start the timer running. More... | |
void | stopTimer () |
![]() | |
bool | initialize (udp_pcb *pcb=nullptr) |
UdpConnection () | |
UdpConnection (UdpConnectionDataDelegate dataHandler) | |
virtual | ~UdpConnection () |
virtual bool | listen (int port) |
virtual bool | connect (IpAddress ip, uint16_t port) |
virtual void | close () |
virtual bool | send (const char *data, int length) |
bool | sendString (const char *data) |
bool | sendString (const String &data) |
virtual bool | sendTo (IpAddress remoteIP, uint16_t remotePort, const char *data, int length) |
bool | sendStringTo (IpAddress remoteIP, uint16_t remotePort, const char *data) |
bool | sendStringTo (IpAddress remoteIP, uint16_t remotePort, const String &data) |
bool | setMulticast (IpAddress ip) |
Sets the UDP multicast IP. More... | |
bool | setMulticastTtl (size_t ttl) |
Sets the UDP multicast Time-To-Live(TTL). More... | |
![]() | |
bool | joinMulticastGroup (IpAddress localIp, IpAddress multicastIp) |
Uses IGMP to add a local network interface to multicast group. More... | |
bool | joinMulticastGroup (IpAddress multicastIp) |
Uses IGMP to add all local network interfaces to multicast group. More... | |
bool | leaveMulticastGroup (IpAddress localIp, IpAddress multicastIp) |
Uses IGMP to remove a local network interface from multicast group. More... | |
bool | leaveMulticastGroup (IpAddress multicastIp) |
Uses IGMP to remove all local network interfaces from multicast group. More... | |
Protected Attributes | |
String | server |
IP address or Hostname of NTP server. More... | |
NtpTimeResultDelegate | delegateCompleted = nullptr |
NTP result handler delegate. More... | |
bool | autoUpdateSystemClock = false |
True to update system clock with NTP time. More... | |
bool | autoQueryEnabled = false |
unsigned | autoQuerySeconds = NTP_DEFAULT_AUTOQUERY_SECONDS |
Timer | timer |
Deals with timeouts, retries and autoquery updates. More... | |
![]() | |
udp_pcb * | udp = nullptr |
UdpConnectionDataDelegate | onDataCallback = nullptr |
Additional Inherited Members | |
![]() | |
static void | staticOnReceive (void *arg, struct udp_pcb *pcb, struct pbuf *p, LWIP_IP_ADDR_T *addr, u16_t port) |
Detailed Description
NTP client class.
Constructor & Destructor Documentation
◆ NtpClient() [1/3]
|
inline |
Instantiates NTP client object.
◆ NtpClient() [2/3]
|
inline |
Instantiates NTP client object.
- Parameters
-
onTimeReceivedCb Callback delegate to be called when NTP time result is received
◆ NtpClient() [3/3]
NtpClient::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)
Member Function Documentation
◆ internalRequestTime()
|
protected |
Send time request to NTP server.
- Parameters
-
serverIp IP address of NTP server
◆ onReceive()
|
overrideprotectedvirtual |
Handle UDP message reception.
- Parameters
-
buf Pointer to data buffer containing UDP payload remoteIP IP address of remote host remotePort Port number of remote host
Reimplemented from UdpConnection.
◆ requestTime()
void NtpClient::requestTime | ( | ) |
Request time from NTP server.
- Note
- Instigates request. Result is handled by NTP result handler function if defined
◆ setAutoQuery()
void NtpClient::setAutoQuery | ( | bool | autoQuery | ) |
Enable / disable periodic query.
- Parameters
-
autoQuery True to enable periodic query of NTP server
◆ setAutoQueryInterval()
void NtpClient::setAutoQueryInterval | ( | unsigned | seconds | ) |
Set query period.
- Parameters
-
seconds Period in seconds between periodic queries
◆ setAutoUpdateSystemClock()
|
inline |
Enable / disable update of system clock.
- Parameters
-
autoUpdateClock True to update system clock with NTP result.
◆ setNtpServer()
|
inline |
Set the NTP server.
- Parameters
-
server IP address or hostname of NTP server
◆ startTimer()
|
inlineprotected |
Start the timer running.
- Parameters
-
milliseconds Time to run in milliseconds
◆ stopTimer()
|
inlineprotected |
Member Data Documentation
◆ autoQueryEnabled
|
protected |
◆ autoQuerySeconds
|
protected |
◆ autoUpdateSystemClock
|
protected |
True to update system clock with NTP time.
◆ delegateCompleted
|
protected |
NTP result handler delegate.
◆ server
|
protected |
IP address or Hostname of NTP server.
◆ timer
|
protected |
Deals with timeouts, retries and autoquery updates.
The documentation for this class was generated from the following file: