User avatar
CopterRichie
Posts: 131
Joined: Tue Mar 26, 2013 3:14 am
Location: Los Angeles CA.

Updating Time Clock via GPS

Mon Sep 30, 2013 6:55 pm

Hello all,

I would like to set the Raspberry PI's time clock on start up or once the GPS has a lock because the application this will be used on will not have access to the internet.

Do anyone have a example program of how this could be done?

Thank you.


User avatar
CopterRichie
Posts: 131
Joined: Tue Mar 26, 2013 3:14 am
Location: Los Angeles CA.

Re: Updating Time Clock via GPS

Mon Sep 30, 2013 8:55 pm

Thank you!!!

aevertett
Posts: 1
Joined: Fri Jun 20, 2014 12:31 pm

Re: Updating Time Clock via GPS

Fri Jun 20, 2014 12:39 pm

It would be interesting to know how you have got on using the NTP daemon with the GPSd GPS parsing daemon. GPSD uses the NTP shared memory module to provide time stamps to NTP. However, I have had a few problems using the latest version on NTP (4.2.6) with the GPS daemon. It appears that NTP 4.2.4 works OK, but the later version 4.2.6 does not appear to communicate with GPSd. We use NTP and GPSd in some of our network timing products http://www.timetoolsglobal.com/informat ... tp-server/. Currently, we only offer NTP version 4.2.4. It would be interesting to hear from anyone else has found similar issues with NTP 4.2.6.

beampoweramp
Posts: 21
Joined: Fri Jan 05, 2018 10:05 pm

Re: Updating Time Clock via GPS

Fri Jan 19, 2018 6:09 pm

Can someone provide further guidelines to locking the Raspberry Pi clock to the GPS clock in the absence of an internet connection?
The link provided https://www.lammertbies.nl/comm/info/GPS-time.html has a lot of details on wiring up an external GPS receiver, but it's written for Centos.
I looked for a gpsd folder in /etc
I could not find one.

I ran [email protected]:/etc $ ls | grep gpsd
Nothing there.

Should I create a gpsd folder in /etc with the contents as described?
Where is gpsd getting its config information on the Raspberry Pi?
Does gpsd need to re-installed?

Also, what's a quick way to check if ntpd and gpsd daemons are running?

Maybe I should post a new question(s)?

gscassa
Posts: 2
Joined: Fri Feb 16, 2018 3:28 pm

Re: Updating Time Clock via GPS

Fri Feb 16, 2018 3:42 pm

/lib/systemd/system/gpsd.service
/etc/defaults/gpsd

gscassa
Posts: 2
Joined: Fri Feb 16, 2018 3:28 pm

Re: Updating Time Clock via GPS

Fri Feb 16, 2018 3:47 pm

# Supplemental:
##################################################################
#/lib/systemd/system/gpsd.service
#################################################################

[email protected]:/# cat /lib/systemd/system/gpsd.service
[Unit]
Description=GPS (Global Positioning System) Daemon
Requires=gpsd.socket
# Needed with chrony SOCK refclock
After=chronyd.service

[Service]
EnvironmentFile=-/etc/default/gpsd
#
# I hardcoded the values here.
ExecStart=/usr/sbin/gpsd -n -N -P /tmp/gpsd.pid -F /var/run/gpsd/gpsd.sock /dev/ttyUSB0

[Install]
Also=gpsd.socket

[email protected]:/# cat /etc/default/gpsd
# Default settings for the gpsd init script and the hotplug wrapper.

# Start the gpsd daemon automatically at boot time
START_DAEMON="true"

# Use USB hotplugging to add new USB devices automatically to the daemon
USBAUTO="true"

# Devices gpsd should collect to at boot time.
# They need to be read/writeable, either by user gpsd or the group dialout.
DEVICES=""

# Other options you want to pass to gpsd
GPSD_OPTIONS=""

##############################################################
# systemctl status gpsd ( you will want to do: `systemctl daemon-reload ; systemctl stop gpsd ; systemctl start gpsd` after
# any changes are made to the above files.)
##############################################################

[email protected]:/# systemctl status gpsd
● gpsd.service - GPS (Global Positioning System) Daemon
Loaded: loaded (/lib/systemd/system/gpsd.service; indirect; vendor preset: enabled)
Active: active (running) since Fri 2018-02-16 10:16:30 EST; 17min ago
Main PID: 3416 (gpsd)
CGroup: /system.slice/gpsd.service
└─3416 /usr/sbin/gpsd -n -N -P /tmp/gpsd.pid -F /var/run/gpsd/gpsd.sock /dev/ttyUSB0

Feb 16 10:16:30 pip0 systemd[1]: Started GPS (Global Positioning System) Daemon.

##############################################################
# NTP CONFIG FILE: /etc/ntp.conf
##############################################################

[email protected]:/# cat /etc/ntp.conf
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.

restrict default kod nomodify notrap nopeer
restrict -6 default kod nomodify notrap nopeer

# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Read the rough GPS time from device 127.127.28.0
# Read the accurate PPS time from device 127.127.28.1

server 127.127.28.0 minpoll 4 maxpoll 4
fudge 127.127.28.0 time1 0.535 refid GPS
server 127.127.28.1 minpoll 4 maxpoll 4 prefer
fudge 127.127.28.1 refid PPS

# Use servers from the ntp pool for the first synchronization,
# or as a backup if the GPS is disconnected

server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org

# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
driftfile /var/lib/ntp/drift

statsdir /var/log/ntp/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys

################################################################## NTP QUERY PEERS
#################################################################
[email protected]:/# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*SHM(0) .GPS. 0 l 15 16 377 0.000 24.513 68.413
SHM(1) .PPS. 0 l - 16 0 0.000 0.000 0.000
asa0 .INIT. 16 u - 512 0 0.000 0.000 0.000
+pacific.latt.ne 113.178.200.166 2 u 10 64 377 86.370 5.505 47.047
-clock.trit.net 192.12.19.20 2 u 15 64 377 79.310 -61.731 53.452
-linode227395.st 192.5.41.41 2 u 17 64 373 36.970 -60.699 67.414
+ec2-52-6-160-3. 130.207.244.240 2 u 14 64 377 17.199 -38.803 37.555
[email protected]:/#

### Hope this works for you.

beampoweramp
Posts: 21
Joined: Fri Jan 05, 2018 10:05 pm

Re: Updating Time Clock via GPS

Fri Mar 23, 2018 5:16 pm

Thank you for the reply.
I wound up trying the process described here:
https://github.com/beta-tester/RPi-GPS-PPS-StratumOne

this is what's in my gpsd.service file:

~ $ cat /lib/systemd/system/gpsd.service

Code: Select all

[Unit]
Description=GPS (Global Positioning System) Daemon
Requires=gpsd.socket
# Needed with chrony SOCK refclock
After=chronyd.service

[Service]
EnvironmentFile=-/etc/default/gpsd
ExecStart=/usr/sbin/gpsd -N $GPSD_OPTIONS $DEVICES

[Install]
Also=gpsd.socket
~ $ chronyc sources

Code: Select all

210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
#* PPS                           0   3   377    12   +188ns[ +257ns] +/-  248ns
#- PPSx                          0   3   377    12   +188ns[ +188ns] +/-  242ns
#- PPSy                          0   3   377     8   +435ns[ +435ns] +/-  242ns
#- NMEA                          0   3   377    12    +49ms[  +49ms] +/-  110ms
The nanosecond level specs look great, but I just don't have a warm fuzzy that the system clock is being updated in a timely manner.
Or if it is even possible to reliably synchronize multiple Raspberry Pi's.

I'll have to try your recommendations.

gordon77
Posts: 3370
Joined: Sun Aug 05, 2012 3:12 pm

Re: Updating Time Clock via GPS

Fri Mar 23, 2018 6:14 pm

beampoweramp wrote:
Fri Jan 19, 2018 6:09 pm
Can someone provide further guidelines to locking the Raspberry Pi clock to the GPS clock in the absence of an internet connection?
You could use a USB GPS and python...


viewtopic.php?f=32&t=108848&p=748408&hilit=gps#p748408

beampoweramp
Posts: 21
Joined: Fri Jan 05, 2018 10:05 pm

Re: Updating Time Clock via GPS

Tue Mar 27, 2018 1:47 am

I tried this.
Now I get a PolicyKit error.
What is PolicyKit?

Code: Select all

~$ systemctl daemon-reload
Failed to reload daemon: The name org.freedesktop.PolicyKit1 was not provided by any .service files

Return to “Python”

Who is online

Users browsing this forum: Bing [Bot] and 15 guests