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.

Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Thu Mar 12, 2015 8:11 am

Hey,
I'm using a Raspberry Pi B+ and the Adafruit Ultimate GPS HAT and I want to create a Stratum 1 NTP Server.
Is there a good and working tutorial how to do this?
What are the Steps with using GPS and PPS?

Thx
Tobi

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by adafruit_support_mike on Sat Mar 14, 2015 1:03 am


adafruit_support_mike
 
Posts: 55974
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Mon Mar 16, 2015 5:49 am

Have your already used the Pi als a Stratum 1 NTP Server?

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by adafruit_support_mike on Mon Mar 16, 2015 10:22 pm

Yes and no.

I've worked through the steps involved, but then disassembled the system when I needed to test the GPS module and RasPi in other ways. For a Stratum-1 server the operating history is as important as the hardware, and I didn't keep one running long enough to acquire a really good history.

adafruit_support_mike
 
Posts: 55974
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Tue Mar 17, 2015 3:32 am

Yes , your right, but at first i want it working :P
I was using this Howto :http://musingsfromthe8thfloor.com/2015/02/08/stratum-1-ntp-server-on-raspberry-pi/comment-page-1/#comment-28
but i think this is not really detailed despite they're using the original Adafruit Hardware and so the same equipment like me.
So today i will try to do the very detailed How-to on http://satsignale.eu.
Maybe you can tell me how to very/check if the GPS time is working with the PPS and thereby that i have a high accuracy?
Is it possible to work out a how-to together or at least to help me at some steps?

Thanks a lot, but i'm really despairing:D
Tobi

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Tue Mar 17, 2015 5:51 am

Now i tried it again and i get these numbers:

Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
-148.251.84.200  161.62.157.173   3 u   60   64   37  162.894  -849.17  28.747
+129.70.132.37   129.70.130.71    2 u   59   64   37  192.526  -829.17  53.682
+129.250.35.250  130.149.17.21    2 u   58   64   37   74.272  -775.89 102.457
+141.82.25.203   131.188.3.222    2 u  125   64   36   59.574  -766.10 116.720
 127.127.22.0    .PPS.            0 l    6   16  377    0.000  203.864   0.660
x127.127.28.0    .GPS.            0 l    5   16  377    0.000   48.271  92.572
*192.53.103.108  .PTB.            1 u   55   64   37   62.350  -767.58 104.679

What does this mean to me?

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Tue Mar 17, 2015 8:11 pm

Tobi2707 wrote:Now i tried it again and i get these numbers:

Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
-148.251.84.200  161.62.157.173   3 u   60   64   37  162.894  -849.17  28.747
+129.70.132.37   129.70.130.71    2 u   59   64   37  192.526  -829.17  53.682
+129.250.35.250  130.149.17.21    2 u   58   64   37   74.272  -775.89 102.457
+141.82.25.203   131.188.3.222    2 u  125   64   36   59.574  -766.10 116.720
 127.127.22.0    .PPS.            0 l    6   16  377    0.000  203.864   0.660
x127.127.28.0    .GPS.            0 l    5   16  377    0.000   48.271  92.572
*192.53.103.108  .PTB.            1 u   55   64   37   62.350  -767.58 104.679

What does this mean to me?


It means that .GPS. has been eliminated for any number of reasons and .PPS. is just not being used at all.

You really only need 1 entry in ntp.conf instead of 2. It should look something like...

Code: Select all | TOGGLE FULL SIZE
# 127.127.20.1: Use the NMEA driver on /dev/gps1 and /dev/gpspps1
# mode 88: speed 115200 and process the $GPZDA or $GPZDG sentences for time
# set the speed for your installation.
# prefer: use this server is at all possible.
server 127.127.20.1 mode 88 minpoll 3 iburst prefer

# flag 1: enable pps
# flag3: use the kernel discipline
# time2: The time sentence is delayed by approximately 105ms from the pps (not critical).
fudge 127.127.20.1 stratum 1 flag1 1 flag2 0 flag3 1 flag4 0 time1 0.0 time2 0.105 refid GPS1


The best information for the NMEA driver is here...
https://www.eecis.udel.edu/~mills/ntp/h ... ver20.html

For your other servers, set them all to 'noselect' temporarily except for 1 of them.

Now restart ntpd and see what happens.

If it's working, you'll see 'o' next to the GPS1 entry like...

Code: Select all | TOGGLE FULL SIZE
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 127.127.1.1     .LCL1.           4 l 259m   16    0    0.000    0.000   0.000
o127.127.20.1    .GPS1.           1 l    5    8  377    0.000    0.000   0.004
 192.168.147.250 PPS(1)           2 u    4    8  377    0.219   -0.029   0.031

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Wed Mar 18, 2015 4:15 am

First thank you for your answer.
I tried your solution and this is my /etc/ntp.conf:
Code: Select all | TOGGLE FULL SIZE
  GNU nano 2.2.6                      File: /etc/ntp.conf                                                 

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift


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

server 0.debian.pool.ntp.org iburst noselect
server 1.debian.pool.ntp.org iburst noselect
server 2.debian.pool.ntp.org iburst noselect
server 3.debian.pool.ntp.org iburst

# 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

# 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


# GPS NMEA
server 127.127.20.1 mode 88 minpoll 3 iburst prefer
fudge 127.127.20.1 stratum 1 flag1 1 flag2 0 flag3 1 flag4 0 time1 0.0 time2 0.105 refid GPS


now when i type ntpq -pn i get:
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 178.63.14.131   178.63.61.67     3 u   52   64    3   54.209    8.425  13.511
 148.251.6.51    131.188.3.221    2 u   54   64    3   54.084   10.086   0.697
 148.251.84.200  91.189.94.4      3 u   53   64    3   51.715    7.024   1.653
*130.0.73.18     130.133.1.10     2 u   53   64    3   54.689    4.581   1.391


now there is no GPS or PPS at all?

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Wed Mar 18, 2015 10:19 am

Today spend time i this issue again and i got to this result:
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*127.127.28.0    .GPS.            0 l    16   16  377    0.000  -21.230  42.534
o127.127.22.0    .PPS.            0 l    15   16  377    0.000  -108.86  3.722


So GPS and PPS is used but i think the Offset and Jitter values are to high.
I think they should be around 0 or am I wrong? Something else conspicuous?

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Wed Mar 18, 2015 12:42 pm

Ah wait...Are you using gpsd or the serial port directly? For time, you should always use the serial port directly because you want as little as possible between ntpd and the gps unit. The reason that the gps and pps disappeared was probably because gpsd has grabbed the serial port.

Offset and jitter should eventually be 0.00x for PPS if it has the 'o' next to it. GPS will waver because the sentences aren't as accurate as the pps signal.

The best way to do this is to set the GPS to 115200 baud, set the update rate to 4Hz, and only enable the few sentences you need. Grab the tools I wrote (Python: https://github.com/f5eng/mt3339-utils) and use the gpsinit_time.conf file.

Now in /dev create links as follows...
ln -s /dev/ttyXXX /dev/gps0 (where ttyXXX is the serial port)
ln -s /dev/pps0 /dev/gpspps0

You can use udev to automatically create these for you on bootup.

To test if the pps is working, look for the 'ppstest' utility in your distribution. The package name might be 'pps-tools'.
You can then run 'ppstest /dev/pps0' and you should see output like...

Code: Select all | TOGGLE FULL SIZE
# ppstest /dev/pps0
trying PPS source "/dev/pps0"
found PPS source "/dev/pps0"
ok, found 1 source(s), now start fetching data...
source 0 - assert 1426696560.000000516, sequence: 75193 - clear  0.000000000, sequence: 0
source 0 - assert 1426696560.999999083, sequence: 75194 - clear  0.000000000, sequence: 0
source 0 - assert 1426696561.999997981, sequence: 75195 - clear  0.000000000, sequence: 0
source 0 - assert 1426696563.000001880, sequence: 75196 - clear  0.000000000, sequence: 0
source 0 - assert 1426696564.000001155, sequence: 75197 - clear  0.000000000, sequence: 0
source 0 - assert 1426696564.999999761, sequence: 75198 - clear  0.000000000, sequence: 0
source 0 - assert 1426696566.000000365, sequence: 75199 - clear  0.000000000, sequence: 0
...


The important thing is that you have to make sure you're getting NMEA sentences from the serial port and getting the PPS data from /dev/pps0 before trying to mess with ntpd.

Once that's done, do the ntp config. Note: I changed the 127.127.20.1 to 127.127.20.0 to match gps0 and gpspps0.
Code: Select all | TOGGLE FULL SIZE
# 127.127.20.0: Use the NMEA driver on /dev/gps0 and /dev/gpspps0
# mode 88: speed 115200 and process the $GPZDA or $GPZDG sentences for time
# set the speed for your installation.
# prefer: use this server is at all possible.
server 127.127.20.0 mode 88 minpoll 3 iburst prefer

# flag 1: enable pps
# flag3: use the kernel discipline
# time2: The time sentence is delayed by approximately 105ms from the pps (not critical).
fudge 127.127.20.1 stratum 1 flag1 1 flag2 0 flag3 1 flag4 0 time1 0.0 time2 0.105 refid GPS1


Try this and let me know.

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Wed Mar 18, 2015 1:51 pm

At first, thank you for the answer. I will try this at first tomorrow morning:)

But i'm new in Linux and Raspberry so is there any step by step tutorial for this:
The best way to do this is to set the GPS to 115200 baud, set the update rate to 4Hz, and only enable the few sentences you need. Grab the tools I wrote (Python: https://github.com/f5eng/mt3339-utils) and use the gpsinit_time.conf file.

Now in /dev create links as follows...
ln -s /dev/ttyXXX /dev/gps0 (where ttyXXX is the serial port)
ln -s /dev/pps0 /dev/gpspps0

You can use udev to automatically create these for you on bootup.


because for me it sounds very difficult...

The pps-tools are already installed by the how-to form http://www.satsignal.eu/ntp/Raspberry-Pi-quickstart.html
What exactly do i have to change?

And sorry for my questions...

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Wed Mar 18, 2015 2:14 pm

No worries! The tutorial you linked to is actually pretty good..up to the part in "Getting the time stand-alone" where it recommends to use gpsd. :)

Have you been able to successfully run the 'ppstest' command?

Can you run 'cat /dev/ttyXXX' (where ttyXXX is the serial port where the GPS is connected) and see NMEA sentences that start with $GPRMC. $GPZDA, etc?

Run 'stty -F /dev/ttyXXX' and report the output.

We'll go from there.

EDIT: Oh yeah, stop gpsd before you do this.

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Wed Mar 18, 2015 3:20 pm

Yes, the ppstest works and adds a new line every second:)

I worked through the whole tutorial, also including standalone. So I have to shutdown the gaps service, right?

I will try the comand cat /dev/ttyAMA0 at first tomorrow morning, but I think when i started with the GPS HAT i worked through the setting up tutorial on Adafruits website and there I used this command and get these lines. I used this page: https://learn.adafruit.com/adafruit-ultimate-gps-hat-for-raspberry-pi/basic-test

So I will run : stty -F /dev/ttyAMA0 , right?

Tomorrow I will post the results and we go on:)

But I have two additional questions:
1. When i reboot the pi, the PPS doesn't get the 'o' until I restart the ntp service, is there any workaround?
2. I can't use the command 'ntpq -pn' when the LAN cable is ejected, the error 'service or name not known'

Thank you for your patience und your help, I'm very happy about that:)

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Wed Mar 18, 2015 4:37 pm

Tobi2707 wrote:Yes, the ppstest works and adds a new line every second:)

Excellent!

Tobi2707 wrote:I worked through the whole tutorial, also including standalone. So I have to shutdown the gaps service, right?

Yes. It's best for ntpd to get the data directly from the serial port.
Tobi2707 wrote:I will try the comand cat /dev/ttyAMA0 at first tomorrow morning, but I think when i started with the GPS HAT i worked through the setting up tutorial on Adafruits website and there I used this command and get these lines. I used this page: https://learn.adafruit.com/adafruit-ultimate-gps-hat-for-raspberry-pi/basic-test

Also excellent!
Tobi2707 wrote:
So I will run : stty -F /dev/ttyAMA0 , right?


Yep. That will give us the working baud rate. It's probably 9600 which is fine. Just want to make sure though.
Tobi2707 wrote:Tomorrow I will post the results and we go on:)

But I have two additional questions:
1. When i reboot the pi, the PPS doesn't get the 'o' until I restart the ntp service, is there any workaround?

The ntpd service should start at boot but it may take a minute for it to sync, expecially if the pi's clock is off significantly or there isn't another available server.
Tobi2707 wrote:2. I can't use the command 'ntpq -pn' when the LAN cable is ejected, the error 'service or name not known'

It may be that ntpd is detecting that there's no network connectivity and shutting down. We can look at that later.
Tobi2707 wrote:
Thank you for your patience und your help, I'm very happy about that:)


No problem!

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Thu Mar 19, 2015 4:16 am

So back again:)

The command gives me following output:
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ sudo service gpsd stop
pi@raspberrypi ~ $ stty -F /dev/ttyAMA0
speed 9600 baud; line = 0;
-brkint -imaxbel
As expected the baud is 9600

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

Please be positive and constructive with your questions and comments.