×

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

Bi-monthly release with minor bug fixes and improvements

GPS date and time wrong

  • Posts: 96
  • Thank you received: 25
I wrote this little script that runs as part of my observatory start. It just checks that my position is reasonable, and runs that systemctl command if not. It would be easy to extend the check to restart gpsd if the reported date is too old while the gps thinks it has a fix.
#!/usr/bin/env python3
 
import subprocess
from json import loads
from time import sleep
 
 
def get_gps_data():
    cmd = ['gpspipe', '-w', '-n', '8']
    cmd_out = subprocess.run(cmd, text=True, capture_output=True).stdout
    rv = {}
    for x in cmd_out.splitlines():
        d = loads(x)
        k = d.pop('class', None)
        rv[k] = d
 
    return rv
 
def check_gps_confusion():
    gps = get_gps_data()
 
    #print(gps['TPV'])
    #print(gps['SKY'])
 
    have_fix = (gps['TPV']['mode'] in [2, 3] and gps['TPV']['status'] in [1,2,3,4])
    is_zero = (gps['TPV']['lat'] == 0.0 and  gps['TPV']['lon'] == 0.0 and gps['TPV']['altHAE'] == 0.0)
    have_sats = gps['SKY']['uSat'] > 5
 
    return have_sats and have_fix and is_zero
 
def main():
 
    if check_gps_confusion():
        print("Restarting GPSD")
        subprocess.run(['sudo', 'systemctl', 'restart','gpsd'])
        sleep(5)
        if check_gps_confusion():
            print("ERROR: GPSD did not reset")
        else:
            print("GPS OK")
    else:
        print("GPS OK")
 
 
if __name__ == '__main__':
    main()
The following user(s) said Thank You: Lars
1 year 4 months ago #87732

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

  • Posts: 12
  • Thank you received: 1

Replied by Georg Papp on topic GPS date and time wrong

I had a similar problem some time ago. the position was correct but the time was all wrong. I am using my Galaxy Tab as gps-source. It turned out that the problem was in the tablet itself, verified with a random positioning app. The error did not return after an update and reboot of the tablet.
1 year 4 months ago #87738

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

  • Posts: 145
  • Thank you received: 7

Replied by Lars on topic GPS date and time wrong

Hi,
Interesting with the script, maybe I don't need it for this particular problem if it not occur more often. But script can solve other things. Are there some examples somewhere to read about what it can be useful for ?

/Lars
1 year 4 months ago #87747

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

  • Posts: 96
  • Thank you received: 25


I have a couple of scripts to do stuff when starting and stopping an observing session. These scripts then call other scripts that do single things like checking the GPS, turning the camera cooler on or off, making the filter selection dialog shut up, parking or unparking the mount, ... In short: what do you do every time you're observing? What make you say "why do I have to do this every time? why can't the computer do it for me?" ... and then you put that in a script.
The following user(s) said Thank You: Lars
1 year 4 months ago #87756
Attachments:

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

  • Posts: 145
  • Thank you received: 7

Replied by Lars on topic GPS date and time wrong

I have now been out in the dark and use my equipment. It works better now and the GPS coordinates is transfered to EKOS/KStars. But still the time isn't corrected.

In the EKOS GPSD it looks like this:



The coordinates, time and date are correct. It transfer the coordinats to KStars, and the manual update also work.

But in KStars the time is correct in one place (the tablet clock) but not the other KStars' clock.



It's the clock at the green arrow that's wrong. It's say that the GPS place is used, but nothing if it also use the GPS date and time. Anyway everything looks to work now, only that the timestamps of the photos take the wrong time (the green arrow). I have another problem, when doing a meridian flip the plate solver can no longer find the object, could it too be related to this problem ?

How to fix that also the date and time is transfered to the KStars' time , is there a setup for that ?

/Lars
Last edit: 1 year 4 months ago by Lars.
1 year 4 months ago #88124
Attachments:

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

  • Posts: 145
  • Thank you received: 7

Replied by Lars on topic GPS date and time wrong

I must have done something wrong last time when the date / clock was wrong. Next time I used it and did the recommended restart of GPSD it worked. I hope it will do it all time now.

Thanks for all help !

/Lars
1 year 4 months ago #88220

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

  • Posts: 145
  • Thank you received: 7

Replied by Lars on topic GPS date and time wrong

Now when I understand a bit better about the problem. It looks that I need to type the command: sudo systemctl restart gpsd often when I start up the Raspberry.

If I want to do it very simple, I want a button on the screen that send this command:

sudo systemctl restart gpsd

To the command window, how I do that ?

Lars
1 year 4 months ago #88332

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

  • Posts: 145
  • Thank you received: 7

Replied by Lars on topic GPS date and time wrong

Now I have used my Raspberry a lot, most of the time it work perfectly.

But some problem left to solve if there is a solution for it:
When I'm out on the field without internet connection I get a problem. If the Raspberry hasn't been connected to internet during the day earlier I get the wrong date. The GPSD with a connected GPS dongle set the correct time and location but not the date. In the GPSD INDI window I see that it receives the correct date but it still doesn't correct the date. I have to correct the date with a sudo command. Maybe that's is the way it must be done because when reading in the setup I can enable the GPSD to force the other devices to use GPSD time and location. But there is nothing about the date.

Or is there a way to even let it correct the Raspberrys date ?

I can solve this if I during the day connect the Raspberry to internet before I go out to my dark places without internet. It looks if the Raspberry remember the last day it was up and running. Just have to remember to do this, or I can do a sudo command to set the date later.

My setup is documented here:
www.astrofriend.eu/astronomy/projects/project-heq5/07-heq5.html

/Lars
11 months 3 weeks ago #91744

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

  • Posts: 155
  • Thank you received: 12
Are you setting up ntp to get the date/time from your gps or just the indi drivers?

I setup a usb gps dongle recently (just because..) and configured ntp to get the time from gpsd by the shared memory driver. I also had the indi gpsd configured. Not sure if I really needed both for time but at least ntp would configure the system before I even got round to getting indi going.

In the end I decided that as my setup is static and my ipad feeds it gps and my internet connection time plus the cheap dongle I got didn’t lock onto the satellites very quickly, that there was no point in using it. ( I had my play time and decided the extra stress wasn’t worth it)
The following user(s) said Thank You: Lars
11 months 3 weeks ago #91747

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

  • Posts: 145
  • Thank you received: 7

Replied by Lars on topic GPS date and time wrong

Hi Nigel,
I configure it through INDI, but I did some commands in the comando window, set it to NEMA mode and pointed it to correct port, is that NTP or INDI ?

I have tested it more now. I can see that the time is corrected but normally not the date. But this evening it even corrected the date. When started the date was 6th but when GPS update it was set to 9th which is correct. I have no explanation why it sometimes only correct the time and sometimes both time and date. For me it takes about 5 minutes until it lock on satellites and get a stable location and time. It doesn't matter for me because it takes an hour to cool down the optics.

/Lars
11 months 2 weeks ago #91844

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

  • Posts: 155
  • Thank you received: 12
Hi Lars

I think you can ignore what I was saying as I’ve checked the astroberry source and it configures chrony (which it uses in place of ntp) to get the date/time from the gps :-

# Set chrony to update time from GPS
if [ -e /etc/chrony/chrony.conf ] && [ -z "$(grep 'refclock SHM 0 offset 0.5 delay 0.2 refid GPS' /etc/chrony/chrony.conf)" ]; then
echo "refclock SHM 0 offset 0.5 delay 0.2 refid GPS" >> /etc/chrony/chrony.conf
fi
11 months 2 weeks ago #91871

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

  • Posts: 145
  • Thank you received: 7

Replied by Lars on topic GPS date and time wrong

Hi Nigel,
Sorry to ask so much, but do you type that command once and after that it always use chrono ? I haven't got it to work yet.

And one more question, does it only set the KStars time and date or does it also correct the Raspberry clock time and date ?

I have now got the KSTars clock and time correct, but it's the offset from the Raspberry clock. Raspberrys clock still wrong and then also the time stamp of the photo files. I don't understand why KStars take the Raspberry clock and not it's own time which is correct.

/Lars
11 months 1 week ago #92273

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

Moderators: Radek Kaczorek
Time to create page: 0.596 seconds