NTP client class. More...

#include <NtpClient.h>

Inheritance diagram for NtpClient:
[legend]
Collaboration diagram for NtpClient:
[legend]

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 ()
 
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 initialize (udp_pcb *pcb=nullptr)
 

Static Protected Member Functions

static void staticOnReceive (void *arg, struct udp_pcb *pcb, struct pbuf *p, LWIP_IP_ADDR_T *addr, u16_t port)
 

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
 

Detailed Description

NTP client class.

Constructor & Destructor Documentation

◆ NtpClient() [1/3]

NtpClient::NtpClient ( )
inline

Instantiates NTP client object.

◆ NtpClient() [2/3]

NtpClient::NtpClient ( NtpTimeResultDelegate  onTimeReceivedCb)
inline

Instantiates NTP client object.

Parameters
onTimeReceivedCbCallback 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
reqServerIP address or hostname of NTP server; nullptr to use default server
reqIntervalSecondsQuantity of seconds between NTP requests
onTimeReceivedCbCallback delegate to be called when NTP time result is received (Default: None)

Member Function Documentation

◆ close()

virtual void UdpConnection::close ( )
virtualinherited

◆ connect()

virtual bool UdpConnection::connect ( IpAddress  ip,
uint16_t  port 
)
virtualinherited

◆ initialize()

bool UdpConnection::initialize ( udp_pcb *  pcb = nullptr)
protectedinherited

◆ internalRequestTime()

void NtpClient::internalRequestTime ( IpAddress  serverIp)
protected

Send time request to NTP server.

Parameters
serverIpIP address of NTP server

◆ listen()

virtual bool UdpConnection::listen ( int  port)
virtualinherited

◆ onReceive()

void NtpClient::onReceive ( pbuf *  buf,
IpAddress  remoteIP,
uint16_t  remotePort 
)
overrideprotectedvirtual

Handle UDP message reception.

Parameters
bufPointer to data buffer containing UDP payload
remoteIPIP address of remote host
remotePortPort 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

◆ send()

virtual bool UdpConnection::send ( const char *  data,
int  length 
)
virtualinherited

◆ sendString() [1/2]

bool UdpConnection::sendString ( const char *  data)
inlineinherited

◆ sendString() [2/2]

bool UdpConnection::sendString ( const String data)
inlineinherited

◆ sendStringTo() [1/2]

bool UdpConnection::sendStringTo ( IpAddress  remoteIP,
uint16_t  remotePort,
const char *  data 
)
inlineinherited

◆ sendStringTo() [2/2]

bool UdpConnection::sendStringTo ( IpAddress  remoteIP,
uint16_t  remotePort,
const String data 
)
inlineinherited

◆ sendTo()

virtual bool UdpConnection::sendTo ( IpAddress  remoteIP,
uint16_t  remotePort,
const char *  data,
int  length 
)
virtualinherited

◆ setAutoQuery()

void NtpClient::setAutoQuery ( bool  autoQuery)

Enable / disable periodic query.

Parameters
autoQueryTrue to enable periodic query of NTP server

◆ setAutoQueryInterval()

void NtpClient::setAutoQueryInterval ( unsigned  seconds)

Set query period.

Parameters
secondsPeriod in seconds between periodic queries

◆ setAutoUpdateSystemClock()

void NtpClient::setAutoUpdateSystemClock ( bool  autoUpdateClock)
inline

Enable / disable update of system clock.

Parameters
autoUpdateClockTrue to update system clock with NTP result.

◆ setNtpServer()

void NtpClient::setNtpServer ( const String server)
inline

Set the NTP server.

Parameters
serverIP address or hostname of NTP server

◆ startTimer()

void NtpClient::startTimer ( uint32_t  milliseconds)
inlineprotected

Start the timer running.

Parameters
millisecondsTime to run in milliseconds

◆ staticOnReceive()

static void UdpConnection::staticOnReceive ( void *  arg,
struct udp_pcb *  pcb,
struct pbuf *  p,
LWIP_IP_ADDR_T addr,
u16_t  port 
)
staticprotectedinherited

◆ stopTimer()

void NtpClient::stopTimer ( )
inlineprotected

Member Data Documentation

◆ autoQueryEnabled

bool NtpClient::autoQueryEnabled = false
protected

◆ autoQuerySeconds

unsigned NtpClient::autoQuerySeconds = NTP_DEFAULT_AUTOQUERY_SECONDS
protected

◆ autoUpdateSystemClock

bool NtpClient::autoUpdateSystemClock = false
protected

True to update system clock with NTP time.

◆ delegateCompleted

NtpTimeResultDelegate NtpClient::delegateCompleted = nullptr
protected

NTP result handler delegate.

◆ onDataCallback

UdpConnectionDataDelegate UdpConnection::onDataCallback = nullptr
protectedinherited

◆ server

String NtpClient::server
protected

IP address or Hostname of NTP server.

◆ timer

Timer NtpClient::timer
protected

Deals with timeouts, retries and autoquery updates.

◆ udp

udp_pcb* UdpConnection::udp = nullptr
protectedinherited

The documentation for this class was generated from the following file: