Skip to content

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";

Creates a new NTP client object instance.

NTP(options)

options

socket - A UDP class constructor options object.

servers - An array of one or more strings indicating the NTP hosts to use.

Closes the NTP client and releases any resources.

close()

Initiates a time synchronization operation.

getTime(callback)

callback

callback(error, time)

error - An Error object if the operation failed, or null if successful.

time - The synchronized time as an ECMAScript number value.

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)}`);
});

NTP Client