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 gtj on Thu Mar 19, 2015 11:30 am

Tobi2707 wrote: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


Excellent.
BTW, You can turn off gpsd permanently by running 'chkconfig gpsd off'

Now you need to create those links so ntpd can find the serial port and pps device. I forget how to create these permanently but I'm looking.

Code: Select all | TOGGLE FULL SIZE
ln -s /dev/ttyAMA0 /dev/gps0
ln -s /dev/pps0 /dev/gpspps0


And use the following config in ntp.conf...

Code: Select all | TOGGLE FULL SIZE
server 127.127.22.0 minpoll 3 iburst prefer
fudge 127.127.22.0 stratum 1 flag2 0 flag3 1 flag4 0 refid PPS0

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


Alternatively, you can use the combined NMEA and PPS server but I'd use the separate ones for now.

Code: Select all | TOGGLE FULL SIZE
server 127.127.20.0 mode 16 minpoll 3 iburst prefer
fudge 127.127.20.0 stratum 1 flag1 1 flag2 0 flag3 1 flag4 0 time1 0.0 time2 0 refid GPS0


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 Thu Mar 19, 2015 11:52 am

Okay i was setting up a new SD card and went through the tutorial without the Standalone step.
So the gpsd is not installed anymore and i don't need to disable it:)

pi@raspberrypi ~ $ sudo ln -s /dev/ttyAMA0 /dev/gps0
pi@raspberrypi ~ $ sudo ln -s /dev/pps0 /dev/gpspps0

I'm not logged in as root so i have to use sudo in front of your 2 commands, right?


So the ntp.conf is:
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 prefer
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst


# 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# 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

#PPS and GPS
server 127.127.22.0 minpoll 3 iburst prefer
fudge 127.127.22.0 stratum 1 flag2 0 flag3 1 flag4 0 refid PPS0

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

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Thu Mar 19, 2015 12:06 pm

Tobi2707 wrote:Okay i was setting up a new SD card and went through the tutorial without the Standalone step.
So the gpsd is not installed anymore and i don't need to disable it:)

pi@raspberrypi ~ $ sudo ln -s /dev/ttyAMA0 /dev/gps0
pi@raspberrypi ~ $ sudo ln -s /dev/pps0 /dev/gpspps0

I'm not logged in as root so i have to use sudo in front of your 2 commands, right?


Correct.
Tobi2707 wrote:So the ntp.conf is:
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 prefer
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst


# 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# 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

#PPS and GPS
server 127.127.22.0 minpoll 3 iburst prefer
fudge 127.127.22.0 stratum 1 flag2 0 flag3 1 flag4 0 refid PPS0

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


To avoid confusion, I'd remove all but the first pool server and remove the 'prefer' from the one that remains. Otherwise it looks 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 19, 2015 12:28 pm

okay:)
so what are the next steps?

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Thu Mar 19, 2015 12:52 pm

Tobi2707 wrote:okay:)
so what are the next steps?


That's it! Start ntpd and do the ntpq -pn.

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 12:58 pm

Now after restarting nt. service the output is:

Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
x127.127.22.0    .PPS0.           1 l    1    8  377    0.000   33.847  18.699
 127.127.20.0    .GPS0.           1 l    -    8    0    0.000    0.000   0.000
*188.138.9.208   129.69.1.153     2 u    2   64    3  196.549  -50.882  39.062


GPS doesn't get the 'o' and PPS is marked as falseticker, whats wrong?
I think there will be a problem with the GPS?

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Thu Mar 19, 2015 1:32 pm

Tobi2707 wrote:Now after restarting nt. service the output is:

Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
x127.127.22.0    .PPS0.           1 l    1    8  377    0.000   33.847  18.699
 127.127.20.0    .GPS0.           1 l    -    8    0    0.000    0.000   0.000
*188.138.9.208   129.69.1.153     2 u    2   64    3  196.549  -50.882  39.062


GPS doesn't get the 'o' and PPS is marked as falseticker, whats wrong?
I think there will be a problem with the GPS?


I think you're correct. The PPS can only work with another server that's marked as 'prefer'. Since the GPS doesn't seem to be working, try setting the pool server to prefer and remove the 'prefer' from the GPS server. That will at least tell us if the PPS part is working.

If that works, then make sure you can do a 'cat /dev/gps0' and see the NMEA sentences.

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Thu Mar 19, 2015 1:41 pm

Oh yeah, to automatically create those links at startup, create a file named '99-gps.rules' in '/etc/udev/rules.d'

It should contain...

Code: Select all | TOGGLE FULL SIZE
KERNEL=="ttyAMA0", SYMLINK+="gps0"
KERNEL=="pps0", SYMLINK+="gpspps0"


You can test it by running 'sudo udevadm trigger' and see that the links were created.

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 1:43 pm

So i typed cat /dev/gps0 and my Pi was frozen so i had to restart it.

Then i ran ntpq -pn and it seems that pps is running:
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
o127.127.22.0    .PPS0.           1 l    4    8  377    0.000    0.031   0.025
*85.25.105.106   192.168.100.15   2 u   45   64    7   24.174   -0.055   1.396


and then i ran cat /dev/gps0 and got this:
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ cat dev/gps0


EDIT: I haven't done the setting up the gps yet (/boot/cmdline.txt and /etc/inittab) maybe this is missing?
cat: dev/gps0: No such file or directory


pool server is prefer and prefer at gps is deleted

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

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

Now i added the GPS rules file for autostart and restarted the Pi. As result the cat command works:
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ cat /dev/gps0
$GPGGA,181119.000,5002.1718,N,00902.3176,E,1,07,1.20,101.2,M,48.0,M,,*67

$GPGSA,A,3,31,12,24,25,14,29,02,,,,,,1.48,1.20,0.87*0F

$GPGSV,3,1,11,12,69,061,29,25,64,283,34,14,40,274,29,24,39,144,22*76

$GPGSV,3,2,11,29,36,204,19,02,31,104,15,37,31,163,,06,24,055,14*7E

$GPGSV,3,3,11,31,15,309,39,03,01,355,,32,01,314,16*4F

$GPRMC,181119.000,A,5002.1718,N,00902.3176,E,0.31,250.88,190315,,,A*65

$GPVTG,250.88,T,,M,0.31,N,0.57,K,A*3A

$GPGGA,181120.000,5002.1720,N,00902.3177,E,1,07,1.19,101.1,M,48.0,M,,*6E


then i changed the ntp.conf to:
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 # prefer


# 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


#PPS and GPS
server 127.127.22.0 minpoll 3 iburst prefer
fudge 127.127.22.0 stratum 1 flag2 0 flag3 1 flag4 0 refid PPS0

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

Next i restarted ntp service and ran ntpq -pn and got this :
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
x127.127.22.0    .PPS0.           1 l    5    8  377    0.000  463.159   0.187
x127.127.20.0    .GPS0.           1 l    4    8  377    0.000   17.017  39.705
*213.209.109.45  10.129.40.211    2 u   47   64   17   30.815  463.230   1.607


So PPS and GPS both are marked as falseticker?

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Thu Mar 19, 2015 2:31 pm

Hmmm. That's weird. Both PPS0 and GPS0 appear to be reachable (377) so I'm not sure why they're being ignored. Try with the pool server commented out completely and see what happens. You could also run 'ntpdate -b <pool server>' once before starting ntpd to get the system clock closer.

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 3:21 pm

I will try this and Tell you the result :)
I think the pps without gps does work well,
But i have to fix it with gps. I'll try your Way tomorrow

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Fri Mar 20, 2015 4:40 am

After commenting out all pool servers I got this:
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
xPPS(0)          .PPS0.           1 l    1    8  377    0.000  474.622   0.195
xGPS_NMEA(0)     .GPS0.           1 l    1    8  377    0.000  -55.965  49.774


Both still marked as falsetickers...:(

And I got this output:
Code: Select all | TOGGLE FULL SIZE
pi@raspberrypi ~ $ sudo ntpdate -b 127.127.20.0
20 Mar 09:38:39 ntpdate[2623]: the NTP socket is in use, exiting


Very tricky evrything:P

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by Tobi2707 on Fri Mar 20, 2015 9:53 am

Here i wrote down the step I did before:
http://www.file-upload.net/download-10443387/NTP-GPS-PPS_Tutorial.pdf.html

Maybe you could take a look and we could solve the problem:)

If you want we can also communicate by email for not the spam this forum;)

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

Re: Raspberry Pi GPS Stratum 1 NTP Server

by gtj on Fri Mar 20, 2015 11:28 am

Let's leave the conversion here in case others can use the information.

From looking at your log, I think the big issue is that the offset between PPS0 and GPS0 is too great. It can't be more than ~0.500 seconds or ntpd won't be able to lock the 2 together. The reason they're not is that at 9600 baud, the GPS can't send all of it's information in that short of a time span. So we need to increase the speed of the GPS to 115200.

Download 'gpsinit' from my tools repository (https://github.com/f5eng/mt3339-utils) then mark it executable with 'chmod a+x gpsinit'. Now create the following file and save it as gpsinit_time.conf.

Code: Select all | TOGGLE FULL SIZE
# Set NMEA Sentence Output
PMTK314,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0

# Set output rate to 4/second
PMTK220,250


Now stop ntpd and run the gpsinit command as follows: 'gpsinit -s 115200 -f gpsinit_time.conf /dev/ttyAMA0'
This sets the GPS in the best configuration for a time server.

Now you need to change ntp.conf to match so change 'mode 16' to 'mode 88' on the GPS0 server line.

Before starting ntpd, get the pi's time as close as possible with ntpdate... 'ntpdate -bu 0.debian.pool.ntp.org'

Finally, start ntpd and see what happens.

I think we're getting close. :)

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

Please be positive and constructive with your questions and comments.