What's new

ntpmerlin / chrony with GPS

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

morphine

New Around Here
Hi,

After a bit of hassle, I've managed to get ntpmerlin and chrony to be GPS-conditioned, so my router is now a stratum 1 ntp-server with millisecond accuracy. :)
No need for a separate NTP-server, unless you want to use PPS.
The guides I've found have been conflicting, so I thought I would share my setup here to give something back to the community.

Hardware:
RT-AC86u
Quescan GPS, https://www.aliexpress.com/item/1005005133580325.html

Install ntpmerlin and gpsd (opkg install gpsd).
Your GPS will appear as a terminal, mine was at TTYACM0.
ls /dev/tty*
There shouldn't be too many of them, and ttyS0 and S1 are the router's.

Gpsd settings:
Since we are not interested in navigation (I presume your router is not travelling), we can use the -r flag, and get time even if we have less-than-ideal reception.
-r, --badtime
Use GPS time even with no current fix. Some GPSs have battery powered Real Time Clocks (RTC’s) built in, making them a valid time source even before a fix is acquired. This can be useful on a Raspberry Pi, or other device that has no battery powered RTC, and thus has no valid time at startup. Use with caution.
We also want to poll the GPS continuously for timekeeping, so we use -n:
-n, --nowait
Don’t wait for a client to connect before polling whatever GPS is associated with it. Some RS232 GPSes wait in a standby mode (drawing less power) when the host machine is not asserting DTR, and some cellphone and handheld embedded GPSes have similar behaviors. Accordingly, waiting for a watch request to open the device may save battery power. (This capability is rare in consumer-grade devices). You should use this option if you plan to use gpsd to provide reference clock information to ntpd or chronyd. This option will also enable clients to see data from the receiver sooner on connection.
So our gpsd command looks like this:
gpsd /dev/ttyACM0 -nr
To check if it is working, and that you have the correct device, you can cat /dev/ttyACM0.

Chrony settings:
Add the following to your chrony.conf (mine is at /jffs/addons/ntpmerlin.d/chrony.conf):
refclock SHM 0 refid GPS poll 4 precision 1e-3 offset 0.128

Running:
Counterintuitively, gpsd needs to start AFTER chrony. This caused me a lot of headscratching until I rtfm.
killall -9 gpsd chronyd
(start chrony, either manually or via ntpmerlin)
sleep 2
gpsd /dev/ttyACM0 -nr
 
Last edited:
This is not a new idea - its actually where ntpMerlin evolved from, an earlier version that some hacked to use GPS...I seem to recall someone was using it on a boat.
I've an old Garmin GPS from Blackberry times. I've often wondered if it would work.
(Good lord, I've been around here for a long time...)
 
This is not a new idea - its actually where ntpMerlin evolved from, an earlier version that some hacked to use GPS...I seem to recall someone was using it on a boat.
I've an old Garmin GPS from Blackberry times. I've often wondered if it would work.
(Good lord, I've been around here for a long time...)
As long as it will constantly stream the GPS data over USB - should work fine. Gpsd is pretty clever ;-)

I did once connect a GPS module to my older router. As @morphine explained, use entware to load gpsd, finangle the USB drivers to read the data and voila, very accurate NTP time. Trouble was that the router was not near a window - and my GPS reception was a bit poor.
So, being bored and wanting a new project, recommisioned a Raspberry Pi (Pi 3) with a uBlox module using Serial I/O and PPS, added a low cost external antenna - wow, true Stratum 1.
 
What problem is this solution solving?
 
I don't think it's solving a problem per se...

It's more that some folks like to tinker about, and NTP is fairly low-risk, and hey, why not?
Yes, no problems - the built in ntpd is ok, the ntpMerlin chrony even better.

But, it is a fun exercise and nice to see ntpMerlin graphs at uSec precision.
And being a good open source proponent, I even had the Rpi ntp server in pool.ntp.org
At least until I moved last year and the parts are in a box somewhere…
 
Yes, no problems - the built in ntpd is ok, the ntpMerlin chrony even better.

But, it is a fun exercise and nice to see ntpMerlin graphs at uSec precision.

I designed and built out a PiHat with a ublox GPS module and a high-end VCTCXO - Nice part there is that we also provided hardware PPS support - performance was comparable to a bench reference - I made 8 of them for a project I was working on at the time...

I might still have the HW bill of materials and gerbers.
 
Welcome @morphine.

Not sure why so much negativity, I personally think its awesome that you are willing to share your experience.

Two thumbs up!
 
This is not a new idea - its actually where ntpMerlin evolved from, an earlier version that some hacked to use GPS...I seem to recall someone was using it on a boat.
I've an old Garmin GPS from Blackberry times. I've often wondered if it would work.
(Good lord, I've been around here for a long time...)
I know, just wanted to do a brain dump to save someone else hours of troubleshooting. Like trying to use the unix socket in /opt/var/run/chrony.ttyACM0.sock caused gpsd to crash intermittently. :b
 
As long as it will constantly stream the GPS data over USB - should work fine. Gpsd is pretty clever ;-)

I did once connect a GPS module to my older router. As @morphine explained, use entware to load gpsd, finangle the USB drivers to read the data and voila, very accurate NTP time. Trouble was that the router was not near a window - and my GPS reception was a bit poor.
So, being bored and wanting a new project, recommisioned a Raspberry Pi (Pi 3) with a uBlox module using Serial I/O and PPS, added a low cost external antenna - wow, true Stratum 1.
yes - a uBlox device w/Serial stream and most importantly the PPS signal - been using it on a Pi for almost three years... great little hack...
 
I don't think it's solving a problem per se...

It's more that some folks like to tinker about, and NTP is fairly low-risk, and hey, why not?
Back in the day it was a matter of being able to say something to the effect of "my system clock references atomic clocks in outer SPACE, man. Look at me being all Han Solo"
 
As long as it will constantly stream the GPS data over USB - should work fine. Gpsd is pretty clever ;-)
but am I clever enough to make it all work as it is supposed to? lately, I'm pretty sure not.
but that's not going to stop me from digging it out on Sunday when I'll have some mental bandwidth to throw at it, if it's where I seem to remember putting it
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top