NTP Client
Out of date
This library was built with older versions of the mbed library.
For an NTP client that is compatible with mbed OS 5, please see the updated example: https://github.com/ARMmbed/ntp-client-example
Packages¶
Precompiled version:
Import libraryNTPClient_NetServices
NTP Client for the "old" NetServices libraries
Library¶
Architecture¶
The NTP client is a simple UDP client that will update the mbed's RTC.
Includes¶
#include "NTPClient.h"
Reference¶
Import program
Public Member Functions |
|
NTPClient () | |
Instantiates the NTP client.
|
|
NTPResult | setTime (const Host &host) |
Gets current time (blocking)
|
|
NTPResult | setTime (const Host &host, void(*pMethod)( NTPResult )) |
Gets current time (non-blocking)
|
|
template<class T > | |
NTPResult | setTime (const Host &host, T *pItem, void(T::*pMethod)( NTPResult )) |
Gets current time (non-blocking)
|
|
void | doSetTime (const Host &host) |
Gets current time (non-blocking)
|
|
void | setOnResult (void(*pMethod)( NTPResult )) |
Setups the result callback.
|
|
void | close () |
This flags the service as to be destructed if owned by the pool.
|
|
Protected Member Functions |
|
virtual void | poll () |
This method can be inherited so that it is called on each
Net::poll()
call.
|
Examples¶
This example updates the RTC.
#include "mbed.h" #include "EthernetNetIf.h" #include "NTPClient.h" EthernetNetIf eth; NTPClient ntp; int main() { printf("Start\n"); printf("Setting up...\n"); EthernetErr ethErr = eth.setup(); if(ethErr) { printf("Error %d in setup.\n", ethErr); return -1; } printf("Setup OK\r\n"); time_t ctTime; ctTime = time(NULL); printf("Current time is (UTC): %s\n", ctime(&ctTime)); Host server(IpAddr(), 123, "0.uk.pool.ntp.org"); ntp.setTime(server); ctTime = time(NULL); printf("\nTime is now (UTC): %s\n", ctime(&ctTime)); while(1) { } return 0; }
This program can be imported from here :