×

INDI Library v2.0.7 is Released (01 Apr 2024)

Bi-monthly release with minor bug fixes and improvements

Synchronize the time of the RPI with the USB GPS

  • Posts: 335
  • Thank you received: 19
Hello,
I use an USB GPS in order to setup location and date/time into Kstars, on my Stellarmate system. But I would need to synchronise also the time/date system in order to correctly time-stamp the image files when recording. I try 2 process, one with ntp and an another with chrony. Both are unsuccessfull,  ntp definetively.

With chrony, the issue is, the daemon starts but stops after a time. I have to start it again with "sudo systemctl start chronyd". And after a while, the clock system is updated.

Has anyone been able to synchronize the system time with their USB GPS, automatically ?

Thank for your help
2 years 2 months ago #80231

Please Log in or Create an account to join the conversation.

  • Posts: 348
  • Thank you received: 69
Is this with Stellarmate appliance (which has a built in RTC), or with Stellarmate OS (which will only have a RTC if you have installed one on the GPIO)?

With a USB GPS you are not going to get a synchronisation that is entirely accurate (expect it to be around a second out), and if chronyd/ntpd has access to better time sources then it will label the GPS time as too out of date to sync to.

As I'm not using Stellarmate, I'm probably not going to be much help, but it is strange that you say ntp / chrony are not working, firstly, you should only run one or the other, you can't run both. I think they both try to bind to a port udp/123, so if one is running already then the other won't start properly.

You should probably try and find some relevant logs (in /var/log) which would tell you why something is not starting properly.
2 years 2 months ago #80234

Please Log in or Create an account to join the conversation.

  • Posts: 300
  • Thank you received: 57
I use a GPS to time-sync my Pi at a mountain cabin that is completely off-grid and has no internet connectivity at all. It works extremely well, but I use a GPS "hat" on a dedicated Pi rather than a USB dongle.

My system uses chrony for time sync and then shares the "network" time with all other devices in and around the cabin via wifi.

You need two pieces of software to build a pi-based timeserver: gpsd and chrony

I found the following articles very helpful in setting this up:
www.liquidweb.com/kb/how-to-install-and-configure-chrony/
opensource.com/article/18/12/manage-ntp-chrony
blogging.dragon.org.uk/using-chrony-on-ubuntu-18-04/

I have found that there is absolutely no advantage to all this if you have internet connectivity. Internet timeservers are just as good as GPS and FAR less hassle!
Last edit: 2 years 2 months ago by Scott Denning.
2 years 2 months ago #80244

Please Log in or Create an account to join the conversation.

  • Posts: 111
  • Thank you received: 41
 

File Attachment:

File Name: gpstime_py.txt
File Size:1 KB
Another option besides chrony etc... is to use e.g. the following python script (see attachment: gpstime_py.txt) which fetches the time/date from GPS and set it
simply with a "sudo date" command.

#!/usr/bin/python

import os
import sys
import time
from gps import *

print 'Set System Clock to GPS UTC time'

try:
  gpsd = gps(mode=WATCH_ENABLE)
except:
  print 'ERROR: No GPS Present, time not set!!'
  sys.exit()

while True:
  #wait until the next GPSD time tick
  gpsd.next()
  if gpsd.utc != None and gpsd.utc != '':
    #gpsd.utc is formatted like"2015-04-01T17:32:04.000Z"
    #convert it to a form the date -u command will accept: "20140401 17:32:04"
    #use python slice notation [start:end] (where end desired end char + 1)
    #   gpsd.utc[0:4] is "2015"
    #   gpsd.utc[5:7] is "04"
    #   gpsd.utc[8:10] is "01"
    gpsutc = gpsd.utc[0:4] + gpsd.utc[5:7] + gpsd.utc[8:10] + ' ' + gpsd.utc[11:19]
    os.system('sudo date -u --set="%s"' % gpsutc)
    sys.exit()



 
Last edit: 2 years 2 months ago by Thomas Stibor.
2 years 2 months ago #80253
Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 12
  • Thank you received: 0
I can't comment regarding Stellarmate, but I do have an RPi system with a USB GPS (Ublox 7) that I have working for location and time source within the accuracy I want.

The best I have configured this so far (spent a while on this...) is to have the gpsd.socket service active - but do not start the gpsd daemon and own the GPS device, if I do that, then my indi_gpsd driver won't seem to work.  /etc/defaults/gpsd conf file is relevant here.  I have configured NTP to use the time that gpsd dumps to shared memory (I don't have PPS available) as its time source.  This works to set the system time on the RPi even without battery backup/RTC, though you also need to configure NTP to have a large enough fudge factor so that it will take the new time from the GPS.

If manually start 'gpsmon' or 'cgps', then the time dumps begin to appear in 'ntpshmmon' soon after.

I can use 'indiserver indi_gpsd' in this configuration.
Last edit: 2 years 2 months ago by Tim.
2 years 2 months ago #80258

Please Log in or Create an account to join the conversation.

  • Posts: 335
  • Thank you received: 19
The best result I obtain is with chrony, following this process: photobyte.org/raspberry-pi-stretch-gps-d...-chrony-timedatectl/
But after the boot, chronyd starts and stops some time after. So I have to restart the service to update after a while the system clock.
I use gpsd for my USB key GPS Ublock7 and it runs well for ages.

I am going to explore the links you give me and the script. I did not get any result with ntp.

After installation of NTP, I modify the ntp.conf, with only these lines :
#GPS TIME SOURCE
server 127.127.28.0 minpoll 4 maxpoll 4
fudge 127.127.28.0 refid GPS

Next sudo service ntp restart.

ntpq -p but the line HMS has not a star and the reach column remains to 0 :

stellarmate@stellarmate:~ $ ntpq -p
remote refid st t when poll reach delay offset jitter
=======================================
SHM(0) .SHM. 0 l – 16 0 0.000 0.000 0.000

Systemctl status ntp gives this result:

ntp.service – Network Time Service
Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2022-02-03 23:12:13 CET; 10s ago
Docs: man:ntpd(8)
Process: 2355 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS)
Main PID: 2361 (ntpd)
Tasks: 2 (limit: 4915)
CGroup: /system.slice/ntp.service
`-2361 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 121:128

févr. 03 23:12:14 stellarmate ntpd[2361]: SHM: difference limit exceeded, delta=43276s
févr. 03 23:12:15 stellarmate ntpd[2361]: SHM: difference limit exceeded, delta=43276s
févr. 03 23:12:16 stellarmate ntpd[2361]: SHM: difference limit exceeded, delta=43276s
févr. 03 23:12:17 stellarmate ntpd[2361]: SHM: difference limit exceeded, delta=43276s
févr. 03 23:12:18 stellarmate ntpd[2361]: SHM: difference limit exceeded, delta=43276s
févr. 03 23:12:19 stellarmate ntpd[2361]: SHM: difference limit exceeded, delta=43276s
févr. 03 23:12:20 stellarmate ntpd[2361]: SHM: difference limit exceeded, delta=43276s
févr. 03 23:12:21 stellarmate ntpd[2361]: SHM: difference limit exceeded, delta=43276s
févr. 03 23:12:22 stellarmate ntpd[2361]: SHM: difference limit exceeded, delta=43276s
févr. 03 23:12:23 stellarmate ntpd[2361]: SHM: difference limit exceeded, delta=43276s

Thank you for your help.
2 years 2 months ago #80261

Please Log in or Create an account to join the conversation.

  • Posts: 348
  • Thank you received: 69
Try changing:
fudge 127.127.28.0 refid GPS

to 

fudge 127.127.28.0 flag1 1 refid GPS

flag1 enables signal processing of implicitly, regardless how out of date from system time it is.
2 years 2 months ago #80262

Please Log in or Create an account to join the conversation.

  • Posts: 12
  • Thank you received: 0
I didn't try with chrony.  Hopefully this helps if you try NTP...

My ntp.conf includes:

# Server from shared memory provided by gpsd
server 127.127.28.0 minpoll 4 maxpoll 4 prefer
fudge 127.127.28.0 refid GPS stratum 4
fudge 127.127.28.0 flag1 1

The flag1 parameter is to overcome the panic if the time is too far out of sync.

As mentioned above, the NTP shared memory only starts to get time from my GPS device after I wake it up with a client software such as gpsmon or cgps.  Otherwise, the system will sit there with no time source.  Starting gpsd in daemon mode fixes this, however, my indiserver indi_gpsd doesn't work then (if I could specify the indi_gpsd to connect to the network socket, rather than try to own the USB device, maybe that would work?)

Hope that helps.
2 years 2 months ago #80264

Please Log in or Create an account to join the conversation.

  • Posts: 335
  • Thank you received: 19
I'll try it Tim. Thanks
2 years 2 months ago #80268

Please Log in or Create an account to join the conversation.

  • Posts: 335
  • Thank you received: 19
Hi,

I try to modif the ntp.conf unsuccessfull. The script of Thomas is a perfect solution. I add a line into /etc/xdg/lxsession/LXDE-pi/autostart (sh /home/stellarmate/Update_Time.sh) and the script is automatically executed at the boot. Thank so much to all the helper.
2 years 2 months ago #80310

Please Log in or Create an account to join the conversation.

Time to create page: 1.185 seconds