Not quite 5 minute guide to making an NTP Server

THIS ARTICLE HAS BEEN DEPRECIATED AND INSTRUCTIONS CONTAINED BELOW NO LONGER WORK WITH LATEST RASPBIAN. HOWEVER GOOD NEWS – ITS MUCH EASIER NOW SEE HERE:

https://ava.upuaut.net/?p=951

This is an article on making a network attached Stratum 1 NTP Server using a Raspberry Pi+ Model 2 or 3 and the Uputronics Raspberry Pi+ GPS Expansion Board. If you need a standalone ready to go solution or need more performance please consider the LeoNTP Networked Time server unit which is available here.

As of May 2016 this was heavily reworked due to a new version of Raspbian which did all sorts of wonderful things like disabling the serial ports etc. This guide assumes Raspbian Jessie Lite June 2017 2017-06-21. No other version or distribution is supported.

I’ve also removed the off grid/standalone instructions as NTP isn’t designed to work off grid using just the NMEA derived time and PPS to discipline it.

HAB Supplies Raspberry Pi+ GPS Expansion Board

Uputronics Raspberry Pi+ GPS Expansion Board

Ideally rather than supplying a premade image I would have a set of concise instructions on making your own install from scratch so you could use the latest versions of the software. With assistance from David Taylor who did lots of background work on this here I present the following instructions on making a cheap PPS disciplined NTP Time server using one of the Raspberry Pi+ GPS boards sold on Uputronics.

The guide assumes you have a cursory knowledge of Linux, enough to install Raspbian and login should do.

You will need a Raspberry Pi 2 or 3 B+, the Uputronics Raspberry Pi+ GPS Expansion Board and a suitable GPS antenna.

This guide is assuming you’re using Raspbian Jessie Lite installed from the June 2017 image. Download and write this to an SD card (See http://www.raspberrypi.org/documentation/installation/installing-images/README.md). Other distributions may work but these instructions are known to work with Raspbian Jessie Lite.

Attach the Uputronics Raspberry Pi+ GPS Expansion Board to the Pi, insert the SD card, connect the antenna and network cable and boot the Pi up. Either connect locally or via SSH to the Pi. Follow the instructions carefully if you miss steps things won’t work.

Text in italics is what you type.
Text in red indicates editing inside a file.

Prerequisite Settings

sudo raspi-config
5 Interfacing Options
P2 SSH -> Would you like the SSH server to be enabled – YES (Recommended)
P6 Serial -> Login Shell (no) Hardware (yes)
Quit but no need to reboot at this point.

sudo nano /boot/config.txt
Add at the bottom :
# Allow the normal UART pins to work
dtoverlay=pi3-miniuart-bt
dtoverlay=pps-gpio,gpiopin=18
Save and Quit Nano.

sudo apt-get update
sudo apt-get dist-upgrade

sudo systemctl disable hciuart
sudo systemctl mask [email protected]

sudo apt-get install pps-tools
sudo apt-get install libcap-dev
sudo reboot

Verifying PPS Is Working

Ensure the GPS has a lock and the Green PPS LED on the Uputronics Pi+ GPS Expansion Board is blinking once a second.

dmesg | grep pps

Output should be similar to :

[ 2.443494] pps_core: LinuxPPS API ver. 1 registered
[ 2.446699] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <[email protected]>
[ 2.471796] pps pps0: new PPS source pps.-1
[ 2.471886] pps pps0: Registered IRQ 498 as PPS source
[ 6.965166] pps_ldisc: PPS line discipline registered
[ 6.966569] pps pps1: new PPS source ttyAMA0
[ 6.966664] pps pps1: source "/dev/ttyAMA0" added

sudo ppstest /dev/pps0

Output should be similar to:

 trying PPS source "/dev/pps0"
 found PPS source "/dev/pps0"
 ok, found 1 source(s), now start fetching data...
 source 0 - assert 1418933982.998042450, sequence: 970 - clear  0.000000000, sequence: 0
 source 0 - assert 1418933983.998045441, sequence: 971 - clear  0.000000000, sequence: 0

(Press CTRL+C to quit). This indicates the PPS Module is loaded (top example) and is working (bottom).

GPS board mounted in Geaux Robot Dog Bone Case for Raspberry Pi B+ also available from HAB Supplies

GPS board mounted in Geaux Robot Dog Bone Case for Raspberry Pi B+ also available from Uputronics

Enabling PPS/ATOM Support in NTPD

The supplied version of NTPD on the Raspberry Pi doesn’t support PPS so we need to recompile it (Please note that some of these steps may take up to 30 minutes).

wget https://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p10.tar.gz
tar zxvf ntp-4.2.8p10.tar.gz
cd ntp-4.2.8p10
./configure  –enable-lcap
make -j4
sudo make install
sudo service ntp stop
sudo cp /usr/local/bin/ntp* /usr/bin/ && sudo cp /usr/local/sbin/ntp* /usr/sbin/
sudo nano /etc/ntp.conf

Add
server 127.127.22.0 minpoll 4 maxpoll 4
fudge 127.127.22.0  flag3 1  refid PPS

Amend

server 0.debian.pool.ntp.org iburst prefer

You may also want to add your local lan to so you can query the NTP Server by adding:
restrict 192.168.1.0 mask 255.255.255.0

Note You MUST add a preferred server or PPS doesn’t work. Its worth at this point seeing if you’re ISP has its own NTP server you can use and adding that but for the purposes of this exercise adding prefer to the Debian pool one will do.

Save and close nano.

sudo nano /etc/init.d/ntp
Find the line NTPD_OPTS=”$NTPD_OPTS -u $UGID”
Amend it to say NTPD_OPTS=”$NTPD_OPTS”

sudo systemctl daemon-reload

sudo service ntp restart

After a few minutes run

ntpq –p

if you get oPPS(0) this indicates source selected, Pulse Per Second (PPS) used and everything is working.

If you aren’t seeing the settings its possible the NTP server is picking up the NTP information via DHCP which is over riding your settings above. Do this :

rm /etc/dhcp/dhclient-exit-hooks.d/ntp
rm /var/lib/ntp/ntp.conf.dhcp

At this point you have a NTP server which will use an external time source and use your local PPS to discipline it.

Setting Stationary Mode

Grab this small program code here : https://pastebin.com/YTc9Nd3D
Compile + link:

gcc -o gpsControl gpsControl.c

sudo ./gpsControl -p -d /dev/ttyAMA0 = Portable Mode
sudo ./gpsControl -s -d /dev/ttyAMA0 = Stationary Mode

May take a few goes to set it.

pi@hypatia:~ $ sudo ./gpsControl -s -d /dev/ttyAMA0
Set GPS for stationary mode
Configuring device /dev/ttyAMA0
>>>>>>>>>>>>>>>>>>>>> SENDING >>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>> SENDING >>>>>>>>>>>>>>>
GPS mode set OK

Static IP + Hostname

If you want to fix your LAN IP you do it by amending /etc/dhcpcd.conf adding the following lines:

interface eth0
static ip_address=192.168.1.7/24
static routers=192.168.1.254
static domain_name_servers=8.8.8.8 8.8.4.4

Amend your hostname by editing /etc/hostname and then adding this to /etc/hosts as well. I.e if you call your machine ‘eleanor’ add this after localhost in /etc/hosts:

127.0.0.1 localhost eleanor

Further Reading

David Taylor’s website here http://satsignal.eu/ntp/Raspberry-Pi-NTP.html goes into much further detail about the process above and covers graphing, remote access monitoring etc and I highly recommend you read it.

References from this draft document by Eric S. Raymond https://www.ntpsec.org/white-papers/stratum-1-microserver-howto/

Hope this helps, let me know how you get on with these instructions and I’ll try keep them up to date.

Thanks to:

David Taylor
Dave Akerman
Chris Stenton for the new kernel fix.
Tris Mabbs for the DHCP issue heads up.
Michiel Kanis for testing DHCP fix.
Phil Heron for the GPSD Autostart fix.

Updated : 27/06/17 Fixed for new June 2017 Raspbian. Updated links to ntp-4.2.8p10.
Updated : 25/05/16 Fixed for Pi3/May Raspbian. Removed Standalone mode (NTP isn’t designed for this)
Updated : 22/03/16 Added Pi3/Standalone etc
Updated : 24/02/16 Added Code to set stationary mode.
Checked : 29/09/15 Works with Raspian Jessie – Thx Ciaran!
Updated : 03/07/15 NTP version and location amended – Thx Greg!
Checked : 13/06/15 Works with 2015-05-05-raspbian-wheezy.img
Updated : 13/04/15 ntp-4.2.8p2.tar.gz links updated.
Updated : 23/02/15 Verified these instructions are good with 2015-02-16-raspbian-wheezy.img as a base
Updated : 20/02/15 ntp-4.2.8p1.tar.gz links updated.
Updated : 28/01/15 DHCP Client can pick up NTP from DHCP server and override all your good work. See below.
Updated : 27/01/15 New kernel breaks previous instructions. Updated.
Updated : 26/12/14 Updated NTP to 4.2.8 and tested with Raspbian 2014-12-14

Leave a comment ?

196 Comments.

  1. Comment from Mark Martinec which some of you may find helpful :

    Since you are already suggesting to compile ntpd from source, it would make sense to get rid of the two dozens of unused clock drivers which are enabled by default. So my suggestion is:

    ./configure –enable-linuxcaps \
    –disable-all-clocks –disable-parse-clocks \
    –enable-NMEA –enable-ATOM

    (optionally consider also:
    –enable-ntpdate-step –disable-hourly-todr-sync
    –disable-nls –disable-autokey –without-net-snmp-config )

    My second comment is about your seconds-enumerating reference clock, for which you are suggesting a network server, e.g.:

    server 0.debian.pool.ntp.org iburst prefer

    This is fine if a computer is connected to a network, but useless for standalone setups. Moreover, since there is already a GPS receiver connected with its PPS as well as its serial line to the RPi, it makes it a natural choice to use its NMEA serial stream for seconds counting – costs nothing, just needs a proper configuration.

    The MAX-7Q by default sends its NMEA at 9600 baud, so all that is needed is to make the serial line available to ntpd and to enable its NMEA clock driver (Type 20).

    Moreover, regarding PPS, there are two choices: either use the Type 22 PPS Clock Discipline (= ATOM) clock driver as you are suggesting (in addition to NMEA for seconds counting), or just let the NMEA clock driver handle the PPS too, in which case a separate Type 22 driver becomes redundant.

    So the possible configs are:

    separate PPS & NMEA clock drivers (interesting for testing):

    # NMEA /dev/gps0, RMC, 9600
    server 127.127.20.0 mode 17 minpoll 4 maxpoll 4 prefer
    fudge 127.127.20.0 flag1 0 flag3 0 time2 0.115

    # Atom/PPS (/dev/pps0)
    server 127.127.22.0 minpoll 4 maxpoll 4
    fudge 127.127.22.0 flag3 0 refid PPS

    or the simpler setup with only one driver, which I’m suggesting:

    # NMEA /dev/gps0, /dev/gpspps0, RMC, 9600
    server 127.127.20.0 mode 17 minpoll 4 maxpoll 4 prefer
    fudge 127.127.20.0 flag1 1 flag3 0 time2 0.115

    Performance is the same, the NMEA driver just deals with both data sources (PPS & serial) and feeds PPS directly to a NTP clock discipline, just like the ATOM driver.

    About the ‘magical’ time2 0.115 and mode 17:
    it turns out that the RMC NMEA records from MAX-7Q come first after a full second tick, and that their delay is about 0.115 ms after the PPS pulse. I have verified it by comparing to our institute’s stratum-1 ntp server (Trimble Accutime, connected to the same LAN). The exact value of time2 is not important as long as it gets within a 0.5 second interval from the PPS pulse, but when using separate drivers it looks nice if the NMEA source comes close to the PPS source.

    There is one detail that still needs to be addressed:
    stealing the serial line from Linux getty making it available for reading by ntpd, and creating soft links in /dev named /dev/gps0 and /dev/gpspps0 which are needed by a NMEA ntp driver (names are not configurable in ntp).

    Stealing serial line from getty:

    # /usr/bin/raspi-config
    -> Advanced Options -> Serial ->
    Would you like a login shell to be accessible over serial? No

    Adding soft links:
    /dev/gps0 -> /dev/ttyAMA0
    /dev/gpspps0 -> /dev/pps0
    can be done automatically by udev by creating rules, for example creating a file in /etc/udev/rules.d/ e.g. /etc/udev/rules.d/55-ntp-gps.rules, with contents like:

    SUBSYSTEM==”tty”, KERNEL==”ttyAMA0″, KERNELS==”dev:f1″,
    SYMLINK+=”gps0″
    SUBSYSTEM==”pps”, KERNEL==”pps0″, SYMLINK+=”gpspps0″

    A reboot will now release a serial line as well as create soft links.

    Btw, the PRi Model B is capable of handling several hundred NTP requests per second (caps at 1200/s) over a 100 Mbps Ethernet (with crypto/autokey disabled). Should be plenty for a small to mid-sized company. Works over IPv6 too (add a line: ipv6 to /etc/modules, and configure address on the interface).

  2. Hi Anthony and Mark,

    Today I did a new installion with the suggestions of Mark. This is my output of the ntpq -p:
    command:

    remote refid st t when poll reach delay offset jitter
    ==============================================================================
    oPPS(0) .PPS. 0 l 12 16 377 0.000 -0.001 0.004
    192.168.178.255 .BCST. 16 B – 64 0 0.000 0.000 0.004
    *services.freshd 213.136.0.252 2 u – 64 377 21.429 -1.571 0.471
    +213.109.127.82 193.79.237.14 2 u 34 64 377 23.128 -2.190 0.143
    +213.109.127.195 193.79.237.14 2 u 35 64 377 24.375 -1.938 0.095
    -ran.as65342.net 192.36.144.23 2 u 42 64 377 21.235 -0.887 0.100

    First of all my provider disconnect me from the internet because I didn’t add “disable monitor” in /etc/ntp.conf file.
    When execute dmesg | grep pps I got new PPS source pps.-1 instead of new PPS source pps-gpio.18.
    But when executing all the tests I was successfull.

    I am not sure but when execute ./configure I’ll think the proper design would be:

    ./configure -–enable-linuxcaps \
    -–disable-all-clocks –disable-parse-clocks \
    -–enable-NMEA –enable-ATOM \
    -–enable-ntpdate-step -–disable-hourly-todr-sync \
    -–disable-nls -–disable-autokey \
    –-without-net-snmp-config && make

    I also create the rule to create the softlinks, is there any way to test if this was successfull?

    Now waiting for the score I will get from the folks at the NTP Pool Project.

    Thanks in advanced,

    Michiel Kanis

  3. I found your excellent description after I had followed David Taylor’s quick-start page (using the later ntp-4.2.8p2 tarball). I’m using the HAB GPS board on a Pi B+ and it all appears to be working. My uncertainty is around recompiling ntpd: neither you nor DJT enable-ATOM in config, though you enable-linuxcaps, which he doesn’t. Can my NTP server be working correctly without ATOM enabled? It’s easy enough to go back and recompile ntpd following the guidelines here, but can I do this over the existing module or must I remove the ntp* instances.
    Thanks

  4. Hi Walter,
    I think when you recompile ATOM is built in by default now. You can certainly check its working with the output of ntpq -p check the PPS line and check it has says oPPS(0) next to it. I don’t think linux caps is needed any more. I may spend this weekend going back over the instructions and checking them. I do occasionally do this to keep them upto date as between Raspberry Pi updates and NTP updates things generally break 🙂

  5. Martin G0HDB

    Hi Anthony, I have a few questions for you about your excellent build instructions that even I, as a complete Linux newbie, should be able to follow given a fair wind and a favourable tide… 🙂

    1. The latest version of Raspbian-wheezy seems to be 2015-05-05; has your solution been tested with that version yet?

    2. Your build instructions for the NTP server are based around using a Pi Model B+ with your Pi+ GPS board for that. For the last several months I’ve had a Pi Model B, with one of your earlier GPS boards, running as an NTP server using the image that Hauke Lampe put together some time ago – this system did actually go together in about the 5minutes claimed(!) and has seemed to work very reliably. However it seems to me that perhaps I should consider bringing the system a bit more up to date so I’ll be interested to know if your current build instructions will work successfully with the older hardware, assuming I start with either the current 2015-05-05 or the earlier 2015-02-16 version of wheezy?

    3. It’s occurred to me that it might be extremely useful to attach an LCD display, eg 16 char x 2 line, to a Pi that’s running as an NTP server so that the time, date etc can be displayed, thus making the NTP server also into an accurate and very useful clock for use in, for example, an amateur radio ‘shack’. Do you know if anyone has tried this and how difficult it might be to get such a system up and running (especially for a novice like me!)?

    Thanks in advance,

    Martin

  6. Hey Martin,

    Timely I checked it this afternoon with 2015-05-05-raspbian-wheezy.img and it worked fine. The instructions work with both the original Pi, the Pi+ and the V2 Pi+ (In fact I tested it on a V2 B+ today). I’d start from scratch with the whole O/S, the Lampe image has a version of NTP with a vulnerability in it now so strongly recommend you update asap.

    As for a display in theory should be doable. I’ll check out the Adafruit one and see what I can come up with. As long as it doesn’t use GPIO18 or serial should be fine.

    Cheers

  7. Martin G0HDB

    Hi Anthony, many thanks for the information – it’s good to know that your current build instructions will (should!) work for my Model B Pi that has one of your original GPS add-on boards attached.

    I’ve just downloaded 2015-05-05-raspbian-wheezy.img and written it onto an 8G SD card so sometime soon I’ll get round to putting the card into the Model B Pi that has your GPS board attached and trying to follow your build instructions. If for some reason I don’t succeed then I can always revert to the existing setup that is using the Lampe image although as you point out that’s no longer a desirable configuration.

    Re: displays, I’ve had a quick look at the Adafruit ones and they do some nice TFT HATs but these seem only to fit the Model B+ Pi’s and not my existing Model B. I do have a currently-unused Model B+ Pi but to use that I’d presumably need to buy one of your latest GPS add-on boards! An alternative might be to use the DFRobot USB-connected 2.8″ TFT display that’s available from Pimoroni; this would presumably be compatible with any current or earlier version of the Pi and would also enable the display to be sited a short distance away from the Pi and its attached GPS module. This might make for a slightly more convenient installation in some situations.

    I’ll let you know how I get on when I try your build instructions using the 2015-05-05 version of wheezy on the Model B Pi!

    Cheers

    Martin

  8. Martin G0HDB

    Hi again Anthony, just an update on my attempt to use your current build instructions with 2015-05-05-raspbian-wheezy on a Model B Pi with your older GPS add-on module.

    I’ve been through all the steps and everything seems to be working; the ntpq -p command results in ‘oPPS(0)’ being displayed on the first line and the offset is coming down nicely towards zero.

    The only part of your build instructions that didn’t give the expected result was the ‘dmesg | grep pps’ command – the resulting output wasn’t the same as you show. Instead, it looks like:

    pi@raspberrypi ~/ntp-4.2.8p2 $ dmesg | grep pps
    [ 5.752187] pps_core: LinuxPPS API ver. 1 registered
    [ 5.837847] pps_core: Software ver. 5.3.6 – Copyright 2005-2007 Rodolfo Giometti
    [ 6.068690] pps pps0: new PPS source pps.-1
    [ 6.089447] pps pps0: Registered IRQ 412 as PPS source

    However, when I use the ‘lsmod’ command as per David Taylor’s detailed instructions the result is similar to what he shows:

    pi@raspberrypi ~/ntp-4.2.8p2 $ lsmod | grep pps
    pps_gpio 2897 1
    pps_core 8752 2 pps_gpio

    So, on the face of it my new build is working correctly and my RPi-based NTP server is now running up-to-date versions of Raspbian and NTP. All we need to do now is add a display…!

    Thanks for your excellent information,


    Martin

  9. Thanks for your reply of 06/06/2015 and the check/update you made on 13/06/2015. I’ve just completed a second system using the HAB GPS board on a Raspberry Pi 2. This time I used the ./configure details that Mark Martinec provided. The Pi 2 compiles much faster so encourages making changes! I’m using a headless WiFi connection which limits ultimate performance, but until I get a switch it’s the best I can do: good enough for learning. I’d like to ‘observe’ the leap-second on June 30th and have added the leap-second file to ntp.conf and enabled loopstats, but whether I’ll understand MRTG and SNMP in time to emulate David Taylor’s plots is moot. At least I’ll have the data for post-processing.
    Once again thanks.

  10. Greg Moeller

    Just got my GPS mod from HAB, nice fit, works great.
    Tried the install and had a few issues.
    First, NTP is now P3, the download link is broke.
    Next, I was having issues with ./configure.
    I was trying Anthony’s config and it wasn’t working at all.
    Just discovered the issue, copying/pasting from this blog make a hash of the text.
    But, when I pasted the configure line into my terminal, it still looked ok. Found the problem when I grepped out the line from .bash_history.

    ./configure –enable-linuxcaps –disable-all-clocks –disable-parse-clocks –enable-NMEA –enable-ATOM

    The blog seems to be doing special things to the ‘-‘ character. Just a warning to folk who get strange results.
    Last, rpi-update brings the kernel to 4.0.7 which doesn’t seem to cause too many problems but the symlink line of Anthony’s no longer works, I took out the KERNELS param and that made it better.

    Hope this helps some folk.

    Greg

  11. Hi Greg,

    Thanks for letting me know.

    Looks like its changed in the last day or so. I’ve updated the links for NTP. Not sure why the cut and paste is messing up, I tested it here and I can’t replicate the issues.

    Cheers

  12. Stratum-1 NTP server, part 2 | Richard WM Jones - pingback on 04/07/2015 at 14:43
  13. Martin G0HDB

    Hi Anthony, further to my earlier comments here’s an update on what I’ve been doing with the R-Pi since I first got it running as an NTP server by following your excellent instructions.

    I’ve just followed the revised instructions for installing NTP 4.2.8p3 and everything still seems to be working correctly so once again I’m very grateful to you for making it so easy for a complete novice like me to get the NTP server up and running.

    Fortunately, when I installing 4.2.8p3 I didn’t experience the problems that Greg (Moeller) seemed to have with cutting-and-pasting your instructions; I was connected to the Pi via an SSH session and I just copied each line from the instructions on this website and pasted them into the SSH terminal screen and everything worked perfectly.

    Re: my previous suggestion about adding a display to the NTP-serving Pi, I’ve achieved this by following the build instructions provided by David Taylor for a digital wall clock based on a Pi. I’ve connected a small(5″) LCD with a resolution of 800 x 480 to the Pi’s composite video output and have installed David’s DigitalClock program and it works beautifully so I now have a highly-accurate clock that sits on my windowsill alongside some of my amateur radio equipment.

    Cheers


    Martin

  14. Got any pics of the setup ?

  15. Martin G0HDB

    Hi Anthony, I’ve got some pics of the digital clock but I can’t see how to post them directly into these comments. If you let me have your email address I’ll send the pics to you and you can decide what to do with them.

    FYI, I got the LCD monitor that I’ve connected to the NTP-serving Pi from eBay, it’s described as “5inch 800*480 TFT LCD HD Screen Monitor for Rear Reverse Rearview Backup Camera” and it cost about £17.


    Martin

  16. Martin G0HDB

    Here’s a couple of pics of the digital clock in situ.

    http://imgur.com/X5HQ2bq

    http://imgur.com/Rsa8ewR


    Martin

  17. Martin G0HDB

    And another pic of the digital clock.

    http://imgur.com/QP4ELgV


    Martin

  18. Faber Chri

    Hi all,

    I want to use the GPS signal as time source if no internet is available.

    Currently I see the following output of ntpq -p:

    
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
    *SHM(0)          .SHM.            0 l    7   16    1    0.000  -89.953   0.001
     SHM(1)          .PPS.            0 l    -   16    0    0.000    0.000   0.000
     bind.ch         195.186.4.100    3 u    1   64    1    1.269   32.209   4.181
     192.33.214.57   129.194.21.195   2 u    -   64    1    5.428   33.146   4.184
     bwntp1.bluewin. 195.186.197.242  2 u    -   64    1    2.584   37.009   4.924
     gintonic.woody. 82.197.164.46    3 u    1   64    1   14.755   28.435   4.554
    

    with the following servers in the config:

    
    server 127.127.28.0 minpoll 4
    fudge  127.127.28.0 time1 0.000 refid SHM
    server 127.127.28.1 minpoll 4 prefer
    fudge  127.127.28.1 refid PPS
    
    server 0.debian.pool.ntp.org iburst prefer
    server 1.debian.pool.ntp.org iburst
    server 2.debian.pool.ntp.org iburst
    server 3.debian.pool.ntp.org iburst
    

    However as soon as I unplug the ethernet cable from the raspberry, ntpq -p gives ‘Name or service not known’.
    I want that ntpd continues syncing time with the remaining SHM / PPS time source from the GPS. How can I achieve that?
    Many thanks for your help!

  19. pi@raspberrypi ~ $ ntpq -p
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
    *GPS_NMEA(0)     .GPS.            0 l   10   16  377    0.000   -0.150   0.493
    oPPS(0)          .PPS.            0 l    7   16  377    0.000    0.000   0.006
    

    
    leapfile /home/pi/ntp/leap-seconds.file
    # NMEA /dev/gps0, RMC, 9600
    server 127.127.20.0 mode 17 minpoll 4 maxpoll 4 prefer
    fudge 127.127.20.0 flag1 0 flag3 0 time2 0.115
    
    # Atom/PPS (/dev/pps0)
    server 127.127.22.0 minpoll 4 maxpoll 4
    fudge 127.127.22.0 flag3 0 refid PPS
    

  20. Trey Forgety

    Hi all!

    I’ve gone through the steps here, but I don’t get a positive response on the ppstest line. Instead, /dev/pps0 is not found.

    The Hab gps board is powered up and has its PPS LED blinking normally.

    Any help would be greatly appreciated!

    Thanks so much for great guide, Anthony!

  21. Hi Trey,

    This is nearly always caused by the PPS not being enabled in the kernel. The important line is:

    sudo rpi-update

    If you’re starting from a different version of Raspbian let me know (Guide works for 2015-05-05-raspbian-wheezy.img)

    Cheers

  22. Trey Forgety

    Thanks, Anthony!

    That cured the “device not found” error, but now I’m getting “Connection timed out.”

    Any thoughts?

  23. Hey Trey,

    Is the GPS board blinking once a second ? Check its properly seated on the Pi (they can be a little iffy sometimes if not pushed down).

    Anthony

  24. Hello,

    I’ve a problem for use the PPS clock. Everything seems to be good.
    I use:
    – Raspbian 4.1.7-v7+ #817 SMP PREEMPT Sat Sep 19 15:32:00 BST 2015 armv7l GNU/Linux
    – ntp 4.2.8p3

    PPs0 is good:

    
    pi@raspntp ~ $ sudo ppstest /dev/pps0
    trying PPS source "/dev/pps0"
    found PPS source "/dev/pps0"
    ok, found 1 source(s), now start fetching data...
    source 0 - assert 1443019401.999990147, sequence: 550 - clear  0.000000000, sequence: 0
    source 0 - assert 1443019402.999985828, sequence: 551 - clear  0.000000000, sequence: 0
    source 0 - assert 1443019403.999986349, sequence: 552 - clear  0.000000000, sequence: 0
    

    My GPS has a lock and the green PPS LED blinking:

    
    pi@raspntp ~ $ dmesg | grep pps
    [    3.722076] pps_core: LinuxPPS API ver. 1 registered
    [    3.755745] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <[email protected]>
    [    3.853392] pps pps0: new PPS source pps.-1
    [    3.870443] pps pps0: Registered IRQ 498 as PPS source
    

    I use exactly the same configuration in ntp.conf. But I think that I’ve found the problem, but I don’t know
    how I can solded it. When I restart the NTP server, I’ve an error message in syslog:
    refclock_params: time_pps_kcbind: Operation not supported

    And, I haven’t “kern” but “clock_sync” :

    
    pi@raspntp ~ $ ntpq -crv -pn
    associd=0 status=0115 leap_none, sync_pps, 1 event, clock_sync,
    version="ntpd [email protected] Mon Sep 21 09:26:15 UTC 2015 (1)",
    processor="armv7l", system="Linux/4.1.7-v7+", leap=00, stratum=1,
    precision=-18, rootdelay=0.000, rootdisp=1.075, refid=PPS,
    reftime=d9ad3a48.73affb13  Wed, Sep 23 2015 16:48:40.451,
    clock=d9ad3a4d.f9de54d8  Wed, Sep 23 2015 16:48:45.976, peer=35176, tc=4,
    mintc=3, offset=0.010521, frequency=-0.184, sys_jitter=0.003815,
    clk_jitter=0.020, clk_wander=0.003
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
    o127.127.22.0    .PPS.            0 l    6   16  377    0.000    0.011   0.004
    *195.154.216.44  195.83.222.27    2 u   16   64  377   20.312    0.635   0.270
    

    Thanks for your help.

  25. Hi Anthony,

    Just rebuilt a test system based on the new Raspian Jessie. At first glance, these instructions still hold and produce a working system 😆

    73
    Ciaran

  26. Thanks Ciaran that saved me an hour this evening :mrgreen:

  27. Hi Greg,

    I’m not sure what the issue is here as o next to PPS indicates it is using PPS. Unless I’m missing something it looks like its working ?

    Cheers,

    Anthony

  28. Bob Geddes

    The May and September release of Raspbian appear to work well and identically with regards to Anthony’s instructions above.

    I tried Marks additions for NMEA and Atom and they work if I add the symbolic links by hand each time. However I had no luck with his udev bits to cope with reboots – not helped by the fact I had never played with that part of Linux.

    My alternative solution was to edit the /etc/init.d/ntp file and add the following after the “start)” at line # ~53.
    # bobg added 6oct15
    echo `date` >> /home/pi/ntp
    echo “Checking to see that pps-gpio is loaded ” >> /home/pi/ntp
    res=`lsmod | grep pps_gpio`
    if [ -z “$res” ]
    then echo “pps-gpio is not loaded, loading..” >> /home/pi/ntp
    modprobe pps-gpio
    fi
    echo “Checking for symbolic links” >> /home/pi/ntp
    if ! [ -c /dev/gps0 ]
    then echo “Adding GPS symlink” >> /home/pi/ntp
    ln -s /dev/ttyAMA0 /dev/gps0
    fi
    #bobg

    server now running at ntp.tidy.org

    regards
    Bob

  29. Sebastian Nielsen

    Found out that the DHCP fix didnt work.
    Did the following:

    root@raspberrypi:/etc# chattr +i /etc/ntp.conf
    root@raspberrypi:/etc# service dhcpcd restart
    dhcpcd[2571]: sending signal TERM to pid 2545
    dhcpcd[2571]: waiting for pid 2545 to exit
    dhcpcd[2573]: version 6.7.1 starting
    dhcpcd[2573]: all: IPv6 kernel autoconf disabled
    dhcpcd[2573]: eth0: adding address fe80::fc3:670c:e188:39aa
    dhcpcd[2573]: if_addaddress6: Operation not supported
    dhcpcd[2573]: DUID 00:01:00:01:1c:dd:60:6c:b8:27:eb:1d:10:8a
    dhcpcd[2573]: eth0: IAID eb:1d:10:8a
    dhcpcd[2573]: eth0: rebinding lease of 192.168.1.11
    dhcpcd[2573]: eth0: changing route to 192.168.1.0/24
    dhcpcd[2573]: eth0: changing default route via 192.168.1.1
    /lib/dhcpcd/dhcpcd-run-hooks: 148: /lib/dhcpcd/dhcpcd-hooks/50-ntp.conf: cannot create /etc/ntp.conf: Permission denied
    dhcpcd[2573]: forked to background, child pid 2596
    root@raspberrypi:/etc#

    Changing the permission of ntp.conf so the dhcpcd didnt have write permission, did reveal where the Changes to ntp.conf did originate from.

    Apparently, in addition to /etc/dhcp/dhclient-exit-hooks.d/ntp, you have to delete /lib/dhcpcd/dhcpcd-hooks/50-ntp.conf aswell.

    Deleting 50-ntp.conf (which is a script), solves the problem.

  30. Following the above guide I got this in my /var/log/daemon log:
    refclock_params: time_pps_kcbind: Operation not supported
    Thought it was a kernel error but traced it to the source code above.

    I ended up compiling my own .deb for the pi that worked nicely.

    You can get it here:
    wget http://s000.tinyupload.com/index.php?file_id=79407157783045193864

    then just a
    dpkg -i ntp_4.2.6.p5+dfsg-7~pps_armhf.deb

    edit the /etc/ntp.conf to prefer a time server nearest to you like this:
    # pps-gpio on /dev/pps0
    server 127.127.22.0 minpoll 4 maxpoll 4
    fudge 127.127.22.0 refid PPS
    fudge 127.127.22.0 flag3 1 # enable kernel PLL/FLL clock discipline

    # gpsd shared memory clock
    server 127.127.28.0 minpoll 4 maxpoll 4 prefer # PPS requires at least one preferred peer
    fudge 127.127.28.0 refid GPS
    fudge 127.127.28.0 time1 +0.130 # coarse processing delay offset

    server 2.hk.pool.ntp.org prefer

    server 0.debian.pool.ntp.org iburst
    server 1.debian.pool.ntp.org iburst
    server 2.debian.pool.ntp.org iburst
    server 3.debian.pool.ntp.org iburst

  31. I have two of these rascals running now and it’s been virtually flawless. Great tutorial and great hardware! Thanks to all who had a part in making this page!

  32. Barry Jones

    Hello Anthony

    A recent Raspberry Pi upgrade has broken my NTP server, so I followed your instructions above. Whilst looking round the https://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ directory, I noticed in the NEWS file that there is a recommendation to upgrade to ntp-4.2.8p4. The newer version is available from the same folder or from http://archive.ntp.org/ntp4/ntp-4.2/ntp-4.2.8p4.tar.gz.

    I have used the newer version to upgrade my NTP server, and it all appears to be working as expected. I thought I’d let you know.

    Kind regards

    Barry Jones

  33. Hi, I know that this is a stupid stupid question, but having set this up sucessfully, and connected it to my home network, how do I access it as an ntp server, i.e. what do I put in the Windows (10) Internet Time Server box? IP address doesn’t work. I’m missing the obvious here. 🙁

  34. It does seem to work with the IP address under Windows 7. Try this (run as administrator)

    notepad C:\windows\system32\drivers\etc\hosts

    Add :

    192.168.1.1 NTPSERVER

    Save it and close then stick NTPSERVER in Windows time.

  35. Thanks, that fixed it

  36. Hi, on ModMyPi states “Its worth noting the module can, with a serial command, be placed in “Stationary” dynamic mode”.
    How can this be done ? Thru gpsctl ?

    Thanks.

    Marco.

  37. Hi there

    I’ve got an odd problem and wondered if anyone with a bit more knowledge could shed any light on it for me?
    Last week I bought all the required hardware for this project as listed as I need an accurate time source for other things I’m playing with.
    It all turned up Monday 14th and I had chance to play with it on the Tuesday 15th before I went to work and everything installed perfectly and I had a really nice offset decrease appearing. I then decided to set up my WI-FI dongle so I could ditch the network cable and this is where things started to go wrong. Somehow the WI-FI config didn’t work, crashed the GUI desktop and on rebooting the Pi it just sat there. I was unable to PuTTY to it or get it to do anything with a direct connection to a monitor with a keyboard.

    I haven’t been able to look at it again until today (Friday 18th), when I reflashed an SD card with a new image of Wheezy and started again from scratch.
    Three attempts later I was no further forward. Following Anthony’s guide as I did on Tuesday the Pi refuses to reboot after the last sudo reboot in the prerequisite section. Strangely when trying to reboot the LEDs on the on-board NIC switch off and it just sits there.

    Breaking it down I’ve worked through it step by step rebooting after each install / process.
    The problem arises after installing pps-tools – the Pi just hangs and makes an interesting paper weight but that’s about it.

    The only assumption I can make is that there has been a change in a package somewhere in the prerequisite stages which is breaking the configuration in a way serious enough to prevent the Pi from booting.

    Can anyone advise if this is likely or if they have experienced anything similar? I’m amazed that there have been any changes in the space of 3 days to packages which would cause such terminal results.

    Moving on slightly, I’ve discovered that if you use Jessie rather than Wheezy exactly the same problems arise BUT if you don’t follow any of the steps until installing pps-tools things appear to work.

    I say that as I’m still compiling ntp-4.2.8p3 now but the PPS tests show that the PPS module is loaded and working.

    If this all works or fails I’ll post the final result, but if there is anyone who could advise or comment as to what is going wrong I’d be extremely grateful.

    Many thanks

    John

  38. Further to my last . . .

    It works. Just to re-iterate this is by omitting the following steps –

    sudo apt-get update
    sudo apt-get dist-upgrade
    sudo rpi-update
    sudo reboot

    and following the guide from –

    sudo apt-get install pps-tools

    ntpq -p reports –

    remote refid st t when poll reach delay offset jitter
    ==============================================================================
    oPPS(0) .PPS. 0 l 14 16 377 0.000 -0.026 0.002
    *tilia.zsx.hu 192.53.103.108 2 u 50 64 377 49.316 -3.159 0.116
    +148.251.6.51 (a 131.188.3.221 2 u 58 64 377 35.435 -4.299 0.077
    +178.18.118.13 ( 158.43.192.66 2 u 19 64 377 11.351 -0.160 0.120
    -ns1.telecom.lt 212.59.3.3 2 u 43 64 377 55.065 -5.190 0.123

    I’ve sort of answered my own question but knowing the root cause would be a bonus in case it results in breaking the ntp server again.

    Thanks for the well written guide. It made this a lot easier than it could have been.

    Regards

    John

  39. Hey John, no idea what you managed to do there, I’ve not seen the issues you had. It is possible to corrupt SD cards and render the Pi unbootable but its not something I’ve seen for a while. Glad its now working though.

  40. Have successfully updated my two pool servers to “Jessie” 2015-11-21 distribution – no significant issues seen using the above recipe.

  41. Eric Dittman

    I received my GPS module and antenna today and got this going. I started with Raspbian Jessy Lite and followed the instructions. There was no rpi-update but that didn’t seem to be an issue. Like some others have reported, “dmesg | grep pps” shows “pps pps0: new PPS source pps.-1”. At the point of downloading ntp I jumped to Anthony’s instructions. I did download, build, and install ntp-4.2.8p4. I used the configuration with one driver.

    The udev rules didn’t work until I removed the KERNELS==”dev:f1″ parameter.

    I also had to go around with getting dhcp turned off since I use a static IP and didn’t want to rely on the dhcpd server being up to hand out an address.

    Here’s the output of “ntpq -p”:

    # ntpq -p
    remote refid st t when poll reach delay offset jitter
    ==============================================================================
    oGPS_NMEA(0) .GPS. 0 l 2 16 377 0.000 0.004 0.004

    My next step will be to configure all my systems to use this as their primary ntp source. Then, order another GPS module and cable to build another one.

  42. Eric Dittman

    That should say “…I jumped to Anthony’s comment with Mark’s instructions…”

  43. Martin G0HDB

    Hello all, firstly a Happy New Year to everyone.

    My Pi-based NTP server, using 2015-05-05-raspbian-wheezy, NTP 4.2.8p3 and an attached small (5″) LCD with a resolution of 800 x 480 to display the time, has been running happily and seemingly without problems for about 6 months. I now want to update to NTP version 4.2.8p4 and, being a Linux novice, am a bit unsure about how to do this.

    Can I just follow the instructions given above for installing PPS/ATOM support in NTPD but changing the ‘wget’ link to: wget https://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p4.tar.gz (dated 2015-10-21)?

    I’ve checked that the path is correct… 🙂

    I’ll want to keep my existing ntp.conf so will rename it and then re-instate it after doing the ‘sudo cp /usr/local…’ part of the instructions.

    I’ll probably take the opportunity to do an ‘apt-get dist-upgrade’ at the same time as installing NTP 4.2.8p4; I assume that a reboot of the Pi will then be necessary.

    Thanks in advance for whatever help and guidance you can give,


    Martin

  44. Eric Dittman

    This morning I’m getting this:

    $ ntpq -p
    remote refid st t when poll reach delay offset jitter
    ==============================================================================
    xGPS_NMEA(0) .GPS. 0 l 9 16 377 0.000 11.732 0.022

    Any ideas?

  45. Eric Dittman

    John, I’m getting the “refclock_params: time_pps_kcbind: Operation not supported” error message as well. I’m using a later version of ntp. What configure options did you use to get rid of this message?

  46. Hi Eric

    What steps past the instructions above have you done. I can try replicate it here.

    Cheers

  47. Richard Tector

    Hi,

    Has anyone noticed that the PPS clock (using a HAB board) is consistently ~3.2 ms out?

    eg. vs. one of LINX’ time servers:

    
    root@tick:~# ntpdate -q ntp0.linx.net
    server 195.66.241.2, stratum 1, offset -0.003301, delay 0.04573
    10 Jan 21:07:13 ntpdate[1204]: adjust time server 195.66.241.2 offset -0.003301 sec
    

    The RPi is correct as far as it is concerned:

    root@tick:~# ntpq -p
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
    *SHM(0)          .GPS.           14 l   10   16  377    0.000    2.395   0.670
    oPPS(0)          .PPS.            0 l    9   16  377    0.000   -0.002   0.002
    

    Adding my RPi (last entry) to a remote system along with a number of well-used servers in the UK shows the offset quite clearly as well:

    remote refid st t when poll reach delay offset jitter
    ==============================================================================
    -ntp0.pipex.net .PPS. 1 u 53 128 377 8.980 -0.214 0.093
    -ntp1.pipex.net 193.67.79.202 2 u 114 128 377 9.913 -0.218 0.135
    -ntp0.admin.zen. 195.66.241.3 2 u 118 128 377 10.079 0.102 0.022
    +ntp1.admin.zen. 195.66.241.3 2 u 44 128 377 3.128 0.069 0.126
    -ntp1.ja.net .GPS. 1 u 41 128 377 12.085 -0.231 0.096
    -ntp4.ja.net .DCFa. 1 u 34 128 377 11.686 0.319 0.096
    +ntp0.linx.net .PPS. 1 u 41 128 377 9.408 0.124 0.348
    +ntp1.linx.net .PPS. 1 u 46 128 377 9.278 0.053 39.778
    *ntp2.linx.net .GPS. 1 u 46 128 377 9.497 0.119 39.765
    -x.x.x.x .PPS. 1 u 117 128 377 28.619 3.445 0.143
    </code?

  48. Hi Richard,

    PPS is only used to discipline another time source. Can you post your ntpd.conf to pastebin and stick a link here ?

    Cheers,

    Anthony

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Human test : * Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.