Raspberry pi stratum 0 NTP server
HW
- Raspberry Pi 3
- SD card (200MB will do, yes, 200MB!)
- Waveshare MAX-M8Q GNSS HAT for Raspberry Pi
- Raspberry Pi official case for 3B+
SW
-
Download OpenWRT 24.10.5 openwrt-24.10.5-bcm27xx-bcm2710-rpi-3-squashfs-factory.img.gz, flash it on the SD card.
I find the squashfs more stable than the ext4 one, and it will cause less wear on the SD card. - Modify the
/boot/config.txt(config.txtin thebootpartition):... [all] # Place your custom settings here. dtoverlay=pps-gpio,gpiopin=18 ... - Disable the serial console (we need the serial port for the GPS) in
/boot/cmdline.txtconsole=tty1 root=PARTUUID=c8dca970-02 rootfstype=squashfs,ext4 rootwait - Assemble all the HW, and boot. The raspberry will have the
192.168.1.1address, but I prefer it to DHCP.uci set network.lan.proto=dhcp uci commit /etc/init.d/network restart - Setup a root password
root@OpenWrt:~# passwd Changing password for root New password: Bad password: too weak Retype password: passwd: password for root changed by root -
Setup
authorized_keysand disable root password login - Configure
hostnameuci set system.@system[0].hostname=pim-ntp uci commit echo pim-ntp > /proc/sys/kernel/hostname - Install the tools
opkg update uci set system.ntp.enable='0' uci commit /etc/init.d/sysntpd disable /etc/init.d/sysntpd stop opkg install ntpd ntp-utils ntpd kmod-pps-gpio gpsd gpsd-clients \ rsync nano coreutils-who zabbix-agentd python3-light /etc/init.d/ntpd enable - Configure gpsd
uci set gpsd.core.device='/dev/ttyAMA0' uci set gpsd.core.enabled='1' uci commit /etc/init.d/gpsd enable /etc/init.d/gpsd start - Check GPS connectivity :
cgps -s -u mshould showStatus 3D FIX - Configure ntp for using country specific servers:
uci delete system.ntp.server uci add_list system.ntp.server='0.ch.pool.ntp.org' uci add_list system.ntp.server='1.ch.pool.ntp.org' uci add_list system.ntp.server='2.ch.pool.ntp.org' uci add_list system.ntp.server='3.ch.pool.ntp.org' - Configure ntpd :
/etc/ntpd.d/gps.conf# GPS Serial data reference server 127.127.28.0 minpoll 4 maxpoll 4 fudge 127.127.28.0 time1 0.0 refid GPS # GPS PPS reference server 127.127.28.1 minpoll 4 maxpoll 4 prefer fudge 127.127.28.1 refid PPS - (Re-) Start
ntpd/etc/init.d/ntpd restart - Check GPS and PPS functionality :
root@pim-ntp:~# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== +SHM(0) .GPS. 0 l 13 16 377 0.000 +0.117 0.537 *SHM(1) .PPS. 0 l 12 16 377 0.000 +143.77 0.081 ch1.ntp.ynnk.de 210.65.119.71 2 u 4 64 1 14.490 +148.66 1.090 -ntp03.maillink. .PPS. 1 u 27 64 1 18.667 +146.12 4.040 +time.hb9gun.ch .DTS. 1 u 35 64 1 16.882 +148.64 1.001 i7.isp.theswiss .PPS. 1 u 5 64 1 16.474 +205.98 0.983 - A small animation :
watch ntpq -p(opkg install procps-ng-watch)
~~~
Question, remark, bug? Don't hesitate to contact me or report a bug.