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 ?
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.
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
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.
from gps import *
print 'Set System Clock to GPS UTC time'
gpsd = gps(mode=WATCH_ENABLE)
print 'ERROR: No GPS Present, time not set!!'
#wait until the next GPSD time tick
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)
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.
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
Process: 2355 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS)
Main PID: 2361 (ntpd)
Tasks: 2 (limit: 4915)
`-2361 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 121:128
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?)
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.