Skip to content

Instantly share code, notes, and snippets.

@wohali
Created May 28, 2024 15:03
Show Gist options
  • Save wohali/8770331341f53bebb7a9ede2659d6b67 to your computer and use it in GitHub Desktop.
Save wohali/8770331341f53bebb7a9ede2659d6b67 to your computer and use it in GitHub Desktop.
tips on a chrony setup using uputronix board + gpsd + chrony + chrony-exporter --> prometheus + grafana
place at /etc/systemd/system/add-gps0.service
[Unit]
Description=Add /dev/gps0 symlink
Before=gpsd.service
[Service]
Type=oneshot
ExecStart=/usr/bin/ln -s /dev/ttyAMA0 /dev/gps0
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usuable directives.
#
# Pick ntp servers closest to you network-wise, or something like:
#server 0.ca.pool.ntp.org iburst
# if you don't want to try and research what that might be.
# see https://chrony.tuxfamily.org/faq.html#_how_should_chronyd_be_configuration
_with_gpsd
# and https://chrony.tuxfamily.org/doc/4.0/chrony.conf.html
# note: if you restart chrony, you then have to restart gpsd
refclock SOCK /run/chrony.pps0.sock refid PPS
#refclock PPS /dev/pps0 lock NMEA refid GPS noselect
#refclock SHM 0 offset 0.149 delay 0.2 refid NMEA precision 1e-1 noselect
# set larger delay to allow the NMEA source to overlap with
# the other sources and avoid the falseticker status
#refclock SOCK /run/chrony.pps0.sock refid PPS precision 1e-7
#refclock SOCK /run/chrony.pps0.sock refid PPS precision 1e-7
#refclock SOCK /run/chrony.gps0.sock refid GPS precision 1e-1 offset 0.000053
#refclock SOCK /var/run/chrony.ttyAMA0.sock delay 0.0 refid SOCK
#refclock SHM 0 delay 0.325 refid GPS precision 1e-1 offset 0.000053
#refclock SHM 0 maxdelay 0.5 refid NMEA
#refclock SHM 1 offset 0.000053 delay 0.1 refid NMEA+
#refclock SHM 1 refid PPS precision 1e-7
keyfile /etc/chrony/chrony.keys
driftfile /var/lib/chrony/chrony.drift
ntsdumpdir /var/lib/chrony
leapsectz right/UTC
# ensure your ntpd can be seen from your network, e.g.:
allow 192.168.0.0/16
log tracking measurements statistics
logdir /var/log/chrony
# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0
rtcsync
makestep 0.5 -1
place at /etc/default/gpsd
# Default settings for the gpsd init script and the hotplug wrapper.
# Start the gpsd daemon automatically at boot time
START_DAEMON="true"
# Use USB hotplugging to add new USB devices automatically to the daemon
USBAUTO="false"
# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
#DEVICES="/dev/ttyAMA0 /dev/pps0"
DEVICES="/dev/gps0 /dev/pps0"
# Other options you want to pass to gpsd
GPSD_OPTIONS="-n -s 115200"
#GPSD_OPTIONS="-n"
place at /etc/systemd/system/multi-user.target.wants/gpsd.service
[Unit]
Description=GPS (Global Positioning System) Daemon
Requires=gpsd.socket
# Needed with chrony SOCK refclock
After=chronyd.service
[Service]
Type=forking
EnvironmentFile=-/etc/default/gpsd
ExecStart=/usr/sbin/gpsd $GPSD_OPTIONS $OPTIONS $DEVICES
[Install]
WantedBy=multi-user.target
Also=gpsd.socket

Diagnostics in case something seems off:

  • GPS radio

    • tail -f /dev/ttyAMA0
    • screen /dev/ttyAMA0 9600
    • ppstest /dev/pps0
    • cgps -s
    • gpsmon
  • Chrony (NTP - GPS driven)

    • chronyc sources
    • chronyc sourcestats
    • chronyc tracking
10:52 <@Wohali> i didn't do a writeup but there are several out there
10:53 <@Wohali> this is the newer version of the board i have
                https://v3.airspy.us/product/upu-rpi-gps-rtc/
10:53 <@Wohali> you also need an rpi
10:53 <@Wohali> i'm using chrony but you could also use ntpd if you prefer
10:54 <@Wohali> that dashboard is right out of the grafana dashboard "shop"
10:54 <@Wohali> with a bit of cleanup
10:54 <@Wohali> gpsd converts the PPS signal from the kernel to a socket that chrony can
                consume
10:55 <@Wohali> i used this to feed prometheus with chrony data that is then consumed by
                grafana https://github.com/SuperQ/chrony_exporter
10:56 <@Wohali> this program (NOT the gpsctl in debian pakcaging) helps configure the
                device to be in an optimal mode
10:56 <@Wohali> https://github.com/philrandal/gpsctl
10:56 <@Wohali> on boot I give it the systemd script above to ensure i get the modem in the right configuration
place in /etc/systemd/system/ublox-init.service
[Unit]
Description=u-blox initialisation
Before=gpsd.service
Before=ntp.service
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
Environment="PARAMS=-q -a -B 115200 --configure_for_timing"
EnvironmentFile=-/etc/default/gpsctl
ExecStart=/bin/bash -c '/usr/local/bin/gpsctl ${PARAMS}'
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment