Setting up Chrony and NMEA for time clock

Hi there,
I’m setting up my first weather station due to a university project and since it won’t always have reliable internet available (it’s gonna be at the top of a mountain in Italy with 2G at best) I’m gonna use a Glonass GPS U-blox 7 to get the NMEA time signal and keep the clock aligned.
The reasoning behind this is that satellites have 3 atomic clock each inside them (Stratum 0) and can be used as reference clocks to avoid having time to drift.
The computer will connect to them and will use them to become Stratum 1 and keep the time in sync without drifting.
Of course we had the choice to pick the Linux distro and I picked my beloved Fedora (it might become RHEL 8 in the future if we see any stability issue).
Anyway, I installed gpsd and gpsd-clients and make it start at boot time with:

systemctl enable gpsd

in fact:

systemctl is-active gpsd
active
systemctl status gpsd
● gpsd.service - GPS (Global Positioning System) Daemon
     Loaded: loaded (/usr/lib/systemd/system/gpsd.service; enabled; preset: disabled)
     Active: active (running) since Wed 2022-12-28 13:47:08 GMT; 2s ago
TriggeredBy: ● gpsd.socket
    Process: 11916 ExecStart=/usr/sbin/gpsd $GPSD_OPTIONS $OPTIONS $DEVICES (code=exited, status=0/SUCCESS)
   Main PID: 11918 (gpsd)
      Tasks: 1 (limit: 76422)
     Memory: 792.0K
        CPU: 4ms
     CGroup: /system.slice/gpsd.service
             └─11918 /usr/sbin/gpsd /dev/ttyACM0″ GPSD_OPTIONS=-n

Dec 28 13:47:08 router-localhost systemd[1]: Starting gpsd.service - GPS (Global Positioning System) Daemon...
Dec 28 13:47:08 router-localhost systemd[1]: Started gpsd.service - GPS (Global Positioning System) Daemon.

I even checked the gpsd configuration in /etc/sysconfig and set it to:

# Options for gpsd, including serial devices

START_DAEMON=”true”
USBAUTO="true"
DEVICES="/dev/ttyACM0″
GPSD_OPTIONS="-n"

and I also changed chronyd in /etc/ accordingly to make use of it:

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
pool 2.fedora.pool.ntp.org iburst
pool pool.ntp.org iburst
server time1.google.com
server time2.google.com
server time3.google.com
server time4.google.com

#Connect to GPS Atomic Clock
refclock SHM 0 offset 0.5 delay 0.2 refid NMEA

# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# Allow the system clock to be stepped in the first three updates
# if its offset is larger than 1 second.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).


# Enable hardware timestamping on all interfaces that support it.
hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# Allow NTP client access from local network.
#allow 192.168.0.0/16

# Serve time even if not synchronized to a time source.
#local stratum 10

# Specify file containing keys for NTP authentication.
keyfile /etc/chrony.keys

# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC

# Specify directory for log files.
logdir /var/log/chrony

# Select which information is logged.
#log measurements statistics tracking

note the important bit, namely:

#Connect to GPS Atomic Clock
refclock SHM 0 offset 0.5 delay 0.2 refid NMEA

when I check the satellites with xgps I can see satellites and with gpsd I can see the data, however chronyd doesn’t seem to like NMEA and it’s saying #? as if it’s not a source, in fact there’s no data from it.
Why?

Check for SELinux denials.

First, remove the Google pool servers, they should not be used.
Second, remove the delay in your GPS line, and simply call it GPS.

Typical line for USB GPS is this:

refclock SHM 0 refid GPS poll 4 precision 1e-3 offset 0.128

Because you delay it, it won’t be seleted over other internet-sources.
You can even poll it more often, like 2 instead of 4, you may get better time setting it at 2.

Output should look something like this:

#* GPS                           0   4   377    22  +65us[+41us] +/- 6us
^- nas-server.fritz.box          1   6   377    51  +4010us[-1011us] +/-  277us
^- ntp-main-1.oma.be             1   6   377     2  -2553us[-3244us] +/- 9090us
^- ntp0.nl.uu.net                1   6   377    10  -1427us[-2753us] +/-   11ms
^- ptbtime1.ptb.de               1   6   377    43  +1201us[-3175us] +/-   20ms

My numbers are not exactly that as I use PPS too, but it should select GPS after a couple of muinutes.

The precission is there to tell chronly it’s pretty well on time, as it may make mistakes without.

Goodluck,

Bas.

Well, SELinux is disabled, in fact:


sestatus
SELinux status:                 disabled

I changed chrony’s config to:

refclock SHM 0 refid GPS poll 2 precision 1e-3 offset 0.128

but I’m still getting the same error, I mean the source is marked as #? (i.e unreachable).
By the way, for reference, this is a continuation of this thread here: Setting up Chrony and NMEA for time clock

Did you try a reboot?
BTW, you should not run another program directly on the device, as it will hinder GPSD to take control.

Happy New Year!! :smiley:

Yes, I tried rebooting and nothing, still #?
I even tried not using xgps and cgps -s, but it didn’t change anything.
Speaking of which, if I can’t use xgps and cgps -s, how do I know that the GPS has actually got the timestamp? I mean, sure, I can see the green light blinking instead of a fixed red one, but can’t I use something through Fedora to actually check?

Happy New Year for you too, @FranceBB, and welcome to the community!

There seems to be some syntax error in the gpsd configuration file in /etc/sysconfig directory. (May be cut&paste issue from the documentation?) Please check that the double quotes are having the normal ASCII 042 octal code values, and not the fancy back double quotes with the higher values from UNICODE page.

Try running ntpshmmon from gpsd to confirm there are some measurements written to the memory segment. Then I’d suggest to stop the system chronyd service and run chronyd -d -d in terminal to get the debug output. There should be an error message if chronyd is receiving the measurements, but ignoring for some reason.

Mine is started like this in the status:

/usr/sbin/gpsd -n -b /dev/ttyUSB0

But my port is different.

Some other info pages: Troubleshooting GPSD

Did you set the speed of the Ublox too high? Typical is 4800 or 9600baud. When set too high often Chrony don’t read it.

Have you tried to reset the GPS to factory defaults?

Thanks for the additional tips.
Unfortunately the university is temporarily closed during the holidays, so I can’t test 'till Monday next week. I noticed the non ASCII quote and replaced them with real ASCII quotes “”, namely "" so hopefully it should work now.
About the speed of the Ublox, I didn’t actually set it anywhere, so I guess it’s defaulting it to something?
Anyway, I’ll test with the changes on Monday. :slight_smile:
Although I brought the ublox home with me (so it’s not at university and I could technically test it), my apartment block faces south, therefore it won’t be able to get a fix, which is why I gotta test it at university where I have the actually mini pc that will be deployed to the weather station and a south facing room from which the ublox can get the 2D and 3D fix.

I’ll let you know and… see you on Monday, I guess! :wink:

1 Like

Seen it too…only now you mention it:

/usr/sbin/gpsd /dev/ttyACM0″ GPSD_OPTIONS=-n

You have an " after the device, it may well be the problem.

Mine shows exactly this:

root@server:~# service gpsd status
● gpsd.service - GPS (Global Positioning System) Daemon
     Loaded: loaded (/etc/systemd/system/gpsd.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-11-10 15:07:12 CET; 1 months 29 days ago
TriggeredBy: ● gpsd.socket
   Main PID: 888 (gpsd)
      Tasks: 2 (limit: 9374)
     Memory: 1.7M
        CPU: 5h 3min 30.690s
     CGroup: /system.slice/gpsd.service
             └─888 /usr/sbin/gpsd -N -n -b /dev/ttyS0

Yours is passing parameters that should not be there :grin:

You nailed it, guys! It was because of the quotes!
It works!! :smiley:
Thank you so so so so much!
You have no idea how happy I am right now! :smiley:

Screenshot from 2023-01-09 21-13-44

1 Like

Screenshot from 2023-01-09 21-14-08

Stratum 1 :wink:
and it’s all thanks to you, guys!

The GPS is very accurate and spot on.
So much so that even now that I’m testing at university and I have an internet connection, it still goes for Stratum 0 as it’s more accurate, thus proving that it works correctly! :smiley:

Screenshot from 2023-01-09 21-43-44

You’re welcome.

Happy to see it working. :+1:

BTW, stratum 0 or stratum 4 are not more or less accurate, the time is passed from one to another.
The accuracy is the same.
It just means that your closer to the Atom-clock that is feeding your system with time.

In fact, your if your GPS is the only time-source, it means your server can be less accurate then getting time from multiple sources, as e.g. clouds, snow, reflections can make a GPS go jump on accuracy.
Therefor you need more sources to ensure your timeserver is as accurate as possible.

A GPS with PPS has less problems with this, but without PPS will jump a bit more.
When weather conditions go real bad, it can happen that your GPS won’t be selected as primary source, doesn’t happen often but I have seen it doing that.

Oh, I see! Interesting.
Well, I guess I’ll find out. :slight_smile:
Thank you again, guys.

According to RFC5905:

As the stratum number increases, its accuracy degrades depending on the particular network path and system clock stability.

Marco you are right when talking about 20 years back.
But then most NTP-servers depended on phone-calls and other stuff en depend a lot on the system-oscillator. (internal clock)

Today there is no problem to connect to multiple sources and correct every few seconds.
Also we have hardware time-stamping so corrections can be made.

The difference between Stratum 0, 1, 2, 3 etc won’t be that large to notice much of a difference.

Sure, when using 1 source alone can be a problem, but no one should do that these days.

Just look:

Stratum         : 1
Ref time (UTC)  : Wed Jan 11 18:29:01 2023
System time     : 0.000001498 seconds fast of NTP time
Last offset     : +0.000000740 seconds
RMS offset      : 0.000004086 seconds
Frequency       : 11.423 ppm fast
Residual freq   : +0.018 ppm
Skew            : 1.420 ppm
Root delay      : 0.000000001 seconds
Root dispersion : 0.000004641 seconds
Update interval : 1.0 seconds
Leap status     : Normal
Stratum         : 2
Ref time (UTC)  : Wed Jan 11 18:48:47 2023
System time     : 0.000000000 seconds fast of NTP time
Last offset     : -0.000001436 seconds
RMS offset      : 0.000237727 seconds
Frequency       : 12.194 ppm fast
Residual freq   : +0.030 ppm
Skew            : 1.226 ppm
Root delay      : 0.016264930 seconds
Root dispersion : 0.000411160 seconds
Update interval : 16.1 seconds
Leap status     : Normal

And your point is? :grin:

The ST2 server is a lower quality time source, with greater RMS offset and root delay and dispersion, key quality parameters, than the ST1 server.