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 RustyShamrock on Sat Mar 30, 2019 4:14 pm

Well, I'm having a heck of a time getting gpsd to work properly. At first, gpsd wasn't even loading at boot time, and I needed to run gpsmon to get it to load. Once loaded this way, ntpd would receive both PPS and NMEA, though the offset and jitter values were terrible causing ntp to refuse the refclock.

That issue has been resolved. But now, even though gpsd is loading, it's not sending any of the NMEA sentences thru to ntpd. PPS pulses are received, but no NMEA. That is, until I once again run gpsmon, which once it kicks in, allows ntp to do it's thing, eventually settling down to an amazing +- 1uS offset/jitter.

Two separate systems, one a pi 3B w/ultimate Breakout and the other a 3B+ w/ultimate hat and POE hat. Both behave the same.

If anybody has any ideas what is happening here I'd be grateful for any help.

RustyShamrock
 
Posts: 10
Joined: Thu Mar 21, 2019 11:44 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by panttaja on Sat Mar 30, 2019 7:16 pm

I am stuck at a slightly different place - interested to know what tools/settings you have that got you this far. I have tried to read a variety of posts - and make sense of them - but not completely there yet. Do have gpsmon, cgps -s, xgps, ppstest all giving what look to be appropriate results. But ntpq doesn't look like PPS of NMEA data is arriving at ntp...

Edit /etc/rc.local
# Added by JTP - some of these seem superfluous - but this sequence allowed gpsmon, cgpq, xgps to report properly
systemctl daemon-reload
systemctl enable gpsd
systemctl start gpsd
stty -F /dev/serial0 raw 9600 cs8 clocal -cstopb
systemctl stop gpsd.socket
systemctl disable gpsd.socket
gpsd /dev/serial0 -F /var/run/gpsd.sock
Edit /boot/config.txt
# Added by JTP
force_turbo=1
dtoverlay=pps-gpio,gpiopin=4
init_uart_baud=9600
arm_freq=800
Edit /etc/ntp.conf
#Added by JTP
server 127.127.28.0 minpoll 4
fudge 127.127.28.0 time1 0.183 refid NMEA
server 127.127.28.1 minpoll 4 prefer
fudge 127.127.28.1 refid PPS
Edit /etc/default/gpsd
# DEVICES=""
DEVICES="/dev/serial0 /dev/pps0”
Maybe undo this change? Seemed to slow things down… and it didn’t change anything...

Verification:

cat /dev/serial0
gpsmon
cgps -s
sudo ppstest /dev/pps0
ntpq -p

Here is result of ntpq -p I haven't turned off receiving from other ntp servers - I expect the hat to be a backup for me (for now).

ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
SHM(0) .NMEA. 0 l - 16 0 0.000 0.000 0.000
SHM(1) .PPS. 0 l - 16 0 0.000 0.000 0.000
0.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.001
1.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.001
2.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.001
3.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.001
+dns-e.wdc-us.ho 129.6.15.30 2 u 14 64 377 115.525 -10.399 18.935
+ha82.smatwebdes 200.98.196.212 2 u 16 64 377 74.138 -14.261 21.134
+tssnet1.tss.net 63.145.169.3 2 u 54 64 375 67.140 -6.756 15.450
+services.quadra 104.131.155.175 3 u 25 64 377 45.051 -12.282 12.746
#io.netbunker.or 209.51.161.238 2 u 53 64 377 126.242 10.499 15.930
+pacific.latt.ne 46.233.231.73 2 u 60 64 377 35.599 -2.434 7.319
#ntp2.wiktel.com 212.215.1.157 2 u 19 64 377 95.069 -23.157 20.552
+159.203.158.197 130.183.99.210 3 u 14 64 377 112.437 -10.545 14.363
#time.richiemcin 200.98.196.212 2 u 14 64 377 118.817 -13.227 12.982
+ntp.wdc1.us.lea 130.133.1.10 2 u 17 64 377 95.260 -11.972 19.033
+mirror1.sjc02.s 162.213.2.253 2 u 51 64 377 38.357 -11.336 19.557
+palpatine.pha.l 132.239.1.6 2 u 56 64 377 48.003 -5.869 17.704
*darwin.kenyonra 127.67.113.92 2 u 56 64 377 40.948 -9.067 23.968
+moonunit.collie 140.142.1.8 3 u 57 64 377 54.987 -5.546 18.228
+linode227395.st 192.5.41.41 2 u 54 64 277 119.535 -14.700 18.146

panttaja
 
Posts: 4
Joined: Mon Mar 25, 2019 10:50 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by RustyShamrock on Sun Mar 31, 2019 8:41 am

panttaja wrote:I am stuck at a slightly different place - interested to know what tools/settings you have that got you this far. I have tried to read a variety of posts - and make sense of them - but not completely there yet. Do have gpsmon, cgps -s, xgps, ppstest all giving what look to be appropriate results. But ntpq doesn't look like PPS of NMEA data is arriving at ntp...


Not sure I'm a good choice for helping you, but here's what I see in all that.
Verify that gpsd is actually loading and running by running "sudo systemctl status gpsd.service". Here is what I get when running that on a machine that has been "primed" (by use of gpsmon..
.
Code: Select all | TOGGLE FULL SIZE
pi@rpi-tick:~ $ sudo systemctl status gpsd.service
● gpsd.service - GPS (Global Positioning System) Daemon
   Loaded: loaded (/etc/systemd/system/gpsd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2019-03-30 14:46:55 CDT; 16h ago
 Main PID: 286 (gpsd)
   CGroup: /system.slice/gpsd.service
           └─286 /usr/sbin/gpsd -N -n /dev/ttyAMA0 /dev/pps0

Mar 30 14:46:55 rpi-tick systemd[1]: Started GPS (Global Positioning System) Daemon.
Mar 30 14:46:55 rpi-tick gpsd[286]: gpsd:ERROR: /dev/ttyAMA0 already opened by another process
Mar 30 14:46:55 rpi-tick gpsd[286]: gpsd:ERROR: initial GPS device /dev/ttyAMA0 open failed
pi@rpi-tick:~ $ nt
associd=0 status=0118 leap_none, sync_pps, 1 event, no_sys_peer,
version="ntpd 4.2.8p10@1.3728-o Sat Mar 10 18:03:33 UTC 2018 (1)",
processor="armv7l", system="Linux/4.14.98-v7+", leap=00, stratum=1,
precision=-20, rootdelay=0.000, rootdisp=1.075, refid=PPS0,
reftime=e04b2bd2.3bcee2ce  Sun, Mar 31 2019  7:06:42.233,
clock=e04b2bd7.9481a2f0  Sun, Mar 31 2019  7:06:47.580, peer=22862, tc=4,
mintc=3, offset=0.018629, frequency=-5.650, sys_jitter=0.001223,
clk_jitter=0.001, clk_wander=0.004
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+nu.binary.net   204.9.54.119     2 u   39   64  377   28.810    2.226   0.705
-linode.appus.or 127.67.113.92    2 u    1   64  377   47.983    5.096   0.952
+portal.switch.c 213.251.128.249  2 u   21   64  377   54.603   -0.769   1.778
oPPS(0)          .PPS0.           0 l    5   16  377    0.000    0.019   0.001
*SHM(0)          .NMEA.           0 l    7   16  377    0.000    0.019   0.001

and on a machine that has NOT been primed...
Code: Select all | TOGGLE FULL SIZE
pi@rpi-tick1:~ $ sudo systemctl status gpsd.service
● gpsd.service - GPS (Global Positioning System) Daemon
   Loaded: loaded (/lib/systemd/system/gpsd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-03-31 07:20:28 CDT; 7min ago
 Main PID: 309 (gpsd)
   CGroup: /system.slice/gpsd.service
           └─309 /usr/sbin/gpsd -N -n -D 2 /dev/ttyAMA0 /dev/pps0

Mar 31 07:20:28 rpi-tick1 systemd[1]: Started GPS (Global Positioning System) Daemon.
Mar 31 07:20:28 rpi-tick1 gpsd[309]: gpsd:ERROR: /dev/ttyAMA0 already opened by another process
Mar 31 07:20:28 rpi-tick1 gpsd[309]: gpsd:ERROR: initial GPS device /dev/ttyAMA0 open failed
Mar 31 07:20:28 rpi-tick1 gpsd[309]: gpsd:WARN: KPPS:/dev/pps0 missing PPS_CAPTURECLEAR, pulse may be offset
pi@rpi-tick1:~ $ nt
associd=0 status=0618 leap_none, sync_ntp, 1 event, no_sys_peer,
version="ntpd 4.2.8p10@1.3728-o Sat Mar 10 18:03:33 UTC 2018 (1)",
processor="armv7l", system="Linux/4.14.98-v7+", leap=00, stratum=3,
precision=-21, rootdelay=43.277, rootdisp=21.256, refid=216.229.0.50,
reftime=e04b3050.a07a5135  Sun, Mar 31 2019  7:25:52.626,
clock=e04b30d6.f5f56341  Sun, Mar 31 2019  7:28:06.960, peer=24274, tc=6,
mintc=3, offset=1.354136, frequency=-8.383, sys_jitter=2.825891,
clk_jitter=1.486, clk_wander=0.000
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*nu.binary.net   128.252.19.1     2 u   68   64   17   28.603    2.771   1.016
+linode.appus.or 127.67.113.92    2 u   58   64   67   48.828   -0.466   4.395
+portal.switch.c 213.251.128.249  2 u   54   64   77   53.637   -0.232   2.114
-44.190.6.254    127.67.113.92    2 u   26   64  177   64.206   -6.959   2.352
xPPS(0)          .PPS0.           0 l   14   16  377    0.000   -1.343   0.046
 SHM(0)          .NMEA.           0 l    -   16    0    0.000    0.000   0.000


"nt" is an alias for "ntpq -crv -p"
(By the way, when pasting in screen output or config info, use the "[code]" button at the top of the edit window to keep the format clean.)
Make sure the status shows both "loaded" and "active"

RustyShamrock
 
Posts: 10
Joined: Thu Mar 21, 2019 11:44 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by RustyShamrock on Sun Mar 31, 2019 9:23 am

Oh, and here is how I have the "servers" set up in ntp.conf..
.
Code: Select all | TOGGLE FULL SIZE
# GPS PPS reference (from PPS Clock Discipline)
server 127.127.22.0 prefer minpoll 4 maxpoll 4
fudge  127.127.22.0 flag2 0 flag3 1 refid PPS0
# flag1 - not used
# flag2 - signal edge 0=assert (default), 1=clear
# flag3 - kernel PPS 0=disable (default), 1=enable

# get time from SHM from gpsd; this seems working
server 127.127.28.0 prefer minpoll 4 maxpoll 4
fudge  127.127.28.0 time1 +0.00 refid NMEA

RustyShamrock
 
Posts: 10
Joined: Thu Mar 21, 2019 11:44 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by RustyShamrock on Thu Apr 11, 2019 11:46 am

Well, I think I've figured out what is happening, but I've been unsuccessful in fixing it.

The problem is that when gpsd starts up, it attempts to open the serial port /dev/ttyAMA0. This shows up in the system log as...
Code: Select all | TOGGLE FULL SIZE
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: NTP: shmat(0,0,0) succeeded, segment 0
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: NTP: shmat(32769,0,0) succeeded, segment 1
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: NTP: shmat(65538,0,0) succeeded, segment 2
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: NTP: shmat(98307,0,0) succeeded, segment 3
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: NTP: shmat(131076,0,0) succeeded, segment 4
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: NTP: shmat(163845,0,0) succeeded, segment 5
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: NTP: shmat(196614,0,0) succeeded, segment 6
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: NTP: shmat(229383,0,0) succeeded, segment 7
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: successfully connected to the DBUS system bus
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: shmget(0x47505344, 8928, 0666) for SHM export succeeded
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: shmat() for SHM export succeeded, segment 262152
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: stashing device /dev/ttyAMA0 at slot 0
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: no /etc/gpsd/device-hook present, skipped running ACTIVATE hook

Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: opening GPS data source type 2 at '/dev/ttyAMA0'
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:ERROR: /dev/ttyAMA0 already opened by another process
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:ERROR: initial GPS device /dev/ttyAMA0 open failed

Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: stashing device /dev/pps0 at slot 1
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: no /etc/gpsd/device-hook present, skipped running ACTIVATE hook
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: switch_driver(PPS) called...
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: selecting PPS driver...
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: PPS:/dev/pps0 chrony socket /var/run/chrony.pps0.sock doesn't exist
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: KPPS:/dev/pps0 RFC2783 path:/dev/pps0, fd is 7
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: KPPS:/dev/pps0 pps_caps 0x1151
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: KPPS:/dev/pps0 have PPS_CANWAIT
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:WARN: KPPS:/dev/pps0 missing PPS_CAPTURECLEAR, pulse may be offset
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: KPPS:/dev/pps0 kernel PPS will be used
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:PROG: PPS:/dev/pps0 thread launched
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: PPS:/dev/pps0 ntpshm_link_activate: 0
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: device /dev/pps0 activated
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: KPPS:/dev/pps0 gps_fd:-2 not a tty
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: KPPS:/dev/pps0 kernel PPS timeout Interrupted system call
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: KPPS:/dev/pps0 kernel PPS timeout Interrupted system call
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: running with effective group ID 20
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: running with effective user ID 110
Apr 11 10:11:48 rpi-tick gpsd[317]: gpsd:INFO: startup at 2019-04-11T15:11:48.000Z (1554995508)


It then starts processing PPS pulses, but since it isn't receiving the NMEA sentences, it never gets a fix. While it's in this state, if I start gpsmon, it gets registered with gpsd as a new client, and tries again to open ttyAMA0, this time successfully, and all is good.

I am certain that during startup, the kernel is opening ttyAMA0 to issue kernel startup messages.

I have edited /boot/cmdline.txt to remove the references to "console=ttyAMA0", or even to point the console to the other serial port, or to null with no effect. Syslog shows that the kernel command line is...
Code: Select all | TOGGLE FULL SIZE
Apr 11 10:11:47 rpi-tick kernel: [    0.000000] Kernel command line: 8250.nr_uarts=1 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0
p2 rootfstype=ext4 rootwait


Here is my cmdline.txt file...# /boot/cmdline.txt
Code: Select all | TOGGLE FULL SIZE
# Ansible managed

dwc_otg.lpm_enable=0  console=tty1 console=null quiet root=PARTUUID=08616e16-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
#dwc_otg.lpm_enable=0  console=tty1 root=PARTUUID=08616e16-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait nohz=off


I have tried loading gpsd and ntpd last, even inserting sleep commands in the startup scripts to see if i can wait until the serial port is released by the kernel, but to no avail.

If anybody knows how to prevent this system from overriding my console settings to make the serial port available upon gpsd load, I'd sure like to hear about it.

RustyShamrock
 
Posts: 10
Joined: Thu Mar 21, 2019 11:44 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by dl5ari on Sun Jun 09, 2019 7:43 am

@ Rob, KC8KPX: Thank You for very exactly description of my problems

I still ask a question about it. From the Adafruit ultimate GPS Hat over shm both pps and gps are passed to ntp. so far ok.
pps goes very well with the ntp pool. But the GPS time offset is in the range of -500 ms!

remote refid offset
*SHM(1) .PPS. -0.3059
xSHM(0) .GPS. -543.417
de.pool.ntp.org
+tor-relaisl.lin -1.0018 1.4406 or so

This is exactly what cgps -s says: time offset in the range of 500 ms and more
By the way, my ntp.conf includes that:

refclock shm unit 1 refid PPS
refclock shm unit 0 refid GPS

If I correct this with refclock ... time1 0.500, then the system turns around and shows for the ntp-pool time offsets in the high range.
So that's not the solution. Incidentally, cgps also indicates this time offset.
I'm looking for an approach on how to tackle this problem. Can somebody help me?

73 de Tom DL5ARI

dl5ari
 
Posts: 2
Joined: Sat Jun 08, 2019 1:56 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by RustyShamrock on Sun Jun 09, 2019 8:58 am

Try creating a magic symlink...

Code: Select all | TOGGLE FULL SIZE
ln -s /lib/systemd/system/gpsd.service /etc/systemd/system/multi-user.target.wants/gpsd.service

In my case, that eliminated the need for fudge factors

RustyShamrock
 
Posts: 10
Joined: Thu Mar 21, 2019 11:44 am

Re: Raspberry Pi GPS Stratum 1 NTP Server

by dl5ari on Sun Jun 09, 2019 11:44 am

Thanks for the fast suggestion!
But sorry - I don't understand the background of the magic link. What exactly is caused by this?
And For me, I use the construct of NTPsec. (https://www.ntpsec.org/white-papers/str ... ver-howto/)
gpsd and ntpd services are started via an extra System V init script called timeservice.service, which of course is located in ... systemd / system.

dl5ari
 
Posts: 2
Joined: Sat Jun 08, 2019 1:56 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by dstumbo on Thu Jul 04, 2019 7:45 pm

After looking at and synthesizing a lot of how-tos (and quite a few false starts), I have successfully gotten a 4B, 3B, 3B+, and Zero W working as ntp servers, using an Ultimate GPS Hat, including the pps output. I put a how-to on Github: https://github.com/dstumbo/chrony-rpi-gps

I used chrony (not ntp) for two reasons:

1. It worked.
2. My purpose is to serve time when off grid, and chrony is supposed to be better behaved when the internet comes and goes.

Note: I used raspbian buster lite, which gives new enough versions of gpsd and chrony that they work out of the box (no compiling needed)

Comments and suggestions welcome

dstumbo
 
Posts: 3
Joined: Sun Apr 23, 2017 7:39 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by kiokoman on Fri Jul 05, 2019 6:37 pm

i have tried your tutorian and it work, but ntp pool see it as a stratum 2 server, i also have made a tutorial for ntp, i had alot of problem from gpsd (offset/jitter) so i'm using a configuration without it. My howto is here https://www.kiokoman.eu.org/index.php/p ... -1-gps-pps
Comments and suggestions welcome :)

kiokoman
 
Posts: 5
Joined: Fri Jul 05, 2019 2:49 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by dstumbo on Sun Jul 07, 2019 2:57 pm

Hi Kiokoman,

Thanks for testing it, I'm glad it worked. I looked at your tutorial, and if I understand it correctly, the use cases are a little different:

1. For mine, I am trying to provide local NTP services when not connected to the internet or cell network. For my application (WSJT-X for FT-8), +/- a few ms is close enough (it needs to be a little better than plain GPS, thus GPS and PPS). As I understand it, chrony works better than NTP when the internet (and hence the NTP pool) comes and goes. I also found it easy to configure and get running.

2. I think your use case is to improve local accuracy of an internet NTP pool. In that case, GPS is an unnecessary complication: all you need it the pool and PPS, so it sounds like your solution is optimal.

73/Best Regards, Dave N5MNZ

dstumbo
 
Posts: 3
Joined: Sun Apr 23, 2017 7:39 pm

Re: Raspberry Pi GPS Stratum 1 NTP Server

by kiokoman on Mon Jul 08, 2019 5:36 am

well the fact that i'm using it inside a pool is only a plus. my configuration is exactly for the same purpose, it is using time from GPS and PPS, they are cobined from ntpd (127.127.20.0 is the driver that talk to the gps, and flag1 1 is the option that tell ntp to read also PPS) but without gpsd, i can freely remove it from the internet and it will work the same, i'm using a ft-897d for digital mode. In the end they are the same, they are just two different method to obtain the same solution.
73, Manuel IU3CDG :)

kiokoman
 
Posts: 5
Joined: Fri Jul 05, 2019 2:49 pm

Please be positive and constructive with your questions and comments.