Setting up an NTP server and receiving exact time from a GPS sensor

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&#91;5923&#93;: 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?

you need to setup DHCP option 42 with the ip of the NTP server you want the clients to use

Network>Interfaces>LAN>edit>DHCP Sever>Advanced Settings>DHCP-Options>42,192.168.0.1

3 Likes

This option is inserted directly into the active configuration file (/var/etc/ntpd.conf).
Remove it or use the actual physical interface name, e.g. br-lan.

2 Likes

Or do not bind ntpd to a particular interface at all, and use the firewall to limit access. The firewall by default will not allow access from the wan.

3 Likes

I'd advice to use chrony in place of ntpd.

2 Likes

Can you run

Can you run instead:

netstat -lp | grep ntp

The p will verify which processes. Did you ever explicitly disable the built-in system NTP?

Lastly, you asked:

Be advised that most OSes don't request or use DHCP Option No. 42 either. You can redirect 123/udp.

2 Likes

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:~#
The time server I set manually on each Windows PC 192.168.3.1 .

1 Like

I applied the option, but there is no time synchronization.

Replaced lan with br-lan, rebooted the router, no time synchronization.

Dear friends, IMHO, we need to look at how to configure ntp server on ntpd, because on sysntpd time synchronization worked, until I replaced sysntpd with ntpd to configure GPS.

Time clients connect from the lan (br-lan) side.

So you have to alow requests from that subnet? gps ntp connection seems good now.
If you have a linux client try ntpdate -q openwrt.lan

root@(none):~# ntpdate -q 127.0.0.1
15 Mar 14:27:32 ntpdate[3119]: no server suitable for synchronization found

Yeah, weird, huh? Try the router's lan address:

$ ss -tunlp | grep 123
udp   UNCONN 0      0                               *:123              *:*    users:(("ntpd",pid=16043,fd=3))

$ ntpdate -q 127.0.0.1
15 Mar 08:05:28 ntpdate[27620]: no server suitable for synchronization found

$ ntpdate -q 10.1.1.1
server 10.1.1.1, stratum 2, offset +0.000144, delay 0.02809
15 Mar 08:06:17 ntpdate[27732]: adjust time server 10.1.1.1 offset +0.000144 sec

root@OpenWrt:~# ntpq -pn
remote refid st t when poll reach delay offset jitter

127.127.28.0 .GPS. 0 l - 16 0 0.000 +0.000 0.000

root@OpenWrt:~# ntpdate -q 127.127.28.0
15 Mar 04:05:15 ntpdate[3825]: no server suitable for synchronization found

root@OpenWrt:~# ntpdate -q 127.0.0.1
server 127.0.0.1, stratum 16, offset +0.000038, delay 0.02629
15 Mar 04:05:44 ntpdate[3838]: no server suitable for synchronization found
root@OpenWrt:~#

root@OpenWrt:~# ntpdate -q 192.168.3.1
15 Mar 04:14:38 ntpdate[4059]: no server suitable for synchronization found
root@OpenWrt:~#

It appears later version of windows don't use this anymore, but did on older ones
I believe some devices like my VoIP phones still do use this which is why I still have it

Me need to sync Windows 10.

How do I set up chrony to get accurate time from the GPS sensor and distribute accurate time to customers?

the admin command line still works
net time \192.168.1.1 /set /yes

C:\Windows\system32>net time \192.168.3.1 /set /yes
The service is not running