NTP Client Class
The NTP client retrieves the current time from a network time source using the Network Time Protocol (NTP).
import NTP from "embedded:network/ntp/client";Constructor
Section titled “Constructor”NTP(options)
Section titled “NTP(options)”Creates a new NTP client object instance.
NTP(options)Parameters
Section titled “Parameters”options
socket- AUDPclass constructor options object.
servers- An array of one or more strings indicating the NTP hosts to use.
Instance Methods
Section titled “Instance Methods”close()
Section titled “close()”Closes the NTP client and releases any resources.
close()getTime(callback)
Section titled “getTime(callback)”Initiates a time synchronization operation.
getTime(callback)Parameters
Section titled “Parameters”callback
callback(error, time)
error- AnErrorobject if the operation failed, ornullif successful.
time- The synchronized time as an ECMAScript number value.
Examples
Section titled “Examples”import NTP from "embedded:network/ntp/client";
const ntp = new NTP({ servers: ["pool.ntp.org"]});
ntp.getTime((error, time) => { if (error) return console.error("NTP failed"); console.log(`Current time: ${new Date(time)}`);});