Setting up an NTP server and receiving exact time from a GPS sensor.
There is a GPS sensor ID 1546:01a7 u-blox AG - www.u-blox.com u-blox 7 - GPS/GNSS Receiver, router GL.iNet GL-AR150, with OpenWrt 24.10.0 r28427-6df0e3d02a / LuCI openwrt-24.10 branch 25.014.55016~7046a1c.
According to the recommendations from GPS and NTP Settings the following packages were installed:
opkg update && opkg install kmod-usb-acm gpsd gpsd-clients ntpd ntp-utils ntpdate usbutils openssh-sftp-server , then the following files were edited according to the recommendations:
cat /etc/config/gpsd
config gpsd core
option device "/dev/ttyACM0"
option port "2947"
option listen_globally "true"
option enabled "true"[/code]
/etc/ntpd.conf
let's add to it:
# GPS
server 127.127.28.0 minpoll 4 prefer
fudge 127.127.28.0 refid GPS
Restrict 127.0.0.1 [/code]
/etc/config/system
config system
option hostname 'OpenWrt'
option ttylogin '0'
option log_size '128'
option urandom_seed '0'
option zonename 'Etc/GMT-5'
option log_proto 'udp'
option conloglevel '8'
option cronloglevel '7'
option timezone '<+05>-5'
config timeserver 'ntp'
system.ntp=timeserver
option enable_server='1'
system.ntp.enable_server='1'
option interface='br-lan'
# system.ntp.server='0.openwrt.pool.ntp.org'
/etc/init.d/ntpd
find the lines
emit "\n# No limits for local monitoring"
emit "restrict 127.0.0.1"
emit "restrict -6 ::1\n"
and after them we add
emit "\n# GPS"
emit "server 127.127.28.0 minpoll 4 prefer"
emit "fudge 127.127.28.0 refid GPS\n" [/code]
Stop and disable the sysntpd daemon /etc/init.d/sysntpd stop && sleep 2 && /etc/init.d/sysntpd disable
Restart ntpd and gpsd: killall -9 gpsd ntpd
/etc/init.d/gpsd start && sleep 2 && /etc/init.d/ntpd start
We check the operation of the GPS sensor, what it catches and displays:
cgps -s -u m
Conclusion:
lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqklqqqqqqqqqqqqqqqqSeen 19/Used 4qqk
x Time 2025-03-10T04:22:28.000Z (18)xxGNSS S PRN Elev Azim SNR Usex
x Latitude 67.97179200 N xxGP 13 13 44.0 267.0 31.0 Y x
x Longitude 75.97769070 E xxGP 14 14 56.0 231.0 26.0 Y x
x Alt (HAE, MSL) 35.162, 49.363 m xxGP 15 15 30.0 310.0 25.0 Y x
x Speed 0.18 km/h xxGP 22 22 38.0 242.0 26.0 Y x
x Track (true, var) 349.1, 23.9 deg xxGP 1 1 10.0 124.0 0.0 N x
x Climb 7.86 m/min xxGP 2 2 27.0 111.0 0.0 N x
x Status 3D FIX (9 secs) xxGP 7 7 28.0 151.0 0.0 N x
x Long Err (XDOP, EPX) 6.49, +/- 97.3 m xxGP 8 8 40.0 70.0 0.0 N x
x Lat Err (YDOP, EPY) 1.99, +/- 29.9 m xxGP 10 10 12.0 33.0 0.0 N x
x Alt Err (VDOP, EPV) 8.97, +/- 206 m xxGP 17 17 13.0 195.0 21.0 N x
x 2D Err (HDOP, CEP) 6.99, +/- 132 m xxGP 23 23 22.0 352.0 0.0 N x
x 3D Err (PDOP, SEP) 11.38, +/- 216 m xxGP 27 27 12.0 46.0 0.0 N x
x Time Err (TDOP) 9.36 xxGP 30 30 55.0 181.0 12.0 N x
x Geo Err (GDOP) 14.73 xxSB124 37 4.0 237.0 0.0 N x
x Speed Err (EPS) +/- 7.0 km/h xxSB126 39 5.0 233.0 0.0 N x
x Track Err (EPD) n/a xxSB127 40 12.0 202.0 0.0 N x
x Time offset 0.016400649 s xxQZ 1 193 n/a 0.0 0.0 N x
x Grid Square MP77xx73 xxQZ 3 195 n/a 0.0 0.0 N x
x ECEF X, VX 581307.740 m 0.010 m/sxxQZ 4 196 n/a 0.0 0.0 N x
x ECEF Y, VY 2327636.630 m 0.000 m/sxx x
x ECEF Z, VZ 5889946.300 m 0.140 m/sxx x
x xx x
Checking the operation of the daemon:
root@OpenWrt:~# ntpq -pn
remote refid st t when poll reach delay offset jitter
===================================================================================
*127.127.28.0 .GPS. 0 l 15 16 377 0.000 -0.210 1.149
root@OpenWrt:~# ntpdate -q 127.0.0.1
server 127.0.0.1, stratum 1, offset +0.001746, delay 0.03020
10 Mar 04:26:44 ntpdate[5923]: adjust time server 127.0.0.1 offset +0.001746 sec
Ports:
root@OpenWrt:~# netstat -lp | grep ntp
udp 0 0 localhost:ntp 0.0.0.0:* 2981/ntpd
udp 0 0 0.0.0.0:ntp 0.0.0.0:* 2981/ntpd
udp 0 0 localhost:ntp :::* 2981/ntpd
udp 0 0 :::ntp :::* 2981/ntpd
root@OpenWrt:~#
root@OpenWrt:~# ntpdate -u 127.0.0.1
14 Mar 15:39:11 ntpdate
root@OpenWrt:~#
As a result of these settings on the router itself, the time from the GPS sensor is synchronized when the daemon is restarted
/etc/init.d/ntpd restart
but other computers on the network cannot synchronize from the router; the computers write that the timeout for a response from the NTP server has expired.
Question - how to configure OpenWrt demon ntpd so that computers on the local network 192.168.3.0/24 can synchronize their time from the NTP server on the router?