RPI + Adafruit GPS sanity check
Patrick
201905-ntpsec at jslf.app
Thu May 16 06:50:23 UTC 2019
Hi all,
I used the following docs to setup an RPI 2B + Adafruit GPS HAT.
Primarily following:
https://www.ntpsec.org/white-papers/stratum-1-microserver-howto/
while using the following for sanity checks:
https://www.morcant.com/blog/stratum-1-ntp-server/
http://www.satsignal.eu/ntp/Raspberry-Pi-NTP.html
And it all appears to be working. I have some questions though:
Is the caveat against NMEA refclock still valid?
https://www.ntpsec.org/white-papers/stratum-1-microserver-howto/#_why_gpsd
I tried both gpsd and refclock NMEA configs, and they both threw
falsetickers, which I chalked up to my HAT's limited skyview.
Since the PPS is /dev/pps0, gpsd can be dropped.
Is there anything that should be done to prevent mishaps like the USNO
has had over time? It seems like there just needs to be a nagios check
that runs against local time servers to make sure they have a large
enough odd number of peers?
Does refclock NMEA time2 or refclock shm time1 calibration matter?
Depending on skyview, the NMEA refclock may bounce around too much and be
declared a falseticker at times due to too large an offset -- so with a limited
skyview, it's better to think of the NMEA clock as a backup time source.
It seems that the more important source is the PPS which will discipline
when the consensus second starts. PPS should always be flagged with a
leading 'o' and its jitter should be less than 5 microseconds.
ntpq -pn
remote refid st t when poll reach delay offset jitter
===============================================================================
oPPS(0) .PPS. 0 l 10 16 377 0.0000 -0.0008 0.0002
*NMEA(0) .GPS. 0 l 9 16 377 0.0000 26.6331 44.7632
+10.8.0.10 218.186.3.36 2 u 6 16 377 0.3630 -0.1715 0.1588
+10.8.1.7 10.8.0.10 3 u 5 16 377 0.3528 -0.1748 0.0125
-209.58.172.142 85.199.214.98 2 u 58 64 377 3.2658 18.1020 0.0932
-133.243.238.164 .NICT. 1 u 31 64 377 75.7035 2.9800 38.0955
-203.217.204.135 133.243.238.163 2 u 62 64 377 71.4136 -4.2721 0.1610
Thanks!
P.S. Below are notes that others might find useful regarding HAT
configuration and timeN calibration, along with the configs that
were used.
# GPS HARDWARE INITIALIZATION
Configure the GPS to output NMEA MRC (has date + time) once per second
https://www.gpsinformation.org/dale/nmea.htm
https://cdn-shop.adafruit.com/datasheets/PMTK_A08.pdf
N.B. GPS commands are check-summed as per the last page of the PMTK datasheet.
python3
def checksum(cmd):
ck, *cmd = [ ord(x) for x in cmd ]
for c in cmd:
ck ^= c
return hex(ck)[2:].upper()
assert checksum("PMTK605") == '31'
assert checksum("PMTK226,3,30") == '4'
assert checksum("PMTK251,115200") == '1F'
# GPS CALIBRATION
GPS offsets can vary depending on skyview ( what satellites are seen when ) so
calculate the offsets online-average over at least 12 hours ( Medium Earth
Orbit period ).
Run the following to generate the NMEA refclock's time1 offset
while sleep 1; do
ntpq -pn
done | awk '
BEGIN { n = 0 ; mean = 0; }
/^.NMEA/ {
n += 1;
mean += ( $9 - mean ) / n;
printf("%f\t\r", mean);
system("");
}
'
####### /etc/rc.local #######
#!/bin/bash
GPS=/dev/ttyAMA0
gps_config() {
printf '$%s\r\n' "$1" > $GPS
sleep 0.2
}
stty -F $GPS raw 9600 cs8 clocal -cstopb
gps_config 'PMTK251,9600*17'
# only output RMC
# $PMTK314,1,1,1,1,1,5,0,0,0,0,0,0,0,0,0,0,0,0,0*2C<CR><LF>
gps_config 'PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29'
# output once per second
gps_config 'PMTK220,1000*1F'
# ntp talks directly to the adafruit
ps -C ntpd &>/dev/null && {
echo killing ntpd
killall -TERM ntpd
}
nice -19 /usr/local/sbin/ntpd -g -c /etc/ntp.conf
####### /etc/ntp.conf #######
refclock pps refid PPS ppspath /dev/pps0 minpoll 4 maxpoll 4 prefer
refclock nmea refid GPS path /dev/ttyAMA0 baud 9600 minpoll 4 maxpoll 4 mode 1 time2 0.480
# mode 1 cos only RMC has date + time
# local servers
server 10.8.0.10 iburst minpoll 4 maxpoll 4
server 10.8.1.7 iburst minpoll 4 maxpoll 4
server sg.pool.ntp.org iburst
server jp.pool.ntp.org iburst
server kr.pool.ntp.org iburst
restrict default kod limited nomodify nopeer noquery
restrict -6 default kod limited nomodify nopeer noquery
restrict 10.8.0.10
restrict 10.8.1.7
restrict 127.0.0.1
restrict -6 ::1
driftfile /var/lib/ntp/ntp.drift
More information about the users
mailing list