# Setting up Chrony and NMEA for time clock

**URL:** <https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661>\
**Category:** Client Configuration and Development\
**Created:** [December 31, 2022, 2:10am UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661 "2022-12-31T02:10:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![FranceBB](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/francebb/32/1017_2.png) [@FranceBB](https://community.ntppool.org/u/FranceBB)\
**Post date:** [December 31, 2022, 2:10am UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/1 "2022-12-31T02:10:48Z")

</div>

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:

```auto
systemctl is-active gpsd
active

```

```auto
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:

```auto
# 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:

```auto
# 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:

```auto
#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?

 ![Screenshot from 2022-12-28 00-28-36](https://us1.discourse-cdn.com/flex016/uploads/ntppool/original/2X/c/c6db414baed3946ee166be94a51acdb3c4dccb18.png)

---

<div class="post-metadata">

**Author:** ![kenyon](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/kenyon/32/45_2.png) [@kenyon](https://community.ntppool.org/u/kenyon)\
**Post date:** [December 31, 2022, 7:48am UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/2 "2022-12-31T07:48:33Z")

</div>

Check for SELinux denials.

---

<div class="post-metadata">

**Author:** ![Bas](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/bas/32/465_2.png) [@Bas](https://community.ntppool.org/u/Bas)\
**Post date:** [December 31, 2022, 1:53pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/3 "2022-12-31T13:53:41Z")

</div>

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:

```auto
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:

```auto
#* 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.

---

<div class="post-metadata">

**Author:** ![FranceBB](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/francebb/32/1017_2.png) [@FranceBB](https://community.ntppool.org/u/FranceBB)\
**Post date:** [December 31, 2022, 4:22pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/4 "2022-12-31T16:22:52Z")

</div>

Well, SELinux is disabled, in fact:

```auto

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](https://forums.fedoraforum.org/showthread.php?329622-Setting-up-Chrony-and-NMEA-for-time-clock)

---

<div class="post-metadata">

**Author:** ![FranceBB](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/francebb/32/1017_2.png) [@FranceBB](https://community.ntppool.org/u/FranceBB)\
**Post date:** [December 31, 2022, 6:18pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/5 "2022-12-31T18:18:19Z")

</div>

![Screenshot from 2022-12-31 18-08-00](https://us1.discourse-cdn.com/flex016/uploads/ntppool/original/2X/9/997468539639ac997ce2b3772c8e70e0656deb93.png)

---

<div class="post-metadata">

**Author:** ![Bas](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/bas/32/465_2.png) [@Bas](https://community.ntppool.org/u/Bas)\
**Post date:** [December 31, 2022, 6:24pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/6 "2022-12-31T18:24:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![FranceBB](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/francebb/32/1017_2.png) [@FranceBB](https://community.ntppool.org/u/FranceBB)\
**Post date:** [January 1, 2023, 10:28pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/7 "2023-01-01T22:28:06Z")

</div>

Happy New Year!! 😃

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?

---

<div class="post-metadata">

**Author:** ![NTPman](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/ntpman/32/450_2.png) [@NTPman](https://community.ntppool.org/u/NTPman)\
**Post date:** [January 2, 2023, 7:56am UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/8 "2023-01-02T07:56:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mlichvar](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@mlichvar](https://community.ntppool.org/u/mlichvar)\
**Post date:** [January 2, 2023, 11:51am UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/9 "2023-01-02T11:51:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Bas](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/bas/32/465_2.png) [@Bas](https://community.ntppool.org/u/Bas)\
**Post date:** [January 4, 2023, 4:03pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/10 "2023-01-04T16:03:40Z")

</div>

Mine is started like this in the status:

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

```

But my port is different.

Some other info pages: [Troubleshooting GPSD](https://gpsd.gitlab.io/gpsd/troubleshooting.html)

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?

---

<div class="post-metadata">

**Author:** ![FranceBB](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/francebb/32/1017_2.png) [@FranceBB](https://community.ntppool.org/u/FranceBB)\
**Post date:** [January 5, 2023, 12:15pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/11 "2023-01-05T12:15:01Z")

</div>

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. 🙂  
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! 😉

---

<div class="post-metadata">

**Author:** ![Bas](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/bas/32/465_2.png) [@Bas](https://community.ntppool.org/u/Bas)\
**Post date:** [January 9, 2023, 4:51pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/12 "2023-01-09T16:51:43Z")

</div>

Seen it too…only now you mention it:

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

```

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

Mine shows exactly this:

```auto
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 😁

---

<div class="post-metadata">

**Author:** ![FranceBB](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/francebb/32/1017_2.png) [@FranceBB](https://community.ntppool.org/u/FranceBB)\
**Post date:** [January 9, 2023, 9:16pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/13 "2023-01-09T21:16:55Z")

</div>

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

![Screenshot from 2023-01-09 21-13-44](https://us1.discourse-cdn.com/flex016/uploads/ntppool/original/2X/9/9d20fbca6ab941a8e01c8e354e6d5b3a68052b8c.png)

---

<div class="post-metadata">

**Author:** ![FranceBB](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/francebb/32/1017_2.png) [@FranceBB](https://community.ntppool.org/u/FranceBB)\
**Post date:** [January 9, 2023, 9:17pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/14 "2023-01-09T21:17:41Z")

</div>

![Screenshot from 2023-01-09 21-14-08](https://us1.discourse-cdn.com/flex016/uploads/ntppool/original/2X/9/96406cee04e6d3740d8cfcf3a465411f05b6e2f7.png)

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

---

<div class="post-metadata">

**Author:** ![FranceBB](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/francebb/32/1017_2.png) [@FranceBB](https://community.ntppool.org/u/FranceBB)\
**Post date:** [January 9, 2023, 9:46pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/15 "2023-01-09T21:46:18Z")

</div>

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! 😃

![Screenshot from 2023-01-09 21-43-44](https://us1.discourse-cdn.com/flex016/uploads/ntppool/original/2X/e/e49189a10b5d0d15342cae04afad746006f17455.png)

---

<div class="post-metadata">

**Author:** ![Bas](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/bas/32/465_2.png) [@Bas](https://community.ntppool.org/u/Bas)\
**Post date:** [January 10, 2023, 1:17pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/16 "2023-01-10T13:17:15Z")

</div>

You’re welcome.

Happy to see it working. 👍

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.

---

<div class="post-metadata">

**Author:** ![FranceBB](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/francebb/32/1017_2.png) [@FranceBB](https://community.ntppool.org/u/FranceBB)\
**Post date:** [January 10, 2023, 5:18pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/17 "2023-01-10T17:18:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marco.davids](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/marco.davids/32/767_2.png) [@marco.davids](https://community.ntppool.org/u/marco.davids)\
**Post date:** [January 11, 2023, 7:31am UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/18 "2023-01-11T07:31:44Z")

</div>

> [@Bas](#):
>
> stratum 0 or stratum 4 are not more or less accurate

According to RFC5905:

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

---

<div class="post-metadata">

**Author:** ![Bas](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/bas/32/465_2.png) [@Bas](https://community.ntppool.org/u/Bas)\
**Post date:** [January 11, 2023, 6:51pm UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/19 "2023-01-11T18:51:11Z")

</div>

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:

```auto
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

```

```auto
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? 😁

---

<div class="post-metadata">

**Author:** ![ebahapo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/ebahapo/32/1152_2.png) [@ebahapo](https://community.ntppool.org/u/ebahapo)\
**Post date:** [January 16, 2023, 5:50am UTC](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661/20 "2023-01-16T05:50:08Z")

</div>

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.

[Next page](https://community.ntppool.org/t/setting-up-chrony-and-nmea-for-time-clock/2661.md?page=2)
