Black Lives Matter - Action and Equality. ... Adafruit is part of the Stop Hate for Profit campaign. Adafruit is open and shipping.
0

Raspberry Pi GPS Stratum 1 NTP Server
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Thu Mar 26, 2015 1:48 pm

The offset value from GPS got bigger and bigger from -0.075 to -1.719.

After a few minutes (~5-10) the GPS gets the the 'o' and got from -0.270 to 0.050

what does this mean?

Tobi2707
 
Posts: 87
Joined: Thu Mar 12, 2015 8:07 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Thu Mar 26, 2015 1:54 pm

That means it's working!!!

When the 'o' is present that means that ntp is using the pps signal and the gps output for time, You'll slowly see the offset and jitter drop to about +/- 0.005 - 0.015
That means that the system should be accurate to about 5 - 15 microseconds.

gtj
 
Posts: 109
Joined: Wed Feb 04, 2015 9:11 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Thu Mar 26, 2015 2:05 pm

HOHO I'm so happy right now:P

Does this also works after a reboot?:)
I think it took maybe 15 minutes to get an offset of 0.006 ms, that is the accuracy of the time right?

Tobi2707
 
Posts: 87
Joined: Thu Mar 12, 2015 8:07 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Thu Mar 26, 2015 2:10 pm

Yes, it should work fine after a reboot. Correct on the offset. The GPS can theoretically provide an accuracy of 10 ns but there is always a tiny delay between the GPS unit and the processor and the system clock will drift slightly between updates. Over time, ntpd can adjust for some of that. 0.006 ms is pretty good.

gtj
 
Posts: 109
Joined: Wed Feb 04, 2015 9:11 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Thu Mar 26, 2015 2:15 pm

Oh i think 0.005 ms are good enough for me:)

Are there any options to get this fix faster?

How many sentences from NMEA are enabled?

Tobi2707
 
Posts: 87
Joined: Thu Mar 12, 2015 8:07 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Thu Mar 26, 2015 3:11 pm

Tobi2707 wrote:Oh i think 0.005 ms are good enough for me:)

Are there any options to get this fix faster?

How many sentences from NMEA are enabled?


There are 2 parts to this... The time it takes the GPS unit to get a fix and the time it takes ntpd to lock the system to the pps signal.

If you have the battery installed on the gps hat and you don't power off the pi for more that a day or so, the GPS should get a fix within a few seconds of powering on. When the GPS has a fix, the red LED will flash once every 15 seconds instead of once every second. To make this more reliable, you may want to read the README at the site you got the gps-tools from. Basically, every week or so, you want to stop ntpd and run 'gpsinit -s 115200 -f /etc/gpsinit_epoload.conf /dev/ttyAMA0' This will keep the GPS unit loaded with satellite position data and should speed up fixes from power on state.

There's one thing you can do to speed up ntpd... Since the Pi doesn't have a built in clock, it has no idea what the time is until ntpd starts and gets a lock. You can speed that up by installing the ntpdate package with 'apt-get-install ntpdate'. Then remove the 'noselect' from the 'server 0.debian.pool.ntp.org iburst' line in ntp.conf. Now when you reboot, the system will automatically get the time from the remote server to initially set the clock, then use ntpd to keep it synced with the local gps, using the pool server as a backup. You should now see a '+' next to the pool server in ntpq.

The gpsinit_time.conf file enables only 3 sentences: GPGLL, GPRMC, and GPZDA. For timekeeping, that's all that's needed.

gtj
 
Posts: 109
Joined: Wed Feb 04, 2015 9:11 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Thu Mar 26, 2015 3:28 pm

I think that is all enough, when i used more than one Pis with this config they must have almost the equal timestamp (+-10us), that is enough for my uses:)

Can i make a backup from the SD Card and save it so to other cards?

Do you have something to "record" the offset? to make a graph or something like that, because now i have to run ntpq -pn in several intervals and write it down:D

Have you interest in staying in contact (e.g. email)? It would be nice, maybe for other interesting projects and for further questions:)

Tobi2707
 
Posts: 87
Joined: Thu Mar 12, 2015 8:07 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Thu Mar 26, 2015 4:02 pm

Tobi2707 wrote:I think that is all enough, when i used more than one Pis with this config they must have almost the equal timestamp (+-10us), that is enough for my uses:)

Can i make a backup from the SD Card and save it so to other cards?


Yep, you can make a backup of the SD card. Once you back it up, make sure you change the hostname before using it in another device.

Tobi2707 wrote:Do you have something to "record" the offset? to make a graph or something like that, because now i have to run ntpq -pn in several intervals and write it down:D


I don't have anything to record but ntp does. Edit ntp.conf and uncomment the 'statsdir' line and save. Then go to /var/log and so 'sudo mkdir ntpstats' and 'sudo chown ntp:ntp ntpstats' now restart ntp. You'll have to do some research on how to interpret the files.

Tobi2707 wrote:Have you interest in staying in contact (e.g. email)? It would be nice, maybe for other interesting projects and for further questions:)


Sure, See the attachment... I'm going to delete it in a few hours. :)
Last edited by gtj on Thu Mar 26, 2015 4:09 pm, edited 1 time in total.

gtj
 
Posts: 109
Joined: Wed Feb 04, 2015 9:11 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Thu Mar 26, 2015 4:06 pm

how to change the hostname? do you mean the ip?
Okay i downloaded the zip file, you can delete it:)

Tobi2707
 
Posts: 87
Joined: Thu Mar 12, 2015 8:07 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Thu Mar 26, 2015 4:11 pm

Tobi2707 wrote:how to change the hostname? do you mean the ip?
Okay i downloaded the zip file, you can delete it:)


Edit /etc/hostname and set the host name to something different than the original otherwise the new Pi will come up with the same name as the original. If you're using static ip addresses, then change that as well.

gtj
 
Posts: 109
Joined: Wed Feb 04, 2015 9:11 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Thu Mar 26, 2015 5:02 pm

So the hostname isn't the ip address.
what is the hostname used for?
here it is "raspberrypi"

Tobi2707
 
Posts: 87
Joined: Thu Mar 12, 2015 8:07 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by stan_qaz on Sat Mar 28, 2015 4:26 am

First a big thanks to the folks in this topic, I'd have spend a lot of hours figuring this out myself, actually I'd have probably skipped doing the whole project since much of this is over my head.

I just got my GPS hat and put it on an old original Pi B that I modified so it would fit by removing the video out jack from the Pi.

I think I managed to slog my way through all the instructions here and have part of the system working like Tobi2707 shows in his post:

viewtopic.php?f=50&t=70133&start=75#p359930

Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ sudo ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 127.127.20.0    .GPS0.           1 l   6h    8    0    0.000    0.000   0.004
 129.70.132.37   129.70.130.70    2 u    1   64    1   28.380    1.400   0.092


My output:
Code: Select all | TOGGLE FULL SIZE
pi@pi-v1 /var/log $ sudo ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 127.127.20.0    .GPS0.           1 l  925    8    0    0.000    0.033   0.000
*129.250.35.251  77.55.181.184    2 u   74  128  377   28.409    1.159   1.282


So the GPS0 seems to be good but I'm not seeing a line for the PPS like gtj is in his post here:

viewtopic.php?f=50&t=70133&start=60#p359668

Code: Select all | TOGGLE FULL SIZE
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
oGPS_NMEA(0)     .GPS0.           1 l    1    8  377    0.000    0.001   0.004
 xx.xx.xx.xx     PPS(1)           2 u    2    8  377    0.398   -0.072   0.212


Any idea what I missed or got wrong?

stan_qaz
 
Posts: 46
Joined: Sat Mar 21, 2015 7:44 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Sat Mar 28, 2015 8:21 am

stan_qaz wrote:
My output:
Code: Select all | TOGGLE FULL SIZE
pi@pi-v1 /var/log $ sudo ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 127.127.20.0    .GPS0.           1 l  925    8    0    0.000    0.033   0.000
*129.250.35.251  77.55.181.184    2 u   74  128  377   28.409    1.159   1.282


So the GPS0 seems to be good but I'm not seeing a line for the PPS like gtj is in his post here:

Here the GPS/PPS is not used for the time( you can see this at the '*' which is on the pool server). How long after ntp restarting did you get this?
In my case it takes a few seconds till the GPS0 gets the '*' and then it takes around 5 minutes to get the 'o' which means the PPS is working.
You should only have one line for GPS/PSS...

Maybe you can post your ntp.conf, maybe something wrong with prefer and so.

But i think the real expert here is gtj ;)

Tobi2707
 
Posts: 87
Joined: Thu Mar 12, 2015 8:07 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by stan_qaz on Sat Mar 28, 2015 12:49 pm

I'm not sure what happened there, the GPS was being used for time before I started my post but by the time I did the copy paste it had dropped out. Looking at things this morning my Pi was using a pool server for time and the GPS values looked odd with the "when" value steadily rising.

I did another ntpq this morning and saw the when showing 8h, no clue why so I restarted ntpd and got the next two ntpq results, it took less than 2 minutes to get the "o" back in the second one

Code: Select all | TOGGLE FULL SIZE
pi@pi-v1 /var/log $ date
Sat Mar 28 16:05:59 UTC 2015

pi@pi-v1 /var/log $ sudo ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 127.127.20.0    .GPS0.           1 l   8h    8    0    0.000    0.033   0.000
*129.250.35.251  129.250.36.10    2 u  950 1024  377   31.901    2.952   3.585

pi@pi-v1 /var/log $ sudo service ntp restart
[ ok ] Stopping NTP server: ntpd.
[ ok ] Starting NTP server: ntpd.

pi@pi-v1 /var/log $ sudo ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 127.127.20.0    .GPS0.           1 l    -    8    0    0.000    0.000   0.000
*129.6.15.30     .ACTS.           1 u    -   64    1   85.250    0.002   0.199

pi@pi-v1 /var/log $ sudo ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
o127.127.20.0    .GPS0.           1 l    5    8    3    0.000   -0.986   0.143
+129.6.15.30     .ACTS.           1 u   12   64    1   84.589   -0.143   0.343

pi@pi-v1 /var/log $ date
Sat Mar 28 16:08:54 UTC 2015


I think the syslog info looks fine:

Code: Select all | TOGGLE FULL SIZE
Mar 28 16:06:36 pi-v1 ntpd[2947]: ntpd 4.2.8p1@1.3265-o Sat Mar 28 06:39:38 UTC 2015 (1): Starting
Mar 28 16:06:36 pi-v1 ntpd[2947]: Command line: /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 102:104
Mar 28 16:06:36 pi-v1 ntpd[2950]: proto: precision = 3.000 usec (-18)
Mar 28 16:06:36 pi-v1 ntpd[2950]: Listen and drop on 0 v4wildcard 0.0.0.0:123
Mar 28 16:06:36 pi-v1 ntpd[2950]: Listen normally on 1 lo 127.0.0.1:123
Mar 28 16:06:36 pi-v1 ntpd[2950]: Listen normally on 2 eth0 172.16.0.40:123
Mar 28 16:06:36 pi-v1 ntpd[2950]: Listening on routing socket on fd #19 for interface updates
Mar 28 16:06:36 pi-v1 ntpd[2950]: restrict 0.0.0.0: KOD does nothing without LIMITED.
Mar 28 16:06:36 pi-v1 ntpd[2950]: restrict ::: KOD does nothing without LIMITED.
Mar 28 16:06:36 pi-v1 ntpd[2950]: restrict: ignoring line 41, mask '::' unusable.


As does the message log:

Code: Select all | TOGGLE FULL SIZE
Mar 28 07:26:30 pi-v1 kernel: [    5.418552] pps_core: LinuxPPS API ver. 1 registered
Mar 28 07:26:30 pi-v1 kernel: [    5.526423] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
Mar 28 07:26:30 pi-v1 kernel: [    5.657237] pps pps0: new PPS source pps.-1
Mar 28 07:26:30 pi-v1 kernel: [    5.769686] pps pps0: Registered IRQ 398 as PPS source


My /etc/ntp.conf which I believe is the one being used from looking at the logged command line above:

Code: Select all | TOGGLE FULL SIZE
Mar 28 16:06:36 pi-v1 ntpd[2947]: Command line: /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 102:104


Code: Select all | TOGGLE FULL SIZE
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

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

# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example

# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
server 0.debian.pool.ntp.org iburst
#server 1.debian.pool.ntp.org iburst
#server 2.debian.pool.ntp.org iburst
#server 3.debian.pool.ntp.org iburst

server 127.127.20.0 mode 84 minpoll 3 iburst prefer
fudge 127.127.20.0 stratum 1 flag1 1 flag2 0 flag3 0 flag4 0 time1 0.0 time2 0.280 refid GPS0

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust

# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient


After the ntpd restart things are looking more normal with the when field changing but not steadily climbing:

Code: Select all | TOGGLE FULL SIZE
pi@pi-v1 /var/log $ sudo ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
o127.127.20.0    .GPS0.           1 l    3    8  377    0.000    0.018   0.006
+129.6.15.30     .ACTS.           1 u   39   64  377   83.997    0.874   0.453

pi@pi-v1 /var/log $ sudo ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
o127.127.20.0    .GPS0.           1 l    3    8  377    0.000    0.024   0.004
+129.6.15.30     .ACTS.           1 u   47   64  377   83.997    0.874   0.453

pi@pi-v1 /var/log $ sudo ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
o127.127.20.0    .GPS0.           1 l    5    8  377    0.000    0.005   0.004
*129.6.15.30     .ACTS.           1 u   24   64  377   84.951    1.238   0.926

pi@pi-v1 /var/log $ sudo ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
o127.127.20.0    .GPS0.           1 l    4    8  377    0.000    0.002   0.004
*129.6.15.30     .ACTS.           1 u   31   64  377   85.015    1.351   0.841


So aside from whatever glitched in my setup to cause ntpd to not be updating from the GPS I'm still a bit confused as to why gtj was seeing the pps line xx.xx.xx.xx PPS(1) in his ntpq and we aren't.

stan_qaz
 
Posts: 46
Joined: Sat Mar 21, 2015 7:44 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Sat Mar 28, 2015 1:14 pm

I have another PPS based time server which I use instead of the pool servers. That's what the PPS(1) line actually refers to. Not the Pi.

gtj
 
Posts: 109
Joined: Wed Feb 04, 2015 9:11 pm

Please be positive and constructive with your questions and comments.