aoakley
Posts: 66
Joined: Fri May 11, 2012 10:27 pm
Contact: Website

Raspbian NTP clock synchronisation- how often and where?

Wed Dec 14, 2016 5:10 pm

Sorry if this is answered elsewhere, my search-fu failed.

I want to know, please, how often Raspbian attempts to sync its clock to the default remote NTP server, and I want to know where that setting is and how to change that period/frequency in case of intermittent WiFi during boot. For example, no good internet connection for the first hour of boot, but then a couple of hours later we get an hour or so of vaguely usable connectivity.

Note that I do NOT want to know how to force the NTP client to update manually from the commandline. I already know that and could easily write a script & cron job. Also I do NOT want a hardware battery clock add-on.

What I want to know is, is there already some kind of cron job or similar that syncs NTP, and if so where is it?

Reason: I have a headless Pi on the edge of WiFi signal for which correct time is critical. Reception fades in and out. The Pi in question is using a Pimoroni Unicorn Hat to simulate a consistent 6am sunrise as a visual alarm clock (cron job starts at 6am with a few dim red dots, works its way to full Unicorn white dazzling brightness by 6:30am, stays bright for an hour then turns the LEDs off).

Things I already think I know:

* Early to middle-way in boot, the program /sbin/fake-hwclock sets the clock to whatever was in /etc/fake-hwclock.data

* Towards the end of boot, the ntp client attempts to sync the clock to a remote NTP server. Obviously this only works if it has internet access.

* At some point in operation, perhaps during shutdown, the perceived time is written to /etc/fake-hwclock.data . So when you reboot you get a vaguely recent default clock.

* At some point in operation, probably periodically (when?) using cron (triggered from where?) or perhaps as a network up script (which? where?), the ntp client seems to update the clock.

Any hints much appreciated, thank-you.
Andrew Oakley - Cotswold Raspberry Jam, Gloucestershire - http://www.cotswoldjam.org

User avatar
scruss
Posts: 2419
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Raspbian NTP clock synchronisation- how often and where?

Wed Dec 14, 2016 5:57 pm

Look at the minpoll and maxpoll settings in ntp.conf. "man ntp.conf" says:

Code: Select all

       minpoll minpoll, maxpoll maxpoll
              These options specify the minimum and maximum poll intervals for
              NTP messages, in seconds as a power of two.   The  maximum  poll
              interval  defaults  to 10 (1,024 s), but can be increased by the
              maxpoll option to an upper limit of 17 (36.4  h).   The  minimum
              poll  interval defaults to 6 (64 s), but can be decreased by the
              minpoll option to a lower limit of 4 (16 s).  These  option  are
              valid only with the server and peer commands.
So ntp itself manages the polling, and I suspect that it retries after 64 seconds, then after 128, 256, …. It would seem that fiddling with these values is discouraged.

I know you said you don't want an RTC, but if you need the time to be reliable-ish with uncertain network and reboots, it's a cheap way of doing it. If you have skyview in your clock location, a GPS might provide better sync at higher cost and complexity.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
DougieLawson
Posts: 35798
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Raspbian NTP clock synchronisation- how often and where?

Wed Dec 14, 2016 6:25 pm

If you're running ntpd it's continuous until the basic sync is done then on every 1024 ticks (when column) it polls a remote server.

Code: Select all

[email protected] ~ # ntpq -p -n
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
-95.215.175.2    193.27.209.211   3 u 1076 1024  306   15.854   -2.227   1.773
*46.101.52.119   81.174.136.35    2 u 1803 1024  256    9.683   -1.386   8.052
+2001:470:9779:: 79.143.250.152   2 u  37m 1024  374   17.158   -0.888   1.280
-109.74.206.120  194.35.252.7     2 u  42m 1024  174    9.785   -3.403   2.104
+2001:67c:1560:8 145.238.203.14   2 u  480 1024  377    9.789   -1.055   0.263
[email protected] ~ #
On my network Apollo gets the time from the Internet and every other machine syncs to Apollo.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

aoakley
Posts: 66
Joined: Fri May 11, 2012 10:27 pm
Contact: Website

Re: Raspbian NTP clock synchronisation- how often and where?

Thu Jan 05, 2017 4:58 pm

Thanks chaps.

Might have a look for a cheapo USB RTC. Problem is that the GPIO header is taken up with a Unicorn HAT so can't use a GPIO solution.
Andrew Oakley - Cotswold Raspberry Jam, Gloucestershire - http://www.cotswoldjam.org

mattmiller
Posts: 2099
Joined: Thu Feb 05, 2015 11:25 pm

Re: Raspbian NTP clock synchronisation- how often and where?

Thu Jan 05, 2017 5:14 pm

Just wondering - how much does the time on your Pi drift over a 24 hr period

User avatar
DougieLawson
Posts: 35798
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Raspbian NTP clock synchronisation- how often and where?

Thu Jan 05, 2017 5:40 pm

aoakley wrote:Thanks chaps.

Might have a look for a cheapo USB RTC. Problem is that the GPIO header is taken up with a Unicorn HAT so can't use a GPIO solution.
Then you're probably up a gum tree unless you can solder something on the underside. Most RTCs are I²C and need pin#1 or pin#2 for DS1307 (Vcc), pin#3 (SDA), pin#5 (SCL) and pin#6 (GND).

The other option is the Black HAT Hack3r which moves your Unicorn HAT onto a separate carrier board and free up all the pins that aren't used for it.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

paulie
Posts: 262
Joined: Thu Jan 19, 2012 6:51 pm

Re: Raspbian NTP clock synchronisation- how often and where?

Thu Jan 05, 2017 7:22 pm

It's possible to use an Adafruit Ultimate GPS, and feed the 1pps output into a GPIO pin.
Would this fulfill the OP's requirements?
It has been my custom to use Xeyes

User avatar
DougieLawson
Posts: 35798
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Raspbian NTP clock synchronisation- how often and where?

Thu Jan 05, 2017 8:13 pm

paulie wrote:It's possible to use an Adafruit Ultimate GPS, and feed the 1pps output into a GPIO pin.
Would this fulfill the OP's requirements?
Same problem, the Unicorn HAT covers all of the pins.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Raspbian”