We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

5 posts • Page 1 of 1
abishur
Posts: 4505
Joined: Thu Jul 28, 2011 4:10 am

Chrony not updating from GPS

Sun Jul 31, 2022 8:13 pm

I'm using a GPS module to poll for time for my raspberry pi with a pps output and have an RTC module I'm using to preserve time during power loss situations. However I'm having 2 main issues

1) GPS data is not automatically started after a reboot (must manually start cgps)
2) Chrony refuses to use GPS and PPS (seems to be an issue where if GPS time is even more than half a second off from the hardware clock everything fails) both sources have a X by them

All the guides I've looked up use the same basic format, but none of them really appear to be working. So what am I missing with these main issues?

Here's my gpsd.conf file

Code: Select all

# Devices gpsd should collect to at boot time.
START_DAEMON="true"
# They need to be read/writeable, either by user gpsd or the group dialout.
# Swap out line comments to used Serial Port 0 again
DEVICES="/dev/ttyS0 /dev/pps0"
#DEVICES=""
# Other options you want to pass to gpsd
GPSD_OPTIONS="-n"
# Automatically hot add/remove USB GPS devices via gpsdctl
USBAUTO="true"
and my chrony.conf file

Code: Select all

# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usable directives.
local stratum 10
#allow 0.0.0.0
allow 192.168.24.0/23
# Include configuration files found in /etc/chrony/conf.d.
confdir /etc/chrony/conf.d
# Use Debian vendor zone.
#pool 2.debian.pool.ntp.org iburst
refclock SHM 0 delay 0.2 refid GPS precision 1e-1 offset 0.9999
refclock PPS /dev/pps0 refid PPS precision 1e-7
# Use time sources from DHCP.
sourcedir /run/chrony-dhcp
# Use NTP sources found in /etc/chrony/sources.d.
sourcedir /etc/chrony/sources.d
# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys
# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift
# Save NTS keys and cookies.
ntsdumpdir /var/lib/chrony
# Uncomment the following line to turn logging on.
#log tracking measurements statistics
# Log files location.
logdir /var/log/chrony
# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0
# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync
# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 1 3
# Get TAI-UTC offset and leap seconds from the system tz database.
# This directive must be commented out when using time sources serving
# leap-smeared time.
leapsectz right/UTC
Has anyone got this working on their system who can help me out?

memjr
Posts: 4512
Joined: Fri Aug 21, 2020 5:59 pm

Re: Chrony not updating from GPS

Sun Jul 31, 2022 8:24 pm

Sorry, I can't help you with any of that as I have never used any of it.

What I have seen in the past was a Pi with a GPS dongle on it and an RTC. On boot, the pi ran a python script that read the time form the GPS dongle and set the time of the RTC form that. Any desired frequent updates were implemented by the same script that just kept running in the backgound. It read a file that had an integer in it. That integer represented the number of seconds between updates of the RTC, so there was no need to reboot for a change in the update interval. Accuracy was acceptable for that particular user's needs.

CaptainMidnight
Posts: 347
Joined: Sun Nov 03, 2019 4:32 pm

Re: Chrony not updating from GPS

Mon Aug 01, 2022 6:27 am

Hi @abishur from your post I'm not sure what gps module you are using - is it a HAT?

Just for reference one of the time server builds we use, it's built around the Pi4 and the Uputronics GPS RTC HAT https://store.uputronics.com/index.php? ... duct_id=81

For comparison with your config, we don't use chrony but ntp instead - no real reason, just at the time we had more experience with ntp.

For reference and probably more info than you wanted: -

Prep mode of ttyAMA0 so it is readable by NTP

Code: Select all

	sudo nano /etc/udev/rules.d/80-gps-to-ntp.rules
	# Change MODE of ttyAMA0 so it is readable by NTP and provide
	# a symlink to /dev/gps0 
	KERNEL=="ttyAMA0", SUBSYSTEM=="tty", DRIVER=="", SYMLINK+="gps0", MODE="0666" 
	# Symlink /dev/pps0 to /dev/gpspps0 
	KERNEL=="pps0", SUBSYSTEM=="pps", DRIVER=="", SYMLINK+="gpspps0", MODE="0666"


Install GPSD + tools and disable or enable system service

Code: Select all

	sudo apt install gpsd gpsd-clients
	sudo systemctl stop gpsd.socket
	sudo systemctl disable gpsd.socket
	sudo systemctl enable gpsd.socket
	sudo systemctl start gpsd.socket
	
	sudo systemctl enable gpsd
	systemctl is-enabled --quiet gpsd && echo "Enabled" || echo "Disabled"
	sudo systemctl unmask gpsd	

Adjust the default gpsd

Code: Select all

	sudo nano /etc/default/gpsd
	
	START_DAEMON="true"
	USBAUTO="no"
	DEVICES="/dev/ttyAMA0"
	GPSD_OPTIONS="-n"
	GPSD_SOCKET="/var/run/gpsd.sock"

Adjust gpsd.service file

Code: Select all

	sudo nano /lib/systemd/system/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
 ExecStartPre=/bin/stty speed 115200 -F /dev/ttyAMA0
 ExecStart=/usr/sbin/gpsd -b $GPSD_OPTIONS $OPTIONS $DEVICES
 [Install]
 WantedBy=multi-user.target
 Also=gpsd.socket
	
	sudo systemctl daemon-reload

Restart GPSD service to use new settings

Code: Select all

	sudo service gpsd restart
	sudo service gpsd status
"Never get out of the boat."
Absolutely goddamn right!
Unless you were goin' all the way...

abishur
Posts: 4505
Joined: Thu Jul 28, 2011 4:10 am

Re: Chrony not updating from GPS

Tue Aug 02, 2022 3:39 pm

CaptainMidnight wrote:
Mon Aug 01, 2022 6:27 am
Hi @abishur from your post I'm not sure what gps module you are using - is it a HAT?

Just for reference one of the time server builds we use, it's built around the Pi4 and the Uputronics GPS RTC HAT https://store.uputronics.com/index.php? ... duct_id=81

For comparison with your config, we don't use chrony but ntp instead - no real reason, just at the time we had more experience with ntp.
I'm using a set up I made myself using an DS1307 for the RTC and a ZOE-M8Q GPS board I got from sparkfun... though I just realized the ZOE has an RTC so I'm not sure why I added the DS1307 on top of that 🤦‍♂️

I'm using Chrony for basically the same reason you are using NTP :lol:

Right after I posted I was able to figure out how to get things working, in my chrony file I had to add trust and prefer when configuring my GPS and PPS as sources. My system clock was so far out of true that my system decided the GPS source must be false. By telling it to trust the GPS and PPS sources it accepted their values and slowly started updating the system time to them.

For getting it to start on boot, I think the step I was missing was enabling the service. I had started it, but I hadn't explicitly enabled it. Following through your steps did the trick. In the end here are what my files looked like:

Code: Select all

/etc/default/gpsd

Code: Select all

# Devices gpsd should collect to at boot time.
START_DAEMON="true"
# They need to be read/writeable, either by user gpsd or the group dialout.
# Swap out line comments to used Serial Port 0 again
DEVICES="/dev/ttyS0 /dev/pps0"
#DEVICES=""
# Other options you want to pass to gpsd
GPSD_OPTIONS="-n"
# Automatically hot add/remove USB GPS devices via gpsdctl
USBAUTO="no"
GPSD_SOCKET="/var/run/gpsd.sock"

Code: Select all

/lib/systemd/system/gpsd.service

Code: Select all

[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
ExecStartPre=/bin/stty speed 230400 -F /dev/ttyS0
ExecStart=/usr/sbin/gpsd -b $GPSD_OPTIONS $OPTIONS $DEVICES
[Install]
WantedBy=multi-user.target
Also=gpsd.socket

Code: Select all

/etc/chrony/chrony.conf

Code: Select all

# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usable directives.
#Set up local NTP Server and allow devices from LAN to connect to it
local stratum 10
allow 192.168.24.0/23
# Include configuration files found in /etc/chrony/conf.d.
confdir /etc/chrony/conf.d
# Use PPS as primary source and get data from NMEA sentence from GPS unit
refclock PPS /dev/pps0 lock NMEA trust prefer
refclock SHM 0 offset 0.15 delay 0.2 refid NMEA trust prefer
# Use time sources from DHCP.
sourcedir /run/chrony-dhcp
# Use NTP sources found in /etc/chrony/sources.d.
sourcedir /etc/chrony/sources.d
# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys
# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift
# Save NTS keys and cookies.
ntsdumpdir /var/lib/chrony
# Uncomment the following line to turn logging on.
#log tracking measurements statistics
# Log files location.
logdir /var/log/chrony
# Stop bad estimates upsetting machine clock.
maxupdateskew 100.0
# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync
# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 1 3
# Get TAI-UTC offset and leap seconds from the system tz database.
# This directive must be commented out when using time sources serving
# leap-smeared time.
leapsectz right/UTC
And then I did your set of commands

Code: Select all

	sudo apt install gpsd gpsd-clients
	sudo systemctl stop gpsd.socket
	sudo systemctl disable gpsd.socket
	sudo systemctl enable gpsd.socket
	sudo systemctl start gpsd.socket
	
	sudo systemctl enable gpsd
	systemctl is-enabled --quiet gpsd && echo "Enabled" || echo "Disabled"
	sudo systemctl unmask gpsd	
	sudo service gpsd restart
	sudo service gpsd status
Though obviously I also had to install chrony, which uninstalled ntp, and I had to do a couple extra steps to enable my RTC, maybe now that I've got it working I can take all these notes, start over from scratch and carefully document it.

CaptainMidnight
Posts: 347
Joined: Sun Nov 03, 2019 4:32 pm

Re: Chrony not updating from GPS

Tue Aug 02, 2022 6:25 pm

Ah great stuff, at least it's now working.

Yes 'trust' and 'prefer' are generally needs - oops missed spotting that in your config but in my defense I've not really config'd chrony before :oops:
"Never get out of the boat."
Absolutely goddamn right!
Unless you were goin' all the way...

5 posts • Page 1 of 1

Return to "General discussion"

AltStyle によって変換されたページ (->オリジナル) /