Chrony and GPSD
Sources such as:
- http://www.rjsystems.nl/en/2100-ntpd-garmin-gps-18-lvc-gpsd.php
- http://lists.ntp.org/pipermail/questions/2005-November/007878.html
Describe how to wire a Garmin gps 18 lvc to a serial port to grab the PPS (pulse-per-second) signal to create a Stratum 1 timesource. Other sources show using ntpd, and the gpsd man page provides config snippets.
Alpine Linux gpsd package 3.9-r1 and higher has the necessary pps code to interface with chrony. This page lists all of the files for a complete, working example:
- /etc/modules needs to list the pps_ldisc module - you'll need to manually load it if not doing a reboot
Contents of /etc/modules
pps_ldisc
- If the GPS 18 LVC is on /dev/ttyS1, then:
Contents of /etc/conf.d/gpsd
# The GPS device (/dev/ttyUSB0, /dev/ttyS0, ...)
DEVICE="/dev/ttyS1"
BAUDRATE="4800"
# Optional arguments
# Options include:
# -b = bluetooth-safe: open data sources read-only
# -n = don't wait for client connects to poll GPS
# -N = don't go into background
# -F sockfile = specify control socket location
# -G = make gpsd listen on INADDR_ANY
# -D integer (default 0) = set debug level
# -S integer (default 2947) = set port for daemon
ARGS="-n -b"
# Serial setup
#
# For serial interfaces, options such as low_latency are recommended
# Also, http://catb.org/gpsd/upstream-bugs.html#tiocmwait recommends
# setting the baudrate with stty
# Uncomment the following lines if using a serial device:
#
/bin/stty -F ${DEVICE} ${BAUDRATE}
/bin/setserial ${DEVICE} low_latency
- This shows all three methods of getting time from gpsd:
Contents of /etc/chrony/chrony.conf
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
initstepslew 30 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org
# SHM0 from gpsd is the NEMA data at 4800bps, so is not very accurate
refclock SHM 0 delay 0.5 refid NEMA
# SHM1 from gpsd (if present) is from the kernel PPS_LDISC
# module. It includes PPS and will be accurate to a few ns
refclock SHM 1 offset 0.0 delay 0.1 refid PPS
# SOCK protocol also includes PPS data and
# it also provides time within a few ns
refclock SOCK /var/run/chrony.ttyS1.sock delay 0.0 refid SOCK
# If you see something in ns... its good.
# 1 second =
# 1000 ms =
# 1000000 us =
# 1000000000 ns
logchange 0.5
local stratum 10
logdir /var/log/chrony
keyfile /etc/chrony/chrony.keys
commandkey 10
dumpdir /var/log/chrony
driftfile /var/log/chrony/chrony.drift
allow all
Notes
- In /etc/chrony/chrony.conf, there are three possible time sources:
- SHM 0 (NEMA serial data)
- SHM 1 (NEMA with PPS)
- SOCK (PPS 'proprietary' gpsd/chrony interface)
- You only need 1 of them, although all 3 are shown above
- In the example above, SHM1 is specified with a delay of 0.1 to prevent it from competing with the SOCK protocol
- If you prefer to use the SHM1 source instead of SOCK, then either:
- comment out the SOCK protocol line
- or reverse the delay values.
- If you prefer to use the SHM1 source instead of SOCK, then either:
- Note that the SHM0 source (NEMA only, no PPS) is set to a higher delay - don't use it if you have PPS available.
- An example of where you would want to use SHM0 is a USB based gps receiver - they don't have the PPS line
- Chrony creates the SOCK interface; chrony should be started before gpsd. If you restart chronyd for some reason, make sure you restart gpsd after.
- The SHM0 interface can be used with USB based gps devices. In this case, use /dev/ttyUSBX in the /etc/conf.d/gpsd file, and leave the stty and setserial lines commented out.