Chrony and GPSD: Difference between revisions
No edit summary |
(update links & use https) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 2: | Line 2: | ||
Sources such as: | Sources such as: | ||
* | * https://www.rjsystems.nl/en/2100-ntpd-garmin-gps-18-lvc-gpsd.php | ||
* | * https://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 [http://gpsd.berlios.de/gpsd.html gpsd man page] provides config snippets. | 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 [http://gpsd.berlios.de/gpsd.html gpsd man page] provides config snippets. | ||
Line 15: | Line 15: | ||
* If the GPS 18 LVC is on /dev/ttyS1, then: | * If the GPS 18 LVC is on /dev/ttyS1, then: | ||
{{Cat|/etc/conf.d/gpsd|<nowiki> | {{Cat|/etc/conf.d/gpsd|<nowiki> | ||
# | # Copyright 1999-2010 Gentoo Foundation | ||
# Distributed under the terms of the GNU General Public License v2 | |||
# Config file for gpsd server | |||
# Optional arguments | # Optional arguments | ||
# Options include: | # Options include: | ||
Line 30: | Line 29: | ||
# -S integer (default 2947) = set port for daemon | # -S integer (default 2947) = set port for daemon | ||
GPSD_OPTIONS="-n -b" | |||
DEVICES="/dev/ttyS1" | |||
GPSD_SOCKET="/var/run/gpsd.sock" | |||
BAUDRATE="4800" | |||
# Serial setup | # Serial setup | ||
# | # | ||
# For serial interfaces, options such as low_latency are recommended | # For serial interfaces, options such as low_latency are recommended | ||
# Also, | # Also, https://gpsd.gitlab.io/gpsd/upstream-bugs.html#tiocmwait recommends | ||
# setting the baudrate with stty | # setting the baudrate with stty | ||
# Uncomment the following lines if using a serial device: | # Uncomment the following lines if using a serial device: | ||
Line 43: | Line 45: | ||
</nowiki> | </nowiki> | ||
}} | }} | ||
* This shows all | |||
{{Note|As of v3.11, the init.d and conf.d files have been merged from gentoo. | |||
The purpose is to allow gpsd to start without editing /etc/conf.d/gpsd. | |||
Note that while gpsd will now start without editing the conf.d file, it will do so with no gps devices attached. | |||
Also note that if you are using a serial device it is still recommended to add the stty and setserial commands as noted in the example configuration above.}} | |||
* This shows all four methods of getting time from gpsd: | |||
{{Cat|/etc/chrony/chrony.conf|<nowiki> | {{Cat|/etc/chrony/chrony.conf|<nowiki> | ||
server 0.pool.ntp.org | server 0.pool.ntp.org | ||
Line 51: | Line 62: | ||
initstepslew 30 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org | initstepslew 30 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org | ||
# SHM0 from gpsd is the | # SHM0 from gpsd is the NMEA data at 4800bps, so is not very accurate | ||
refclock SHM 0 delay 0.5 refid | refclock SHM 0 delay 0.5 refid NMEA | ||
# SHM1 from gpsd (if present) is from the kernel PPS_LDISC | # SHM1 from gpsd (if present) is from the kernel PPS_LDISC | ||
# module. It includes PPS and will be accurate to a few ns | # module. It includes PPS and will be accurate to a few ns | ||
refclock SHM 1 offset 0.0 delay 0.1 refid | refclock SHM 1 offset 0.0 delay 0.1 refid NMEA+ | ||
# SOCK protocol also includes PPS data and | # SOCK protocol also includes PPS data and | ||
# it also provides time within a few ns | # it also provides time within a few ns | ||
refclock SOCK /var/run/chrony.ttyS1.sock delay 0.0 refid SOCK | refclock SOCK /var/run/chrony.ttyS1.sock delay 0.0 refid SOCK | ||
# PPS is from the /dev/pps0 device. Note that | |||
# chronyd creates the /var/run/chrony.ttyS1.sock device, but | |||
# gpsd creates the /dev/pps0 device | |||
# openrc rules start gpsd /after/ chronyd, so /dev/pps0 | |||
# is not created until after chronyd is started | |||
# If you want to use pps0, either edit the openrc rules | |||
# or add this source after gpsd is started | |||
# refclock PPS /dev/pps0 refid PPS | |||
# If you see something in ns... its good. | # If you see something in ns... its good. | ||
Line 91: | Line 113: | ||
MS Name/IP address Stratum Poll Reach LastRx Last sample | MS Name/IP address Stratum Poll Reach LastRx Last sample | ||
=============================================================================== | =============================================================================== | ||
#x | #x NMEA 0 4 377 14 +684ms[ +684ms] +/- 252ms | ||
#+ PPS 0 4 377 13 +2040ns[+2060ns] +/- 50ms | #+ PPS 0 4 377 13 +2040ns[+2060ns] +/- 50ms | ||
#* SOCK 0 4 377 7 +225ns[ +245ns] +/- 2217ns | #* SOCK 0 4 377 7 +225ns[ +245ns] +/- 2217ns | ||
Line 98: | Line 120: | ||
^? dead.time.server.org 0 10 0 10y +0ns[ +0ns] +/- 0ns | ^? dead.time.server.org 0 10 0 10y +0ns[ +0ns] +/- 0ns | ||
* | * NMEA (SHM0) is "x" - its really unstable | ||
* PPS (SHM1) is good, but the delay of 0.1 makes it the not-preferred master | * PPS (SHM1) is good, but the delay of 0.1 makes it the not-preferred master | ||
* SOCK is the preferred master | * SOCK is the preferred master | ||
Line 105: | Line 127: | ||
== Notes == | == Notes == | ||
* In /etc/chrony/chrony.conf, there are | * In /etc/chrony/chrony.conf, there are four possible time sources: | ||
** SHM 0 ( | ** SHM 0 (NMEA serial data) | ||
** SHM 1 ( | ** SHM 1 (NMEA with PPS) | ||
** SOCK (PPS 'proprietary' gpsd/chrony interface) | ** SOCK (PPS 'proprietary' gpsd/chrony interface) | ||
* You only need 1 of them, although | ** PPS (PPS only from the serial interface pulse) | ||
* You only need 1 of them, although 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 | * 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: | ** If you prefer to use the SHM1 source instead of SOCK, then either: | ||
*** comment out the SOCK protocol line | *** comment out the SOCK protocol line | ||
*** or reverse the delay values. | *** or reverse the delay values. | ||
* Note that the SHM0 source ( | * Note that the SHM0 source (NMEA 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 | ** 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. | * 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. | * 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. | ||
[[Category:Server]] | |||
[[Category:Networking]] |
Latest revision as of 21:32, 25 August 2023
Sources such as:
- https://www.rjsystems.nl/en/2100-ntpd-garmin-gps-18-lvc-gpsd.php
- https://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
- If the GPS 18 LVC is on /dev/ttyS1, then:
Contents of /etc/conf.d/gpsd
The purpose is to allow gpsd to start without editing /etc/conf.d/gpsd. Note that while gpsd will now start without editing the conf.d file, it will do so with no gps devices attached.
Also note that if you are using a serial device it is still recommended to add the stty and setserial commands as noted in the example configuration above.
- This shows all four methods of getting time from gpsd:
Contents of /etc/chrony/chrony.conf
Chronyc
If everything is working correctly, a chronyc 'sources' command should look like this:
chronyc> sources 210 Number of sources = 6 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== #x NMEA 0 4 377 14 +684ms[ +684ms] +/- 252ms #+ PPS 0 4 377 13 +2040ns[+2060ns] +/- 50ms #* SOCK 0 4 377 7 +225ns[ +245ns] +/- 2217ns ^? tick.tock.com 2 10 377 318 -5144us[-5144us] +/- 72ms ^? time.keeper.net 3 10 377 720 -4571us[-4567us] +/- 139ms ^? dead.time.server.org 0 10 0 10y +0ns[ +0ns] +/- 0ns
- NMEA (SHM0) is "x" - its really unstable
- PPS (SHM1) is good, but the delay of 0.1 makes it the not-preferred master
- SOCK is the preferred master
- The other NTP servers are only used if the local server goes down.
Notes
- In /etc/chrony/chrony.conf, there are four possible time sources:
- SHM 0 (NMEA serial data)
- SHM 1 (NMEA with PPS)
- SOCK (PPS 'proprietary' gpsd/chrony interface)
- PPS (PPS only from the serial interface pulse)
- You only need 1 of them, although 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 (NMEA 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.