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).
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
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.
“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
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?
Attach the board the right way up 🙂
Hi David,
Yes this is correct I will document this shortly!
Cheers!
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!
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.
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.
there is an important typo here: you wanted to say:
tos mindist 0.2
It’s missing the “t”.
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?
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.
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
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
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
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!
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.
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 ?
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!
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
Thank you!
I will order today.
Apologies for no response – I can’t find your mail to us anywhere.
@Michael: try ntpq -p 127.0.0.1
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.
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!
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/
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
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.
Cheers for posting very helpful. I fixed your paste just put the code tag round it.
hi Jim,
I’m getting conflicting opinions on this so I need to do further research.
Anthony
Hi Eric,
As with Jim’s comment I’m getting conflicting information on this so I need to do some further research.
Anthony
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 😳 )
….. 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 😎
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?
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.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??
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.
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.