hi,
i have a RPi that i want to use as a high precise NTP server (Stratum1) for a local network, where no connection to the external internet is.
that means i have no connection to any external NTP server.
to have my RPi running as an Stratum One server i use a GPS receiver that also provides a PPS (an high precise pulse per second signal).
the GPS does not have a battery to buffer the RTC of the GPS device (so after power off, everything boots from cold start).
i followed the descriptions here (Quick start NTP on the Raspberry Pi) and here (The Raspberry Pi as a Stratum-1 NTP Server).
i connected everything to the RPi correctly (RX, TX, PPS->GPIO 18).
everything seems to work fine as long the RPi is connected to the network with connection to external internet...
but if i use the RPi in a local network without a connection to external internet, then the RPi isn't able to get the correct time, that is should get from the GPS device.
can somebody tell me, there i made a mistake, and what i have to do to get my NTP Server running correctly with using the GPS time and its precise PPS signal in an isolated local network environment?
so i guess the GPS time never was used correctly to get the time.
in principe, the GPS is working, and PPS is working, the kernel is PPS enabled, NTP is PPS enabled, as you can see on the status messages below.
i use the official Raspbian Jessie Lite image (2016-02-26-raspbian-jessie-lite.img)
Code: Select all
pi@myStratum1:~ $ uname -a
Linux myStratum1 4.1.18+ #846 Thu Feb 25 14:11:56 GMT 2016 armv6l GNU/Linux
Code: Select all
pi@myStratum1:~ $ ntpstat
unsynchronised
polling server every 8 s
Code: Select all
pi@myStratum1:~ $ ntpq -crv -pn
associd=0 status=c016 leap_alarm, sync_unspec, 1 event, restart,
version="ntpd 4.2.8p6@1.3265 Wed Mar 9 21:01:11 UTC 2016 (1)",
processor="armv6l", system="Linux/4.1.18+", leap=11, stratum=16,
precision=-18, rootdelay=0.000, rootdisp=12.570, refid=INIT,
reftime=00000000.00000000 Thu, Feb 7 2036 7:28:16.000,
clock=da8b23f9.95c7cb10 Wed, Mar 9 2016 23:36:41.585, peer=0, tc=3,
mintc=3, offset=0.000000, frequency=0.000, sys_jitter=0.000000,
clk_jitter=0.004, clk_wander=0.000
remote refid st t when poll reach delay offset jitter
==============================================================================
127.127.22.0 .PPS. 0 l - 16 0 0.000 0.000 0.000
127.127.28.0 .NMEA. 3 l - 16 0 0.000 0.000 0.000
Code: Select all
pi@myStratum1:~ $ dmesg | grep pps
[ 3.096409] pps_core: LinuxPPS API ver. 1 registered
[ 3.096417] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[ 3.111760] pps pps0: new PPS source pps.-1
[ 3.111855] pps pps0: Registered IRQ 412 as PPS source
[ 64.919550] pps_ldisc: PPS line discipline registered
[ 64.923106] pps pps1: new PPS source ttyAMA0
[ 64.923236] pps pps1: source "/dev/ttyAMA0" added
Code: Select all
pi@myStratum1:~ $ cgps -s
+-------------------------------------------++---------------------------------+
| Time: 2016-03-10T06:29:00.000Z ||PRN: Elev: Azim: SNR: Used: |
| Latitude: xx.xxxxxx x || xx xx xxx xx Y |
| Longitude: xx.xxxxxx x || xx xx xxx xx Y |
| Altitude: xxxx.x ft || xx xx xxx xx Y |
| Speed: 0.0 mph || xx xx xxx xx Y |
| Heading: 0.0 deg (true) || xx xx xxx xx Y |
| Climb: 0.0 ft/min || xx xx xxx xx Y |
| Status: 3D FIX (2 secs) || xx xx xxx xx Y |
| Longitude Err: +/- x ft || xx xx xxx xx Y |
| Latitude Err: +/- x ft || xx xx xxx xx Y |
| Altitude Err: +/- xx ft || xx xx xxx xx Y |
| Course Err: n/a || xx xx xxx xx N |
| Speed Err: +/- xx mph || xx xx xxx xx N |
| Time offset: -27774.290 || |
| Grid Square: xxxxxx || |
+-------------------------------------------++---------------------------------+
cgps: caught signal 2
Code: Select all
pi@myStratum1:~ $ sudo 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 1457568421.095922675, sequence: 6277 - clear 0.000000000, sequence: 0
source 0 - assert 1457568422.095938675, sequence: 6278 - clear 0.000000000, sequence: 0
source 0 - assert 1457568423.095954675, sequence: 6279 - clear 0.000000000, sequence: 0
source 0 - assert 1457568424.095974675, sequence: 6280 - clear 0.000000000, sequence: 0
source 0 - assert 1457568425.095990675, sequence: 6281 - clear 0.000000000, sequence: 0
^C
Code: Select all
pi@myStratum1:~ $ cat /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
Code: Select all
pi@Stratum1:~ $ cat /boot/config.txt
# /boot/config.txt
init_uart_baud=9600
dtoverlay=pps-gpio,gpiopin=18
Code: Select all
pi@myStratum1:~ $ cat /etc/modules
# /etc/modules: kernel modules to load at boot time.
pps-gpio
Code: Select all
pi@myStratum1:~ $ cat /etc/default/gpsd
# /etc/default/gpsd
# Default settings for gpsd.
# change the options.
START_DAEMON="true"
GPSD_OPTIONS="-n"
DEVICES="/dev/ttyAMA0"
USBAUTO="false"
GPSD_SOCKET="/var/run/gpsd.sock"
Code: Select all
pi@myStratum1:~ $ cat /etc/ntp.conf
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift
# Kernel-mode PPS ref-clock for the precise seconds
server 127.127.22.0 minpoll 4 maxpoll 4 prefer
fudge 127.127.22.0 refid PPS stratum 0
# Server from shared memory provided by gpsd
server 127.127.28.0 minpoll 4 maxpoll 4
fudge 127.127.28.0 refid NMEA stratum 3 time1 0.510
# 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
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
restrict 127.0.0.1
restrict ::1
Code: Select all
pi@myStratum1:~ $ sudo apt-get -y install gpsd gpsd-clients
pi@myStratum1:~ $ sudo apt-get -y install pps-tools
pi@myStratum1:~ $ sudo apt-get -y install minicom ntpstat
pi@myStratum1:~ $ sudo service ntp stop
pi@myStratum1:~ $ sudo apt-mark hold ntp
pi@myStratum1:~ $ mkdir -p ~/ntp
pi@myStratum1:~ $ cd ~/ntp
pi@myStratum1:~ $ sudo apt-get install libcap-dev
pi@myStratum1:~ $ wget http://archive.ntp.org/ntp4/ntp-4.2/ntp-4.2.8p6.tar.gz
pi@myStratum1:~ $ tar xvfz ntp-4.2.8p6.tar.gz
pi@myStratum1:~ $ cd ntp-4.2.8p6/
pi@myStratum1:~ $ ./configure --enable-linuxcaps
pi@myStratum1:~ $ make
pi@myStratum1:~ $ sudo make install
pi@myStratum1:~ $ sudo cp /usr/local/bin/ntp* /usr/bin/ && sudo cp /usr/local/sbin/ntp* /usr/sbin/
pi@myStratum1:~ $ sudo service ntp start
EDIT few days later:
one step forwards, one steps backwards...
i found out, that the ntpd driver 28 for the virtual ip 127.127.28.0 starts to work only, when i connect a gpsd client to the gpsd once.
once that is done the time via NMEA (the gps data strings) acts as time source for ntp.
and also the ntp driver 22 for PPS virtual ip 127.127.28.0 starts to get being active from the view of ntp
(the /dev/pps0 is served by the kernel and is actively working all the time, only ntp takes notice of PPS after a gps client was connected to gpsd first)
the strange thing is, that the gpsd should start automatically, even without a connected gps-client
that what the documentation is telling...
Code: Select all
# /etc/default/gpsd
START_DAEMON="true"
GPSD_OPTIONS="-n"
to auto start the gpsd, i use as WORKAROUND an additional entry gpspipe -r -n 1 & in the /etc/rc.local file, just before the exit 0
Code: Select all
# /etc/rc.local
...
gpspipe -r -n 1 &
exit 0
anyhow, that works now... this was the step forwards.

that's, what i get now, after the RPi is booted up without a internet connection
Code: Select all
pi@myStratum1:~ $ ntpq -crv -pn
associd=0 status=0418 leap_none, sync_uhf_radio, 1 event, no_sys_peer,
version="ntpd 4.2.8p6@1.3265 Wed Mar 9 21:01:11 UTC 2016 (1)",
processor="armv6l", system="Linux/4.1.18+", leap=00, stratum=4,
precision=-19, rootdelay=0.000, rootdisp=1964.960, refid=SHM(0),
reftime=da903eb0.37b57464 Sun, Mar 13 2016 19:32:00.217,
clock=da903eb6.6399f39e Sun, Mar 13 2016 19:32:06.389, peer=60741, tc=4,
mintc=3, offset=22.803398, frequency=-15.352, sys_jitter=0.000000,
clk_jitter=15.239, clk_wander=0.000
remote refid st t when poll reach delay offset jitter
==============================================================================
x127.127.22.0 .PPS. 0 l 5 16 3 0.000 -71.439 13.025
*127.127.28.0 .NMEA. 3 l 6 16 7 0.000 22.803 20.441
the NMEA gps data are not very accurate in sync by nature of gps NMEA string handling.
(the strings arrives not very syncroniusly via serial port and there are many additional gps data where its amount depends on how many satelites are in view and the baud rate of serial connection).
so its jitter can be up to 500ms in average it is something around 300 ms.
that is good enough, to set the local date time to a correct value, but is far away to be very accurate as it should for a stratum1 ntp server.
the problem is now. the ntp keeps to stay at the NMEA source and does never switck to the very precise PPS clock source.
how can i force ntp to use the high precise PPS source, after ntp was taking the NMEA data to setup the date time.
it is written in the documentation, that the PPS is taking in account only in cases. that a "normal" time sounrce was reached - because a PPS itself serves only a signal, not a date time. but a date time source is the NMEA. so the minimum requirements are given to take the PPS in account.
but ntp ignores the PPS. (it is marked as "x" = "falsetick" and is never be used)
and the ntp service gives only the very inaccurate synced time of NMEA.
Code: Select all
pi@myStratum1:~ $ ntpstat
synchronised to UHF radio at stratum 4
time correct to within 365 ms
polling server every 16 s
how can i force ntp to use the high precise PPS in case there is no internet connection?


it should be like (as it is, when i have an internet connection and my local PPS is in use):
Code: Select all
pi@myStratum1:~ $ ntpstat
synchronised to atomic clock at stratum 1
time correct to within 0 ms
polling server every 16 s