Chrony not updating from GPS
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
and my chrony.conf file
Has anyone got this working on their system who can help me out?
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"
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
Re: Chrony not updating from GPS
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.
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
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
Install GPSD + tools and disable or enable system service
Adjust the default gpsd
Adjust gpsd.service file
Restart GPSD service to use new settings
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-reloadRestart 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...
Absolutely goddamn right!
Unless you were goin' all the way...
Re: Chrony not updating from GPS
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 🤦♂️CaptainMidnight wrote: ↑Mon Aug 01, 2022 6:27 amHi @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 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/gpsdCode: 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.serviceCode: 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.socketCode: Select all
/etc/chrony/chrony.confCode: 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
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- CaptainMidnight
- Posts: 347
- Joined: Sun Nov 03, 2019 4:32 pm
Re: Chrony not updating from GPS
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:
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...
Absolutely goddamn right!
Unless you were goin' all the way...
Return to "General discussion"
Jump to
- Community
- General discussion
- Announcements
- Other languages
- Deutsch
- Español
- Français
- Italiano
- Nederlands
- 日本語
- Polski
- Português
- Русский
- Türkçe
- User groups and events
- Raspberry Pi Official Magazine
- Using the Raspberry Pi
- Beginners
- Troubleshooting
- Advanced users
- Assistive technology and accessibility
- Education
- Picademy
- Teaching and learning resources
- Staffroom, classroom and projects
- Astro Pi
- Mathematica
- High Altitude Balloon
- Weather station
- Programming
- C/C++
- Java
- Python
- Scratch
- Other programming languages
- Windows 10 for IoT
- Wolfram Language
- Bare metal, Assembly language
- Graphics programming
- OpenGLES
- OpenVG
- OpenMAX
- General programming discussion
- Projects
- Networking and servers
- Automation, sensing and robotics
- Graphics, sound and multimedia
- Other projects
- Media centres
- Gaming
- AIY Projects
- Hardware and peripherals
- Camera board
- Compute Module
- Official Display
- HATs and other add-ons
- Device Tree
- Interfacing (DSI, CSI, I2C, etc.)
- Keyboard computers (400, 500, 500+)
- Raspberry Pi Pico
- General
- SDK
- MicroPython
- Other RP2040 boards
- Zephyr
- Rust
- AI Accelerator
- AI Camera - IMX500
- Hailo
- Software
- Raspberry Pi OS
- Raspberry Pi Connect
- Raspberry Pi Desktop for PC and Mac
- Beta testing
- Other
- Android
- Debian
- FreeBSD
- Gentoo
- Linux Kernel
- NetBSD
- openSUSE
- Plan 9
- Puppy
- Arch
- Pidora / Fedora
- RISCOS
- Ubuntu
- Ye Olde Pi Shoppe
- For sale
- Wanted
- Off topic
- Off topic discussion