Einen eigenen NTP Server betreiben der via GPS die genaue Zeit bereitstellt, klingt nach einer Aufgabe für einen Raspberry Pi. Dachten sich auch andere und so fand ich im Netz massig Anleitungen und Blogbeträge einen Stratum 1 NTP Server unter Rasbian einzurichten.
Allerdings habe ich keine für mich passende Anleitung gefunden, da sie entweder veraltert oder für ein anderes Raspi-Modell sind (o.ä). Aus den unten verlinkten Quellen habe ich allerdings alle Infos gewinnen können um das Projekt mit folgender Hard- Software zu realisieren:
- Rasbian 10 Buster
- Raspberry Pi 3B
- Mini NEO-7M/NEO-6M GPS Satellite Positioning Module 51
- Aktive GPS-Antenne mit SMA Anschluss 5m
Das GPS Modul hat alle benötigten Signale auf den Pins liegen. So habe ich die Platine mit dem Pi verbunden:
Nach dem üblichen betreiben der SD-Karte und aktivieren des SSH Servers habe ich als erstes das System geupdatetd und die benötigte Software installiert. Dabei fiel mir gleich wieder auf, dass Rasbian per default ohne brauchbaren Editor daherkommt. 😉
sudo apt update && sudo apt full-upgrade -y && sudo apt install vim pps-tools ntp gpsd gpsd-clients -y
Danach wird mit sudo raspi-config
Hostname, Locales und Zeitzone konfiguriert. Danach muss (wichtig) unter „5 Interfacing Options“ unter „P6 Serial“ die serial login shell is aus und das serial interface is eingeschaltet werden. Danach muss der PI neugestartet werden.
Da wir ja auch nen vernünftigen Editor installiert haben, können wir nun auch mal ein paar Config-Dateien anpassen. Los geht es mit der /boot/config.txt
der folgende Zeile hinzugefügt wird:
dtoverlay=pps-gpio,gpiopin=18
Gpsd wird in /etc/default/gpsd konfiguriert:
START_DAEMON="true"
USBAUTO="false"
DEVICES="/dev/ttyS0"
GPSD_OPTIONS="-n"
Dann noch pps-gpio
in /etc/modules
hinzufügen.
Nach einem Neustart kann man mit sudo systemctl status gpsd
überprüfen ob der Dienst korrekt geladen ist.
Das war allerdings bei mir nicht der Fall, abhilfe schaffte folgender Symlink:
sudo ln -s /lib/systemd/system/gpsd.service /etc/systemd/system/multi-user.target.wants/
# Quelle: https://www.raspberrypi.org/forums/viewtopic.php?f=45&t=53644#p1048128
Mit cgps -s
kann nun die GPS Funktionalität überprüft werden.
Nach dem Neustart sollten auch schon die PPS Module geladen sein:
ices@gallifrey:~ $ sudo lsmod|grep pps
pps_ldisc 16384 2
pps_gpio 16384 0
pps_core 20480 3 pps_gpio,pps_ldisc
Ob das PPS Gerät korrekt gefunden wurde überprüft ihr mit:
ices@gallifrey:~ $ sudo dmesg|grep pps
[ 3.112334] pps_core: LinuxPPS API ver. 1 registered
[ 3.114527] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[ 3.129709] pps pps0: new PPS source pps@12.-1
[ 3.132327] pps pps0: Registered IRQ 166 as PPS source
[ 10.106947] pps_ldisc: PPS line discipline registered
[ 10.111550] pps pps1: new PPS source serial0
[ 10.111685] pps pps1: source "/dev/ttyS0" added
Ob das PPS Device ordnungsgemäß funktioniert kann mit dem Befehl ppstest /dev/pps0
getestet werden.
Jetzt muss nur noch die /etc/ntp.conf
angepasst werden:
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help driftfile /var/lib/ntp/ntp.drift # Leap seconds definition provided by tzdata leapfile /usr/share/zoneinfo/leap-seconds.list # 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 time01.thenetworknerds.ca iburst server ntp.wien.diakoniewerk.at iburst server 6.ntp.snails.email 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 limited restrict -6 default kod notrap nomodify nopeer noquery limited # Local users may interrogate the ntp server more closely. restrict 127.0.0.1 restrict ::1 # Needed for adding pool entries restrict source notrap nomodify 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 ###################################################### tinker step 0.4 stepback 0.4 stepfwd 0.4 server 127.127.22.0 minpoll 4 maxpoll 4 fudge 127.127.22.0 refid PPS stratum 0 flag3 1 flag4 1 server 127.127.28.0 minpoll 4 maxpoll 4 prefer fudge 127.127.28.0 time1 +0.130 refid GPS stratum ######################################################
Nach einem Neustart des NTP Dienstes (sudo systemctl restart ntp
) können wir nun auch unseren eigenen Stratum 1 NTP Server testen. 🙂
ices@gallifrey:~ $ ntpq -c peers -c rv remote refid st t when poll reach delay offset jitter ============================================================================== oPPS(0) .PPS. 0 l 16 16 377 0.000 0.005 0.002 *SHM(0) .GPS. 2 l 15 16 377 0.000 4.334 3.659 194.50.19.3 .INIT. 16 u - 1024 0 0.000 0.000 0.000 193.170.62.252 .INIT. 16 u - 1024 0 0.000 0.000 0.000 li1487-219.memb .INIT. 16 u 841 1024 0 0.000 0.000 0.000 associd=0 status=01f8 leap_none, sync_pps, 15 events, no_sys_peer, version="ntpd 4.2.8p12@1.3728-o (1)", processor="armv7l", system="Linux/4.19.58-v7+", leap=00, stratum=1, precision=-19, rootdelay=0.000, rootdisp=1.000, refid=PPS, reftime=e10020ef.6b549b3f Thu, Aug 15 2019 20:20:31.419, clock=e10020ef.7ffc20bf Thu, Aug 15 2019 20:20:31.499, peer=58555, tc=4, mintc=3, offset=0.004137, frequency=-4.528, sys_jitter=0.001907, clk_jitter=0.003, clk_wander=0.004, tai=37, leapsec=201701010000, expire=201912280000
Viel Spaß beim nachbasteln! 🙂
# Quellen:
# https://www.bayreuth.tk/de/linux-und-bsd/raspberry-pi-stratum-1-ntp-server.html
# https://blog.webernetz.net/ntp-server-via-gps-on-a-raspberry-pi/
# https://frillip.com/raspberry-pi-stratum-1-ntp-server/
# https://www.meinberg.de/german/info/ntp.htm
# Produke:
# Mini NEO-7M/NEO-6M GPS Satellite Positioning Module 51 (eBay)
# Aktive GPS-Antenne mit SMA Anschluss 5m (Amazon)