offset - BYO-NTP/recipes GitHub Wiki

INSTALL

curl -O https://byo-ntp.github.io/tools/ntp-offset.sh
chmod 755 ntp-offset.sh

source code, discussion

USAGE

#tooSoon

./ntp-offset.sh NMEA
    Calculating offset for NMEA in /var/log/ntpsec/peerstats
    74.5247 ms
./ntp-offset.sh PPS
    No matching records

After at least an hour

./ntp-offset.sh PPS
Calculating offset for PPS in /var/log/chrony/statistics.log
0.0100531 ms
./ntp-offset.sh NMEA
Calculating offset for NMEA in /var/log/chrony/statistics.log
-1.23626 ms

TIPS

  • Assure statistics are logging (default)
  • Get the NTP daemon synced to 3 peers (default)
    • start up ntpd
    • wait 11+ minutes (w/iburst) or several hours (w/o iburst)
    • check with ntpq -c pe. Assure ntpd has locked onto a *remote and the offset is in the single digits.
  • Assure your GPS has a fix
  • add "stratum 16" to the refclocks so ntpd ignores them
    • use noselect
    • time1 = time2 = 0.0
    • collect data for 1+ hours
➜ ./ntp-offset.sh PPS
Calculating offset for PPS in /var/log/ntp/peerstats
-101.659 ms

➜ ./ntp-offset.sh NMEA
Calculating offset for NMEA in /var/log/ntp/peerstats
-135.343 ms

What's this you say? 101 ms offset for a PPS signal? Yep, this is a LEA-M8T attached via a FTDI USB (2.0) serial adapter. USB has a latency penalty and serial ports are less common in 2025.

  • Edit ntp.conf
    • set NMEA time2 0.135
    • set PPS time1 0.101
    • remove 'stratum 16' from both lines
    • add 'prefer' to the NMEA line
    • restart ntpd
  • wait some minutes...
    • gaze at the beauty:
➜ ntpq -c pe
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ ************** *************    3 u    7   32  177    2.821   +0.460   0.730
+ ************** *************    2 u    5   32  177   64.117   -0.495   0.922
+ ************** *************    2 u   18   32  177   56.308   +2.900   3.770
*NMEA(0)         .NMEA.           0 l   18   64   17    0.000  -42.674  33.344
oPPS(0)          .PPS.            0 l    1   16  377    0.000   +0.375   0.151
  • disable statistics logging
    • especially if running off a SD card