BlueWave Studio forum
Syncing time with USB GPS (ublox 7020) - Printable Version

+- BlueWave Studio forum (https://bluewavestudio.io/community)
+-- Forum: OpenAuto Pro (https://bluewavestudio.io/community/forum-86.html)
+--- Forum: Real Time Clock (RTC) (https://bluewavestudio.io/community/forum-82.html)
+--- Thread: Syncing time with USB GPS (ublox 7020) (/thread-3212.html)



Syncing time with USB GPS (ublox 7020) - DSdavidDS - 02-13-2022

I know this isn't exactly RTC but I belive it is a solid alternative for those who have a GPS module. A lot of these steps are from the original blog post on photobyte.org referenced below but condensed down exactly what I needed to do.

Prerequisite:
- USB GPS Module (mine was from Amazon)
- Open Auto Pro 5 (I used 14.0)
- gpsd (OAP came with 3.17)
- Access to pi's console. Most likely through SSH or keyboard.

Step 1.
Edit gpsd's configuration in /etc/default/gpsd. Not sure why but the line containing START_DAEMON="TRUE" needs to be commented out. I scoured the web for an explanation on why but I didn't find an answer. Maybe the OS just needs to update to the latest version of gpsd. Regardless, here are the lines your config should contain:

#START_DAEMON=”true”
USBAUTO=”true”
DEVICES=”/dev/ttyACM0″
GPSD_OPTIONS=”-n” 


Note: Your "Devices" option might not be /dev/ttyACM0. You can find what it is after you plug in the GPS module and run "dmesg" in console.

Step 2.
Install Chrony. This is the better NTP service that works with gpsd (default timedatectl does not).
$ sudo apt install -y chrony

Step 3.
Configure chrony to use the right gpsd interface (SHM0 in this case). Append "refclock SHM 0 offset 0.5 delay 0.2 refid " to the bottom of /etc/chrony/chrony.conf. 
$ echo "refclock SHM 0 offset 0.5 delay 0.2 refid NMEA" | sudo tee -a /etc/chrony/chrony.conf

Step 4.
Restart chrony and gpsd. Easiest way to do this is to restart the pi but you should be able to just restart the services
$ sudo systemcttl restart chrony
$ sudo systemcttl restart gpsd
OR 
$ sudo reboot

Step 5.
Check for a gps lock. Depending on your location and view with thet sky, it my take some time to get a fix. You can use gpsmon or cgps
$ cgps -s
OR 
$ gpsmon

Step 6. 
Verify chrony is using the correct GPSD interface. You should see "NMEA" on the list.
$ chronyc sources -v


References:
- Best reference google could find regarding the gpsd issue with a simple addition to chrony's config: https://photobyte.org/raspberry-pi-stretch-gps-dongle-as-a-time-source-with-chrony-timedatectl/
- Official gpsd instructions (more in-depth and complicated but good information): https://gpsd.gitlab.io/gpsd/gpsd-time-service-howto.html#_feeding_chrony_from_gpsd


RE: Syncing time with USB GPS (ublox 7020) - wkl3968 - 02-14-2022

thanks for the instructions. I'm still learning about RTC and I don't understand what is it for and what is the advantages for setting up RTC. can you anyone explain in simplest manner the benefit of RTC?


RE: Syncing time with USB GPS (ublox 7020) - DSdavidDS - 02-17-2022

(02-14-2022, 02:35 PM)wkl3968 Wrote: thanks for the instructions. I'm still learning about RTC and I don't understand what is it for and what is the advantages for setting up RTC. can you anyone explain in simplest manner the benefit of RTC?

After computer turns off, there is no way for it to know how much time has passed since it last turned on. One hardware way to approach is to add a "Real Time Clock" which is essentially a piece of hardware that holds just enough power (either a capacitor or a battery) to time how much time has passed since losing power. Once the computer boots up, it can see how much time passed and add the difference since it last booted.

My GPS approach is not RTC. Instead of dedicated hardware to time a clock, it is getting a GPS fix and getting time information from satelllites (in the same way a computer can get time information by connecting to the internet).