5 minute guide to making a GPS Locked Stratum 1 NTP Server with a Raspberry Pi

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.

Due to significant changes to Raspbian we have decided to retire the old guide here https://ava.upuaut.net/?p=726 and redo it.This guide assumes Raspbian Stretch Lite November 2018 released 2018-11-13. No other version or distribution is supported.

This solution will not give you a standalone off grid NTP server. NTP isn’t designed to work off grid using just the NMEA derived time and PPS to discipline it. You need an external server and then use PPS to discipline it.

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 Stretch Lite November 2018 released 2018-11-13 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 Stretch 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 (If you can’t SSH in and don’t have a monitor see this https://www.raspberrypi.org/documentation/configuration/wireless/headless.md)

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) (Optional)
Quit but no need to reboot at this point.

sudo nano /boot/config.txt
Add at the bottom :

dtoverlay=pps-gpio,gpiopin=18
Save and Quit Nano.

sudo apt-get update
sudo systemctl disable hciuart
sudo systemctl mask [email protected]
sudo apt-get install pps-tools ntp dnsutils
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 now supports PPS so there is no need to roll your own NTP.

You need to pick a few local NTP servers to use. The easiest way to do this is pick your region:

https://support.ntp.org/bin/view/Servers/NTPPoolServers
Select your region then you get a list of the country servers. E.g for the UK its uk.pool.ntp.org.
Type:

dig uk.pool.ntp.org

You will get four IP’s back:

; <<>> DiG 9.10.3-P4-Raspbian <<>> +answer uk.pool.ntp.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51647
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;uk.pool.ntp.org. IN A

;; ANSWER SECTION:
uk.pool.ntp.org. 24 IN A 193.150.34.2
uk.pool.ntp.org. 24 IN A 176.58.109.199
uk.pool.ntp.org. 24 IN A 195.195.221.100
uk.pool.ntp.org. 24 IN A 185.53.93.157


sudo nano /etc/ntp.conf
Add
server 127.127.22.0 minpoll 4 maxpoll 4
fudge 127.127.22.0 flag3 1 refid PPS
tos mindis 0.2

Comment out all the pool lines:

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

Add the four servers from the dig command with the top one saying prefer on it:

server 193.150.34.2 iburst prefer
server 176.58.109.199 iburst
server 195.195.221.100 iburst
server 185.53.193.157 iburst

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.

Save and close nano.

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.

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
sout + others on #ntp irc.freenode.org

Leave a comment ?

39 Comments.

  1. Thanks for the post. Unfortunately I cannot make these things work. When I write “sudo ./gpsControl -s -d /dev/ttyAMA0” and run, I get this message:
    “Set GPS for stationary mode
    Configuring device /dev/ttyAMA0
    >>>>>>>>>>>>>>>>>>>>> SENDING >>>>>>>>>>>>>>>”

    After that there is no answer and I cannot write any new commands.

  2. “This solution will not give you a standalone off grid NTP server.”

    That’s wrong, NTP is quite capable or working stand-alone without any network connection. You need to mark the NMEA source as “prefer”. You may need an extra “flag1 1” in the fudge for the type 28 ref-clock.

    https://www.satsignal.eu/ntp/Raspberry-Pi-quickstart.html#Alaska

  3. JF Allaire

    I just got the GPS board (January 3rd 2019). My Raspberry Pi 3 B+ just won’t boot when the board is connected to it. As soon as I remove the board, the Pi boots just fine. (of course, I turn off the Pi before I plug or unplug the board)

    Is there something I should have done in the config of the Raspberry Pi before I plug in the board?

    Is there a parameter somewhere that could prevent booting with a certain connection on a pin?

    Or should I just get to the unfortunate conclusion that I received a defective board and will have to return it?

  4. Attach the board the right way up 🙂

  5. Hi David,

    Yes this is correct I will document this shortly!

    Cheers!

  6. JF Allaire

    Well, I feel a bit stupid… the “additional headers” thing is actually a spacer this should fit between the raspberry pi and the board. Now I know. Honestly though, what threw me off is the force one as to apply in order to make that thing sit where it should.

    I guess fitting tight is necessary since this is a “solderless” solution…

    Thank very much!

  7. Who's Asking?

    For the record, the hat also works correctly in a Pi 3 A+. I was even able to apply GM8ARV’s various tweaks to make the GPS time server work. Like JF Allaire, I did have the board upside-down at first, but the posts helped me to correct it. It would be advised to have people pay attention to the finished picture and point out that, for reference, the chips, components, and lights should all be facing UP.

  8. Bob Geddes

    in /etc/ntp.conf file
    tos mindis 0.2
    results in error in /var/log/syslog. However:
    tos mindist 0.2
    works
    Suspect missing t in instruction above.

  9. there is an important typo here: you wanted to say:
    tos mindist 0.2
    It’s missing the “t”.

  10. Unfortunately I cannot make these things work. When I write “sudo ./gpsControl -s -d /dev/ttyAMA0” and run, I get this message:
    “Set GPS for stationary mode
    Configuring device /dev/ttyAMA0
    >>>>>>>>>>>>>>>>>>>>> SENDING >>>>>>>>>>>>>>>”

    only thing I can do is to ctrl z to stop it…

    I tried running several times….any help on this?

  11. Hello,

    Thanks for the excellent product and a great tutorial.

    I noticed from the ntpq docs online that “tos mindis 0.2” doesn’t look quite right. Should it be “tos mindist 0.2”?

    I’ll also have a LeoNTP as my primary NTP server- and I have set that as my preferred server for the Raspberry Pi/ GPS Board. However the GPS Board (PPS) signal keeps getting given a “X” in ntp querries (as in not being used. Sometimes the LeoNTP is also being marked as “X” too.

    Any ideas why this might be?

    Lastly, I thought that using IPs directly from the NTP pool (as shown here) was generally not the best policy. They aren’t always public access servers and can be removed without warning in most cases. Any comments perhaps?

    Thanks again for the great products and support.

    Kind Regards,

    Andy.

  12. Michael Fincham

    Well I have been at this for ages, almost feel like giving up and purchasing an NTP dedicated server.

    when I type ntp -p the result I get is Temporary failure in name resolution

  13. Michael Fincham

    This is not working at all, I have followd all the instructions and when it comes to ntpq –p it fails every time

    Please help

  14. Michael Fincham

    About the 5th time I done this now and followed your instructions explicitly and this is the result I get

    source 0 – assert 1552046500.000712440, sequence: 124 – clear 0.000000000, sequence: 0
    source 0 – assert 1552046501.000717752, sequence: 125 – clear 0.000000000, sequence: 0
    source 0 – assert 1552046502.000723168, sequence: 126 – clear 0.000000000, sequence: 0
    source 0 – assert 1552046503.000728272, sequence: 127 – clear 0.000000000, sequence: 0
    ^C
    pi@NTP_MCSLTD:~ $ sudo nano /etc/ntp.conf
    pi@NTP_MCSLTD:~ $ sudo service ntp restart
    pi@NTP_MCSLTD:~ $
    pi@NTP_MCSLTD:~ $ sudo service ntp restart
    pi@NTP_MCSLTD:~ $
    pi@NTP_MCSLTD:~ $ ntpq –p
    Temporary failure in name resolution
    ntpq> exit
    pi@NTP_MCSLTD:~ $

    Any Help would be much appreciated, Thanks

  15. Can someone please tell me if the latest GPS boards have V. 3.01 FW and are Galileo capable? From the current M8Q documentation I believe they should. Thanks.

    Cheers!

  16. Anything where the Ublox module ends in -10 can use Galileo. However you need to switch the GNSS mode to use it, by default it does Glonass & GPS only. See CFG-GNSS in manual.

  17. Thats odd, points to more of a DNS issue where it doesn’t know how to resolve its own hostname.

    Check /etc/hosts and make sure you have a localhost entry ?

  18. Can you tell me if your uputronincs board has -10? I got no answer from uputronics but need to order a Galileo-enabled board pretty soon.
    Thank you very much!

  19. We’ve been fitting -10’s for at least a year now probably more.

    See here for the code or use U-Center

    https://portal.u-blox.com/s/question/0D52p00008HKDVACA5/cfggnss-for-maxm8q-to-enable-galileo

    Anthony

  20. Thank you!
    I will order today.

  21. Apologies for no response – I can’t find your mail to us anywhere.

  22. Joren Van Severen

    @Michael: try ntpq -p 127.0.0.1

  23. I’ve forked Tom Dilatush’s gpsctl (http://www.jamulblog.com/2017/11/paradise-ponders-gpsctl-functionally.html):

    https://github.com/philrandal/gpsctl

    sudo /path.to/gpsctl -a –configure_for_timing

    works for me.

  24. Eric McFall

    Just to make sure I have this correct: This setup still requires an outside connection to the NTP servers on the internet and will not work on an air-gap network that is completely not connected to the internet? Thanks!

  25. Carballada

    please check this link, a lot of problems with the port name with BT and wihtout

    https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3/

  26. Time keeper and router – PA1EJO - pingback on 26/07/2019 at 13:51
  27. jim Tallent

    Anthony, on 04/01/2019 at 21:33 you commented “Yes this is correct I will document this shortly!” I assume this was in reference to the off-grid NTP Server. Is this document available?
    Thanks

  28. This works really well with the U-blox dual band antenna.
    https://www.u-blox.com/en/product/ann-mb-series

    I had issues getting Galileo to work.
    I ended up using these commands.
    sudo gpsctl -t u-blox -b -c 1 -D 4 -s 115200 /dev/ttyAMA0
    sudo ubxtool -d BDS
    sudo ubxtool -d IMES
    sudo ubxtool -d QZSS
    sudo ubxtool -d BEIDOU
    sudo ubxtool -d SBAS
    sudo ubxtool -d SURVEYIN
    sudo ubxtool -d NMEA
    sudo ubxtool -d BINARY
    sudo ubxtool -d GPS
    sudo ubxtool -e GPS
    sudo ubxtool -e BINARY
    sudo ubxtool -d GALILEO
    sudo ubxtool -e GALILEO
    sudo ubxtool -e SBAS
    sudo ubxtool -e SURVEYIN
    sudo ubxtool -p SAVE

    (Basically turn everything off then turn on what is needed)
    I thinnk that binary mode needs to be enabled for Gaileo to work.

    This is from a Ublox dual band antenna sitting in my attic.
    xgps looks a lot better but I can’t copy it as text.

    
    ┌───────────────────────────────────────────┐┌──────────────────Seen 33/Used 26┐
    │ Time:          2019-07-30T18:20:16.000Z   ││     PRN  Elev   Azim   SNR  Use │
    │ Latitude:         40.XXXXX340 N           ││GP     2    59    298    45    Y │
    │ Longitude:        74.XXXXX290 W           ││GP     5    32    211    39    Y │
    │ Altitude:         61.289 ft               ││GP     6    60     44    47    Y │
    │ Speed:             0.01 mph               ││GP     9    26     86    42    Y │
    │ Heading:         358.7 deg (true)         ││GP    12    46    277    44    Y │
    │ Climb:            -6.89 ft/min            ││GP    17    35    122    36    Y │
    │ Status:         3D DIFF FIX (11 secs)     ││GP    19    49    116    46    Y │
    │ Long Err  (XDOP, EPX):  0.32, +/-  4.6 ft ││GP    23    14     48    31    Y │
    │ Lat Err   (YDOP, EPY):  0.40, +/-  6.2 ft ││GP    25    20    315    32    Y │
    │ Alt Err   (VDOP, EPV):  0.96, +/-  5.0 ft ││SB    46    17    246    39    Y │
    │ 2D Err    (HDOP, CEP):  0.51, +/-  2.8 ft ││SB    51    32    225    35    Y │
    │ 3D Err    (PDOP, SEP):  1.08, +/- 79.2 ft ││GL    68    40     46    39    Y │
    │ Time Err  (TDOP):       0.56              ││GL    69    57    131    46    Y │
    │ Geo Err   (GDOP):       1.22              ││GL    70    14    183    36    Y │
    │ ECEF X, VX:    1XXXXXX.760 m    0.000 m/s ││GL    74    18    248    36    Y │
    │ ECEF Y, VY:   -4XXXXXX.670 m    0.030 m/s ││GL    75    20    305    43    Y │
    │ ECEF Z, VZ:    4XXXXXX.360 m   -0.020 m/s ││GL    83    28     88    27    Y │
    │ Speed Err (EPS):       +/-  0.0 mph       ││GL    84    59      9    28    Y │
    │ Head Err  (EPD):       +/- 79.3 deg       ││GL    85    21    307    41    Y │
    │ Time offset:            0.076 sec         ││GA   301    19    310    38    Y │
    │ Grid Square:            FXXXxo            ││GA   303    35     67    39    Y │
    └───────────────────────────────────────────┘└More...──────────────────────────┘
    

  29. Cheers for posting very helpful. I fixed your paste just put the code tag round it.

  30. hi Jim,

    I’m getting conflicting opinions on this so I need to do further research.

    Anthony

  31. Hi Eric,

    As with Jim’s comment I’m getting conflicting information on this so I need to do some further research.

    Anthony

  32. Just setup a RP4 and this GPS hat, all working as per the 5-min guide. Very nice setup, with PPS working in NTP nicely.

    Device is found as pps0 in “dmesg | grep pps” and as I said everything NTP related working……

    but, my system is running in headless mode with only ssh console access – how can I get “cpgs -s” to actually show anything – curreintly just sits saying No FIX – although NTP is trimmed and PPS fix is flashing on the hat?

    (excuse the most likely noob question – but just can’t google my way around this at the moment 😳 )

  33. ….. well after a lot of searching, now sorted – just needed to know about bluetooth and as I don’t need it disabled it and reverted the serial ports as per this post:

    https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3-4/

    …. after that, all sorted 😎

  34. I’m also getting held up when I query ntpq. I’m seeing an x next to the PPS entry xPPS(0) which, afaik, means the device is not being used or trusted.

    Any ideas on how to begin troubleshooting this?

  35. I think I initially may have figured out one issue I’m having: I don’t have the same output from dmesg as is listed above. All I see is the first reference to pps0, I do not have a reference to pps1 on /dev/ttyAMA0. No idea where I could have gone wrong. I’ve run through all the steps a few times and am sort of stuck. I still am gettin an x next to the PPS entry from ntpq.

  36. Has anybody tried to adapt the setup to a Raspberry Pi 4?? I have a Pi 4 running separate from my NTP constellation and it seems to not be as jittery as the 3, but it doesn’t have a GPS or PPS (yet). Anybody feeling adventurous??

  37. Andy Bailey

    Hello,

    Thanks for the great guides.

    I have been exploring using chrony rather than NTP as it seems to offer some benefits. However, I can’t get the GPS reference clock to work with chrony.

    Any ideas or suggest (perhaps a new guide?) on how this could be done?

    Kind Regards,

    Andy.

  38. I recently (November 2020) bought the Uputronics GPS HAT and spent several days trying to get the above process to work without success. However, I then tried Phil Randall’s process here:

    http://www.philrandal.co.uk/blog/archives/2019/04/entry_213.html

    …and I’m pleased to say that it worked fine. I had to follow his guidance under the section “Postscript, June 21st, 2020” to get the clock working. I was using a Raspberry Pi 4B.

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.

Trackbacks and Pingbacks: