Chrony+gpsd ntp server on raspbian buster lite using Adafruit Ultimate GPS hat (product 2324) and Adafruit active external antenna (products 960 & 851) for NMEA time and pps
A. Apparently chrony for raspbian buster includes pps support. It works after simple apt-get install chrony (e.g. without a compile). I could never make the passthrough from gpsd to work. Got it on first try with chrony.
B. Good reference for gpsd/chrony: https://forristal.org/blog/2018/01/making-a-raspberry-pi-stratum-1-clock/
C. Good reference for getting rpi ready (mostly serial port): http://www.unixwiz.net/techtips/raspberry-pi3-gps-time.html Note that this reference uses gpsd + ntp (not chrony)
D. https://wiki.alpinelinux.org/wiki/Chrony_and_GPSD and http://robotsforroboticists.com/chrony-gps-for-time-synchronization/ are also helpful
E. Apparently kernel has or installs pps module automagically. No need to add the pps module manually.
F. install procedure (below) tested on RPI 3B+ (works). Resulting card tested on RPI 4B (works), 3B (works), and RPI zero WH (works).
Steps for headless Raspbian Buster Lite on RPI 3B+:
-
Remove trace between pps pads on the Ultimate GPS hat. Solder a 560 ohm (or more, I'd use 1k if I had one handy but tested with 560) resistor across the pps pads (this might prevent blowing things up when both the GPS and RPI try to drive GPIO4. Put RTC battery (any CR12xx) in GPS hat. The RTC is not directly accessible, but the GPS uses it to speed up warm starts etc. Do NOT plug it into the RPI yet.
-
Use balena etcher to write buster lite to SD card (4G or larger)
-
Touch ssh in /boot (e.g. in ubuntu touch /media/username/boot/ssh)
-
Copy wpa_supplicant.conf file (see example file) into /boot (https://www.raspberrypi-spy.co.uk/2017/04/manually-setting-up-pi-wifi-using-wpa_supplicant-conf/). Edit with your wifi SSID and password. You can use: wpa_passphrase YOUR_SSID YOUR_PASSWORD to generate the hashed password instead of putting it in the file in cleartext.
-
Add dtoverlay=pi3-disable-bt at the end of /boot/config.txt
-
Turn off audio #dtparam=audio=on# in /boot/config.txt
-
Add dtoverlay=pps-gpio,gpiopin=4 to the end of /boot/config.txt (or gpiopin=18 if so wired)
-
Put SD card in RPI and boot it
-
Login over ssh: it will be ssh pi@raspberrypi.local if no name conflicts, otherwise find using newest dhcp lease
-
sudo apt-get update/upgrade: may need to do sudo apt-get update --allow-releaseinfo-change
-
sudo raspi-config:
a. set hostname
b. change locale to en_US.UTF-8 UTF-8
c. set TZ to UTC
d. turn off serial port login shell, enable serial hardware
e. change password if desired
f. minimize display memory to 16M since we have no display
g. resize to fill SD card
h. reboot -
sudo systemctl disable hciuart
-
sudo apt-get install pps-tools gpsd gpsd-clients chrony
-
Remove ntp-servers from /etc/dhcp/dhclient.conf
-
sudo rm /etc/dhcp/dhclient-exit-hooks.d/timesyncd
-
sudo rm /lib/dhcpcd/dhcpcd-hooks/50-ntp.conf (might not exist)
-
sudo rm /var/lib/ntp/ntp.conf.dhcp (might not exist)
-
Edit /etc/default/gpsd to add turn off usbauto, add serial device and option -n (see example file)
-
Edit /etc/chrony/chrony.conf to choose ntp pool, configure initial slewing and add the GPS and PPS sources (see example file)
-
Make sure your antenna is outside (really!), with good sky view. This will greatly speed up/make possible acquisition of a fix good enough for pps. I never saw the WAAS sats with the antenna indoors on a south-facing windowsill, and my pps came and went randomly.
-
shutdown, power off, INSTALL GPS HAT, power on
-
Using this approach, NMEA output will be on ttyAMA0. run gpsmon to see it (see example gpsmon output file)
-
Verify that GPS gets a 4D fix and goes to quality 2 (meaning it is using WAAS satellites). This may take 30 or more minutes, especially the first time before the RTC is correct.
-
after GPS hat LED flashing drops to once every 15 sec, verify pps: sudo ppstest /dev/pps0. Should get a new line every second, with incrementing sequence numbers
-
Test chrony: run chronyc sources -v. After a few minutes, you should get something like the example sources output file
-
Test chrony: run chronyc sourcestats -v. After a few minutes, you should get something like the example sourcestats output file
-
From another (linux or OS X) machine, test from the command line: ntpdate -q rpiname.local
-
Set your computer to use the rpi as its NTP server. Check that it works. (out of scope)