I have a Python script that runs at startup and needs the correct time in order to function properly. I have setup the raspi-config to wait for a network connection before continuing so the code won't run until there is an internet connection (I think!). However, I have noticed that after a reboot it may take several seconds after the Python code gets started before the system gets around to running the NTP process that updates the system clock.

Is there some way to test to see when the internal clock gets updated by the NTP process? Is there some resource that keeps track of the last NTP time sync event? And how often does the RPi resync its clock using the NTP (daily, hourly weekly)?

  • Have you considered adding a RTC to the Pi? How precise a time do you need? What is the use case? Aug 7 '17 at 19:25
  • I wanted to avoid adding any additional hardware. The application is a kid's alarm clock (with the added bonus of Mom and Dad being able to set and turn off the alarm via iPhones). Aug 9 '17 at 0:05
  1. ntpstat Show network time synchronisation status

pi@Pi3-01:~ $ ntpstat synchronised to NTP server ( at stratum 3 time correct to within 84 ms polling server every 1024 s

And with pythons ntplib you can get the NTP status.

  1. The poll time (in seconds) is shown in the column poll when you type the command ntpq -p

pi@Pi3-01:~ $ ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *ntp8.flashdance 2 u 162 1024 373 28.540 0.994 4.545 + 2 u 106 1024 375 87.132 -1.339 5.561 +tethys.hot-chil 2 u 759 1024 377 58.820 -1.213 3.116 +sundown.speedwe 2 u 59 1024 377 59.788 0.605 3.521

  1. How often does it sync the time?

Initially every 64th second, if the time is stable, the poll time will increase, and vice versa if it differ to much.

From: http://doc.ntp.org/4.1.0/ntpd.htm

How NTP Operates

The ntpd program operates by exchanging messages with one or more configured servers at designated poll intervals. When started, whether for the first or subsequent times, the program requires several exahanges from the majority of these servers so the signal processing and mitigation algorithms can accumulate and groom the data and set the clock. In order to protect the network from bursts, the initial poll interval for each server is delayed an interval randomized over 0-16s. At the default initial poll interval of 64s, several minutes can elapse before the clock is set. The initial delay to set the clock can be reduced using the iburst keyword with the server configuration command, as described on the Configuration Options page.

  • When I type in ntpstat I get this: ntpstat: command not found I am running Jessie. Aug 9 '17 at 0:08
  • Install it with: sudo apt-get install ntpstat
    – MatsK
    Aug 9 '17 at 0:16
  • I got it installed OK. Here is the output: synchronised to NTP server ( at stratum 3 time correct to within 124 ms polling server every 1024 s So how do I determine that this output is current and not leftover from a previous NTP time sync event that occurred before the reboot event? Aug 9 '17 at 20:27
  • The second command shows?
    – MatsK
    Aug 9 '17 at 21:47
  • The ntpq -p gets me this: ` remote refid st t when poll reach delay offset jitter ============================================================================== *ntp.your.org .CDMA. 1 u 795 1024 377 39.404 1.084 19.478 +clocka.ntpjs.or 2 u 376 1024 377 39.151 7.953 4.993 +li290-38.member 2 u 664 1024 177 61.149 4.258 14.380 + 2 u 407 1024 377 47.402 0.707 24.355` Aug 17 '17 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.