In a previous guide on ESP32, we faced NTP server and Network Time Protocol to get current time for button press event as example. What is Network Time Protocol (NTP)? The Network Time Protocol (NTP) is a standard for synchronizing clocks in computer systems using UDP protocol. NTP is specifically designed to provide reliable time information over variable packet delay networks. In common usage, NTP refers to both the protocol and the software reference implementation thereof. The Simple Network Time Protocol (SNTP) is a simplified version of the NTP. Official website and RFC :
NTP was developed by David L. Mills at the University of Delaware and published in 1985 as RFC 958. UDP port 123 is reserved for NTP. NTP is implemented in UNIX-like operating systems in the form of the background process (daemon) ntpd, which can both adjust the local system and, as a server, provide time for other systems. Windows systems can also obtain the exact time by means of NTP from the Internet without additional external software (Windows Time Service).
The UNIX ntpd synchronizes the local clock by means of external time signals, either directly from a local atomic clock (caesium clock, rubidium clock, etc.) or a local radio receiver (for example, DCF77 , GPS etc), or by NTP from one NTP server. So that the local time does not precisely coincide with the external signal at the cyclic synchronization times, the ntpd process corrects not only the phase but also the frequency of the local timer by means of software. To even more closely couple the internal timer to an external standard time receiver using a high-precision second signal, some UNIX variants (including Linux and FreeBSD) have implemented the above-mentioned software in the kernel. The timestamps in the NTP are 64 bits long. 32 bits encode the seconds since January 1, 1900 00:00:00.
NTP uses a hierarchical system of different strata. Stratum 0 is the time standard, for example an atomic clock or a radio clock (time signal receiver via GNSS or DCF77). The NTP servers directly linked to it are called stratum 1. Each additional dependent unit is given a higher number in the designation (stratum 2, stratum 3 …). The NTP software on Stratum 1, Stratum 2, Stratum 3, etc are also the client of the stratum above, as well as the server of the underlying stratum if one such exists.
Illustration by http://www.burningnode.com/2012/11/11/ntp-lab/
The local system time of a processor environment varies with several typical sources of error. This causes at least two typical errors (1) short-term fluctuations of the time increment along the current time (2) stable local deviations from common system time. Both time errors are compensated with different methods.
The local deviations due to the latency of the stochastically determined transmission paths are compensated by measuring the packet round trip time from the server (Berkeley algorithm) or from the client (Cristians algorithm).
The short-term pseudo-stochastic deviations of the local system clock can only be compensated by a better further system clock (frequency standard) and direct reception of satellite signals (GPS) or other time standards (DCF77).
NTP uses the Marzullo algorithm for internal error compensation of the processor environment and also an algorithm to handle Byzantine errors. NTP is usually run with a UTC – time scale.
NTPv4 can keep the local time of a system over the public Internet with an accuracy of 10 milliseconds, in local networks even accuracies of 200 microseconds and better under ideal conditions. With a sufficiently stable local frequency standard as a clock (thermostat-controlled quartz oscillator, rubidium oscillator, etc.) can be reduced using the kernel software (mentioned above), the error between the reference timer and local clock to the order of a few microseconds.