Set date time via kplex ?

Skip to first unread message

Bernard Mayer

Jul 10, 2020, 3:13:23 AM7/10/20
to kplex
Hello !
Howto set local system date and time from GPS sentence ?
Chrony ? (
other ?
Thanks by advance


Jul 10, 2020, 3:18:58 AM7/10/20
to kplex
Hi Bernard,

I use a python script via GPSD like

#!/usr/bin/env python3
from gps3 import gps3
import subprocess
import sys

gps_socket = gps3.GPSDSocket()
data_stream = gps3.DataStream()
gps_socket.connect(host=sys.argv[1], port=int(sys.argv[2]))'json')
for new_data in gps_socket:
    if new_data:
        if data_stream.TPV['time'] != "n/a":
            print('Time = ',data_stream.TPV['time'])
  ["sudo", "date","-s",data_stream.TPV['time']])



Keith Young

Jul 10, 2020, 1:39:36 PM7/10/20
to kplex
If you just want to roughly set the time (e.g. on system boot) gpsdate or a script like the one Nicholas suggested works, but if your gps unit doesn't have a battery to back up almanac data, be aware that it won't be aware of the leap seconds which offset GPS time from UTC until it has downloaded almanac data.

If you want to *maintain* time, ideally you want a gps receiver with a PPS ("Pulse per second") output.  It takes a while to transmit NMEA sentences over a serial link and time data received only via NMEA sentences is quite offset from the correct time (the adafruit ultimate gps I was experimenting with was about 0.5s offset) with significant jitter.  The trick is to use the NMEA data for "coarse" time and the PPS signal for more exact time.

There's lots of stuff to google on how to do this using gpsd, for example:

I have no experience of chrony but a couple of years ago I did implement a time server using an adafruit ultimate gps, kplex supplying the NMEA feed and kernel PPS consumed by ntpd (ie no gpsd).  Unfortunately I didn't write it up at the time but I will attempt to repeat the experiment in the coming month.  The "normal" (and better documented) way to do this though would be with gpsd (see link above).

Good luck!
Reply all
Reply to author
0 new messages