NetworkTimeProtocol (Synchronize Clock with Internet Time)

The NetworkTimeProtocol function is used to synchronize the datalogger's clock with an Internet time server.

Syntax

variable = NetworkTimeProtocol ( NTPServer, NTPOffset, NTPMaxMSec, Timeout [optional] )

Remarks

Network Time Protocol, or NTP, is an internet protocol that can be used for clock synchronization between devices over a network. The protocol uses Coordinated Universal Time (UTC) as the basis for the synchronization. The datalogger can use network time protocol (NTP) to set its clock, and it can also act as an NTP server.

The NetworkTimeProtocol function returns the measured clock error in milliseconds, prior to the clock adjustment. If the command fails, NAN is returned. The timeout for this instruction is 70 seconds; the command will fail if no response is received within the timeout period. Passing a negative value for Timeout enables “servo mode,” where the datalogger gradually nudges the real-time clock rate based on NTP time differences (rather than relying primarily on hard clock sets).

If the IP address of the NTPServer parameter is a null string, "", it will act an an NTP server rather than a client.

 

Parameters

NTPServer (Internet Time Server)

The IP address or qualified domain name for the Internet time server. The entry must be enclosed in quotes. If a domain name is used, the IP address for a DNS must be set in the datalogger.

Enter a null string, "", if the NetworkTimeProtocol function is being used only to establish a time offset when the datalogger acts as an NTP server.

Type: Constant, enclosed in quotes

NTPOffset (Universal Time Offset)

The NTPOffset parameter is used to specify an offset, in seconds, from Universal Time that should be used when the clock is set; for example, Mountain Standard Time in the U.S. is -7GMT, so the offset would be -25,200 (-7*3600). If the datalogger setting "UTC Offset" is set to a value other than -1 (disabled), this offset parameter will be ignored and the UTC Offset value in the datalogger will be used.

Type: Constant or Variable

NTPMaxMSec (Max Time from Internet Time)

The maximum time, in milliseconds, that the datalogger's clock can differ from the Internet time server without triggering a clock set.

When the NTP server returns a time difference greater than NTPMaxMsec, the datalogger sends additional requests to the NTP server and compares the resulting time differences with the initial response. This verifies that the server is consistently reporting the same time difference before the datalogger performs a full clock set.

If any additional response reports a time difference below NTPMaxMsec, the datalogger stops sending requests and does not perform a full clock set. In this case, the initial request reported an unacceptable time difference, but a subsequent request reported an acceptable difference, so the datalogger cannot confirm that the NTP server is consistently reporting the correct time.

Otherwise, the datalogger continues sending NTP requests for a set number of attempts, checking that consecutive responses report consistent time differences. If this sanity check fails, the datalogger gives up and does not perform a full clock set because it cannot confirm that the NTP server is in a good state and consistently reporting an accurate time difference.

NTP servers vary in quality and consistency. Choose an NTP server that provides reliable and consistent responses.

Type: Constant or Variable

TimeOut (Wait Time)

An optional parameter that specifies how long the instruction will wait before moving on to the next instruction.

  • Timeout = 0/Omitted: Default timeout is applied (75 seconds)

  • Timeout > 0: Specifies the maximum time (in seconds) the instruction will run before moving on.

  • Timeout < 0: The absolute value acts as a timeout and enables time servo mode. Servo mode allows the data logger to gradually adjust its clock to sync with the NTP server rather than making abrupt time changes. While this mode improves time tracking, accuracy is influenced by factors such as network latency and server variability.

Servo Mode Dependencies:

  1. Execute the instruction every 2 to 5 minutes

  2. Set the NTPMaxMSec parameter to 1 second or less to maintain reliable synchronization.

See Servo Mode for details.