×

INDI Library v2.0.6 is Released (02 Feb 2024)

Bi-monthly release with minor bug fixes and improvements

Script to set system date from GPS

  • Posts: 294
  • Thank you received: 54
For those who may find this useful, I have adapted/written a short script that reads from 'gpsd' and sets the computer system date. If you don't have an RTC on your computer (Rasp Pi, Odroid, etc...) or access to a network and/or 'ntpd' (remote nomad operation), the script is useful to set the correct date and time for kstars. Normally the script should be started at boot time, after 'gpsd' is started but I am not sure where to put it (rc.local or other startup scripts).

It can be run manually using 'sudo' ( sudo /file/path/gps_set_date ) but making it automatic would be the best. Furthermore, as I haven't been writting scripts in a long long time, so improvements are welcome, and consideration for the timezone may be needed. See below for the script which works on my Odroid XU4Q running Ubuntu Mate 18.04 LTS, KStars 2.9.8, Ekos and INDI.

gps_set_date:

#!/bin/bash

if [ ! -e "/dev/gps0" ]
then
exit
else
GPSDATE=""

until [ "$GPSDATE" != "" ]; do
GPSDATE=`gpspipe -n 10 -w | grep TPV | grep -e '"mode":[23]' | grep '"time":' | sed -r 's/.*"time":"([^"]*)".*/\1/' | tail -1`
done

date --utc -s "$GPSDATE"
fi
The following user(s) said Thank You: Picard, Stephen Wong
Last edit: 5 years 3 months ago by Gilles Gagnon.
5 years 3 months ago #32659

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

  • Posts: 2247
  • Thank you received: 223
Thanks for the script, I do not have a GPS but I'm sure this will be useful for someone.
As for GPS, what are the benefits for a fixed observatory?
5 years 3 months ago #32662

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

  • Posts: 1067
  • Thank you received: 140
Am I right in thinking that without GPS the time on the rpi doesn't really matter if just controlling remotely with another machine as kstars runs on that and has internet connection to update..
5 years 3 months ago #32670

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

  • Posts: 294
  • Thank you received: 54
GPS may not be as relevant for fixed installation, as you set your location once and you're done, but it may come handy for those who observe/image on-the-go, at different locations and without internet access.

As far as using the script to set the system time; as per the INDI configuration panel, KStars can get the date/time and position info from gpsd but from what I found out, only the position is passed correctly. The time is taken from the system time which is not correct if it's not set via a real time clock and don't have access to the Internet for ntpd.

BTW, I found the series of posts about your remote pico observatory. Great work and it gives me ideas on how to build one for my installation.
5 years 3 months ago #32678

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

  • Posts: 294
  • Thank you received: 54
I think you are correct in your assumption. If KStars is running on a machine connected to the Internet, that machine will have correct time and position, and will likely pass the information to the rpi but I haven't tested this configuration and as such can't be certain.

My solution is meant for people who observe/image on the go without access to the Internet for current time and position information. If your position is fixed, there is not much use for the script.
The following user(s) said Thank You: AstroNerd
5 years 3 months ago #32679

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

  • Posts: 125
  • Thank you received: 24
You should check this which uses phone gps - indilib.org/devices/auxiliary/gps-nmea.html

Following will set time from gps.

sudo setcap cap_sys_time=ep /bin/date
5 years 3 months ago #32688

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

  • Posts: 294
  • Thank you received: 54
Thanks for this info. This GPS NMEA solution is simpler than the GPSD one, plus it frees a port on my USB hub and there's one less cable in the way. Great!
5 years 3 months ago #32713

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

Time to create page: 0.345 seconds