The Navigatrix has been updated. The new website can be found at

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Set system time from GPS

Joined: 04 Jan 2014, 03:19
Posts: 34
Surely there should be a simple way to set the system clock to GPS time soon after startup?

I found this but I thought other people might have already done it on Navigatrix. Maybe ntp is a bit over the top ... _with_gpsd

Right now the back up battery on my motherboard is not working so it is a pain to have to set time every time I start up the computer.

 Post subject: Re: Set system time from GPS

Joined: 04 Nov 2010, 20:51
Posts: 1062
Time is tough. Hardware clocks, system clocks, RTC (realtime clocks), UTC, and localtime.

Navigatrix uses the gpsd to set the time, or so I've been lead to believe all these years. I just don't know which time it is, or when it does it. It a problem with transparency, out of sight out of mind.

You might have read further down in the link, about using gpsd to feed ntpd timeserver magic, and if left alone it will.
When gpsd receives a sentence with a timestamp, it packages the received timestamp with current local time and sends it to a shared-memory segment with an ID known to ntpd, the network time synchronization daemon. If ntpd has been properly configured to receive this message, it will be used to correct the system clock.
As I understand it, the trouble comes with large time differences. The software become suspicious. Where have you been the last 8 years, 4 months, 23 days, 11 hours, 37 minutes 27 point 374321 seconds? This is not normal.

The software appraises the situation to see if it is, as the locals say, fair dinkum. Give reason, and some bona fides, the wild number isn't some 'wild number'. It takes time.

But who has time for that?

Software is also fun, and for those with no impulse control. Do it now. We want to install a Python3 gpsd client from the Pypi Python Cheeseshop
sudo -H pip3 install gps3
This also gives you some examples of other fun Python-GPS things you can use or improve. Read the docs. For a whooping good time read the code itself.

Next we. and I mean any hardy soul, can open a text editor
gksudo medit /usr/local/bin/
Enter something like
# coding=utf-8
"""hard system time changer.  Just brutal, but innocently brutal"""
import time
import subprocess
import sys
from gps3 import agps3 

gpsd_socket = agps3.GPSDSocket()
gpsd_socket.connect(host='localhost', port=2947)
data_stream = agps3.DataStream()

try:['/usr/bin/timedatectl', 'set-ntp', 'false'])  # Turn off the automagic time sync
    print('Turn off automagic time')
    for new_data in gpsd_socket:
        if new_data:
            if data_stream.time != 'n/a':
                #timetest = '2011-11-11T11:11:11.020Z'
                #hardtime, junk = timetest.replace('T', ' ').split('.')
                # uncomment the two lines prior and comment the one line following to change arbitrarily.
                hardtime, junk = data_stream.time.replace('T', ' ').split('.')
      ['/usr/bin/timedatectl', 'set-time', hardtime])
      ['/usr/bin/timedatectl', 'set-ntp', 'true'])  # Turn the automagic time sync back on
                print('Set time: ', hardtime)
                print('Turn automagic time back on')
                print('  Done, Now what?')
            print("No time for that....")
except KeyboardInterrupt:
    print('\nTerminated by user\nGood Bye.\n')
# End
If you make it executable
sudo chmod +x /usr/local/bin/
Then you can call it from the terminal
sudo /usr/local/bin/
This snippet of code
  • turns off the automatic time adjustment
  • grabs the first valid timestamp from the gps
  • changes the system time to that time
  • turns the automatic time fixer back on for fine adjustment
  • exits

See if that gets you by with UTC and all. If it does, then it can be put somewhere hands-free and automagical too.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

Search for:

Credits © 2010 - 2024