What's new

NTP Daemon for ASUSWRT/Merlin

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Things have changed since this thread was started, files are missing from the GPS instructions
Just curious if this works.
Code:
cd /tmp
wget https://github.com/blackfuel/asuswrt-merlin-addon/raw/master/staging/bin/ntpd
opkg update
opkg install coreutils-sha256sum
[ "$(sha256sum ntpd | cut -d' ' -f1)" == "885f0ab1f7885cf8772be02a81a9ad724bf48ae2acce23377496c076b3f27693" ] && echo good || echo bad
# ./ntpd --version
 
Thanks, I have put the output below.
Just curious if this works.
Code:
login as: GoNz0
Authenticating with public key "SSH RSA Private"


ASUSWRT-Merlin RT-AC68U 380.67-0 Sun Jul 16 16:56:04 UTC 2017
GoNz0@Router:/tmp/home/root# cd /tmp
GoNz0@Router:/tmp# wget https://github.com/blackfuel/asuswrt-merlin-addon/raw/ma
ster/staging/bin/ntpd
--2017-07-26 13:42:26--  https://github.com/blackfuel/asuswrt-merlin-addon/raw/master/staging/bin/ntpd
Resolving github.com... 192.30.253.112, 192.30.253.113
Connecting to github.com|192.30.253.112|:443... connected.
ERROR: cannot verify github.com's certificate, issued by 'CN=DigiCert SHA2 Extended Validation Server CA,OU=www.digicert.com,O=DigiCert Inc,C=US':
  Unable to locally verify the issuer's authority.
To connect to github.com insecurely, use `--no-check-certificate'.
GoNz0@Router:/tmp# opkg update
Downloading http://pkg.entware.net/binaries/armv7/Packages.gz
Updated list of available packages in /opt/var/opkg-lists/packages
GoNz0@Router:/tmp# opkg install coreutils-sha256sum
Installing coreutils-sha256sum (8.23-2) to root...
Downloading http://pkg.entware.net/binaries/armv7/coreutils-sha256sum_8.23-2_armv7soft.ipk
Installing coreutils (8.23-2) to root...
Downloading http://pkg.entware.net/binaries/armv7/coreutils_8.23-2_armv7soft.ipk
Configuring coreutils.
Configuring coreutils-sha256sum.
GoNz0@Router:/tmp# [ "$(sha256sum ntpd | cut -d' ' -f1)" == "885f0ab1f7885cf8772
be02a81a9ad724bf48ae2acce23377496c076b3f27693" ] && echo good || echo bad
sha256sum: ntpd: No such file or directory
bad
GoNz0@Router:/tmp# # ./ntpd --version
GoNz0@Router:/tmp# cd /tmp
GoNz0@Router:/tmp# wget https://github.com/blackfuel/asuswrt-merlin-addon/raw/ma
ster/staging/bin/ntpd --no-check-certificate
--2017-07-26 13:44:54--  https://github.com/blackfuel/asuswrt-merlin-addon/raw/master/staging/bin/ntpd
Resolving github.com... 192.30.253.113, 192.30.253.112
Connecting to github.com|192.30.253.113|:443... connected.
WARNING: cannot verify github.com's certificate, issued by 'CN=DigiCert SHA2 Extended Validation Server CA,OU=www.digicert.com,O=DigiCert Inc,C=US':
  Unable to locally verify the issuer's authority.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/blackfuel/asuswrt-merlin-addon/master/staging/bin/ntpd [following]
--2017-07-26 13:44:55--  https://raw.githubusercontent.com/blackfuel/asuswrt-merlin-addon/master/staging/bin/ntpd
Resolving raw.githubusercontent.com... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...
Connecting to raw.githubusercontent.com|151.101.0.133|:443... connected.
WARNING: cannot verify raw.githubusercontent.com's certificate, issued by 'CN=DigiCert SHA2 High Assurance Server CA,OU=www.digicert.com,O=DigiCert Inc,C=US':
  Unable to locally verify the issuer's authority.
HTTP request sent, awaiting response... 200 OK
Length: 527052 (515K) [application/octet-stream]
Saving to: 'ntpd'

ntpd                100%[===================>] 514.70K  --.-KB/s    in 0.1s

2017-07-26 13:44:56 (3.81 MB/s) - 'ntpd' saved [527052/527052]

GoNz0@Router:/tmp# opkg update
Downloading http://pkg.entware.net/binaries/armv7/Packages.gz
Updated list of available packages in /opt/var/opkg-lists/packages
GoNz0@Router:/tmp# opkg install coreutils-sha256sum
Package coreutils-sha256sum (8.23-2) installed in root is up to date.
GoNz0@Router:/tmp# [ "$(sha256sum ntpd | cut -d' ' -f1)" == "885f0ab1f7885cf8772
be02a81a9ad724bf48ae2acce23377496c076b3f27693" ] && echo good || echo bad
good
GoNz0@Router:/tmp# # ./ntpd --version

Code:
Jul 26 15:22:01 ntpd[1113]: ntpd 4.2.8p9-win@1.3728 Sat Mar 18 09:20:25 UTC 2017 (2): Starting
Jul 26 15:22:01 ntpd[1113]: Command line: ntpd -c /jffs/etc/ntp.conf
Jul 26 15:22:01 ntpd[1119]: proto: precision = 1.652 usec (-19)
Jul 26 15:22:01 ntpd[1119]: Listen normally on 0 lo 127.0.0.1:123
Jul 26 15:22:01 ntpd[1119]: Listen normally on 1 br0 192.168.1.1:123
Jul 26 15:22:01 ntpd[1119]: Listening on routing socket on fd #18 for interface updates
Jul 26 15:22:01 ntpd[1119]: refclock 127.127.20.0 isn't supported. ntpd was compiled without refclock support.
Jul 26 15:22:01 ntpd[1119]: 127.127.20.0 local addr 127.0.0.1 -> <null>
Jul 26 15:22:01 ntpd[1119]: refclock 127.127.28.0 isn't supported. ntpd was compiled without refclock support.
Jul 26 15:22:01 ntpd[1119]: 127.127.28.0 local addr 127.0.0.1 -> <null>
Jul 26 15:22:02 GoNz0: Started ntpd from .

Also wondering what that scripts meant to do? :)
 
Last edited:
Also wondering what that scripts meant to do? :)
Try my script to set your router clock, here: https://www.snbforums.com/threads/usb-gps-instead-of-ntp.39806

Use the Busybox NTP server included with Asuswrt-Merlin to serve your NTP clients, here: /usr/sbin/ntpd

It's proof you don't need another NTP server.

Is this the trouble?
Code:
opkg update
opkg install coreutils-stty
stty -F /dev/ttyACM0 9600 raw -clocal -echo icrnl
cat /dev/ttyACM0
 
Last edited:
Try my script to set your router clock, here: https://www.snbforums.com/threads/usb-gps-instead-of-ntp.39806

Use the Busybox NTP server included with Asuswrt-Merlin to serve your NTP clients, here: /usr/sbin/ntpd

It's proof you don't need another NTP server.

Is this what's trouble you?
Code:
opkg update
opkg install coreutils-stty
stty -F /dev/ttyACM0 raw ispeed 9600 ospeed 9600 cs8 -ignpar -cstopb eol 255 eof 255
cat /dev/ttyACM0
I tried your script yesterday and it still failed to see the GPS?
 
Not had the chance (or will power) to do this yet, I need a few days not staring at router console windows to regain my sanity :D

If this fails I may look into doing it on my windows server instead or sack it off as a bad idea :(
I'm starting over using a Raspberry Pi with Arch Linux. It has fast startup because there is no graphical window environment. It boots in under 10 seconds.

Is there a way to configure the Linux hotplug rules in AsusWRT? This makes it easy. My Pi has an I2C RTC and the same USB GPS as you. From a cold start, it automatically sets the system clock from the RTC at boot, configures the USB GPS to report only $GPZDA, and then starts an NTP server configured for Generic NMEA only.

/etc/udev/rules.d/raspberrypi.rules
Code:
ACTION=="add", KERNEL=="ttyACM*", SUBSYSTEM=="tty", ATTRS{idProduct}=="01a7", ATTRS{idVendor}=="1546", RUN+="/bin/bash /lib/udev/usbgps-start /dev/ttyACM%n"
ACTION=="add", KERNEL=="rtc*", RUN+="/bin/hwclock --hctosys --rtc /dev/rtc%n"

/lib/udev/usbgps-start
Code:
#!/bin/bash
GPS_DEVICE="$1"

# NTP server Generic NMEA driver
rm -rf /dev/gps0
ln -s $GPS_DEVICE /dev/gps0

# configure the u-blox7 GPS to report only $GPZDA
stty -F $GPS_DEVICE 9600 raw -clocal -echo icrnl
ubx_write() {
  local cmdline=" $@"
  local fmtline="${cmdline// /\\x}"
  printf $fmtline >$GPS_DEVICE
}
ubx_write "B5 62 06 02 0A 00 01 00 00 00 00 00 00 00 00 87 9A 77" # Turn off info messages
ubx_write "B5 62 06 01 08 00 F0 00 00 00 00 00 00 00 FF 23" # Disable: NMEA GxGGA
ubx_write "B5 62 06 01 08 00 F0 01 00 00 00 00 00 00 00 2A" # Disable: NMEA GxGLL
ubx_write "B5 62 06 01 08 00 F0 02 00 00 00 00 00 00 01 31" # Disable: NMEA GxGSA
ubx_write "B5 62 06 01 08 00 F0 03 00 00 00 00 00 00 02 38" # Disable: NMEA GxGSV
ubx_write "B5 62 06 01 08 00 F0 04 00 00 00 00 00 00 03 3F" # Disable: NMEA GxRMC
ubx_write "B5 62 06 01 08 00 F0 05 00 00 00 00 00 00 04 46" # Disable: NMEA GxVTG
ubx_write "B5 62 06 01 08 00 F0 06 00 00 00 00 00 00 05 4D" # Disable: NMEA GxGRS
ubx_write "B5 62 06 01 08 00 F0 07 00 00 00 00 00 00 06 54" # Disable: NMEA GxGST
ubx_write "B5 62 06 01 08 00 F0 08 01 01 01 01 01 00 0C 6F" # Enable: NMEA GxZDA
ubx_write "B5 62 06 01 08 00 F0 09 00 00 00 00 00 00 08 62" # Disable: NMEA GxGBS
ubx_write "B5 62 06 01 08 00 F0 0A 00 00 00 00 00 00 09 69" # Disable: NMEA GxDTM
ubx_write "B5 62 06 01 08 00 F0 0D 00 00 00 00 00 00 0C 7E" # Disable: NMEA GxGNS
ubx_write "B5 62 06 01 08 00 F0 0E 00 00 00 00 00 00 0D 85" # Disable: NMEA GxTHS
ubx_write "B5 62 06 01 08 00 F0 0F 00 00 00 00 00 00 0E 8C" # Disable: NMEA GxVLW
#ubx_write "B5 62 06 09 0D 00 00 00 00 00 FF FF 00 00 00 00 00 00 01 1B A9" # Save settings to BBR (battery-backed RAM)
ubx_write "B5 62 06 09 0D 00 00 00 00 00 FF FF 00 00 00 00 00 00 03 1D AB" # Save settings to BBR,Flash

#sleep 1
systemctl restart ntpd


/etc/ntp.conf
Code:
# By default, the server allows:
# - all queries from the local host
# - only time queries from remote hosts, protected by rate limiting and kod
restrict default kod limited nomodify nopeer noquery notrap
restrict 127.0.0.1
restrict ::1

# Location of drift file
driftfile /var/lib/ntp/ntp.drift
logfile /var/log/ntp.log

# Configure orphan mode to be stratum 14
# https://www.eecis.udel.edu/~mills/ntp/html/orphan.html
# https://www.eecis.udel.edu/~mills/ntp/html/miscopt.html#tos
tos orphan 14 orphanwait 120

# Generic NMEA GPS Receiver
#  mode is 9600 baud + only $GPZDA
#  /dev/gps0 for NMEA
# https://www.eecis.udel.edu/~mills/ntp/html/drivers/driver20.html
# https://www.eecis.udel.edu/~mills/ntp/html/clockopt.html
server 127.127.20.0 mode 24 minpoll 4 prefer
fudge 127.127.20.0 flag1 0 # Disable PPS signal processing
fudge 127.127.20.0 flag4 1 # Obscures location in timecode

# Undisciplined Local Clock
# https://www.eecis.udel.edu/~mills/ntp/html/drivers/driver1.html
# https://www.eecis.udel.edu/~mills/ntp/html/clockopt.html
server 127.127.1.0
fudge 127.127.1.0 stratum 15

# Please consider joining the pool:
#
#     http://www.pool.ntp.org/join.html
#
# For additional information see:
# - https://wiki.archlinux.org/index.php/Network_Time_Protocol_daemon
# - http://support.ntp.org/bin/view/Support/GettingStarted
# - the ntp.conf man page

# Associate to Arch's NTP pool
#server 0.arch.pool.ntp.org
#server 1.arch.pool.ntp.org
#server 2.arch.pool.ntp.org
#server 3.arch.pool.ntp.org


Example: My USB GPS has lost it's satellite fix, so the NTP server switches to Orphan Mode and it's still serving time to local clients. It has failed over from the GPS to the Undisciplined Local Clock. When I put the USB GPS back in the window, it will re-acquire the satellites and the NTP server will switch back to the reference clock mode.
Code:
# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 GPS_NMEA(0)     .GPS.            0 l    -   16    0    0.000    0.000   0.000
 LOCAL(0)        .LOCL.          15 l   28   64  377    0.000    0.000   0.002


Example: What can happen
DSCF4425a.jpg

You don't want this.
 
Last edited:
I'm starting over using a Raspberry Pi with Arch Linux. It has fast startup because there is no graphical window environment. It boots in under 10 seconds.

Is there a way to configure the Linux hotplug rules in AsusWRT? This makes it easy. My Pi has an I2C RTC and the same USB GPS as you. From a cold start, it automatically sets the system clock from the RTC at boot, configures the USB GPS to report only $GPZDA, and then starts an NTP server configured for Generic NMEA only.

Nice :)

Just keep in mind that a cold-start on the GPS unit - might take a while depending on the GPS almanac...

Warm Start - with a good time reference, which the RTC mod on the RPi provides, things should run fairly fast.

With the Pi, RTC hat, and GPS on the Pi - use it as the timebase as an NTP server.
 
Just keep in mind that a cold-start on the GPS unit - might take a while depending on the GPS almanac...
The DS3231 real-time clock has a temperature compensated oscillator, and goes for weeks without significant drift. Almost don't need a GPS, except now it's real easy to set the RTC from the GPS by typing, hwclock -w.
 
The DS3231 real-time clock has a temperature compensated oscillator, and goes for weeks without significant drift. Almost don't need a GPS, except now it's real easy to set the RTC from the GPS by typing, hwclock -w.

the TCXO is nice on that device ;)

(TCXO's are commonly used on mobile phones - and they're fairly precise, and they're generally backed up by WWAN system time when they sync up to the network)

time geeks - they're going to look at the GPS though - once the GPS is hot and running, and PPS in place - it's going to be a very steady source.

For me - the solution you mention is likely good enough - and then make it the ntp source for the rest of the LAN to keep everything sync'ed up.
 
Last edited:
Try my script to set your router clock, here: https://www.snbforums.com/threads/usb-gps-instead-of-ntp.39806

Use the Busybox NTP server included with Asuswrt-Merlin to serve your NTP clients, here: /usr/sbin/ntpd

It's proof you don't need another NTP server.

Is this the trouble?
Code:
opkg update
opkg install coreutils-stty
stty -F /dev/ttyACM0 9600 raw -clocal -echo icrnl
cat /dev/ttyACM0
I did try, the problem is it doesn't detect the GPS like it does on yours, the best I can get is the stock ntpd install will work but only with the PPS output, it never shows the GPS being active like yours.
 
I did try, the problem is it doesn't detect the GPS like it does on yours, the best I can get is the stock ntpd install will work but only with the PPS output, it never shows the GPS being active like yours.
My router where I use GPS+PPS requires a Linux kernel change to AsusWRT (my brother Jon did it), and I'm using an RY835AI GPS receiver, inside a homemade weatherproof enclosure, mounted up on the roof of the building. However, you don't need to be within microseconds of standard time. Your u-blox7 USB GPS hanging in a side window is good enough to give millisecond accuracy without PPS. So I bought this little u-blox7 USB GPS that you had asked about, and I got it working with only the stock AsusWRT firmware.
 
My router where I use GPS+PPS requires a Linux kernel change to AsusWRT (my brother Jon did it), and I'm using an RY835AI GPS receiver, inside a homemade weatherproof enclosure, mounted up on the roof of the building. However, you don't need to be within microseconds of standard time. Your u-blox7 USB GPS hanging in a side window is good enough to give millisecond accuracy without PPS. So I bought this little u-blox7 USB GPS that you had asked about, and I got it working with only the stock AsusWRT firmware.
So I can only expect PPS output on it?
 
So I can only expect PPS output on it?
U-blox7 USB GPS is no PPS. If PPS is something you need, I would build it myself from scratch. Maybe ask someone in your local area if you don't know how.

Anyway, the Linux kernel would need to be configured to trigger an interrupt on the PPS signal... so he knows exactly when the second begins for a timecode. It's probably 1/10 microsecond accuracy.
 
U-blox7 USB GPS is no PPS. If PPS is something you need, I would build it myself from scratch. Maybe ask someone in your local area if you don't know how.

Anyway, the Linux kernel would need to be configured to trigger an interrupt on the PPS signal... so he knows exactly when the second begins for a timecode. It's probably 1/10 microsecond accuracy.
Even more confused now, when I did ntpq -p the GPS was nowhere in sight just PPSt (I named it PPStest but assume it got truncated)
 
@kvic could you please implement the changes to the webUI in the manual installation guide? Starting with @RMerlin's 380.68 alpha2 there have been significant changes to the code behind the webUI, causing your (helpful) instruction to be outdated regarding the modifications to the Tools > Other Settings page. More info here: https://www.snbforums.com/threads/alpha-asuswrt-rmerlin-380-68-pre-release.40480/#post-339243

@thelonelycoder, if I'm not mistaking, you were writing an install script right? Any updates? I assume you will incorporate the changes above as well when it's ready to release?
 
@kvic could you please implement the changes to the webUI in the manual installation guide? Starting with @RMerlin's 380.68 alpha2 there have been significant changes to the code behind the webUI, causing your (helpful) instruction to be outdated regarding the modifications to the Tools > Other Settings page. More info here: https://www.snbforums.com/threads/alpha-asuswrt-rmerlin-380-68-pre-release.40480/#post-339243

@thelonelycoder, if I'm not mistaking, you were writing an install script right? Any updates? I assume you will incorporate the changes above as well when it's ready to release?
Kvic hasn't been on for a couple of months, I sent him a message last week but no answer, someone who can code may want to take it on if we are lucky.

Sent from my SM-G920F using Tapatalk
 
Kvic hasn't been on for a couple of months, I sent him a message last week but no answer, someone who can code may want to take it on if we are lucky.

Yes, true. That's why I included the request towards @thelonelycoder, as (if I recall correctly) he was writing an install script to simplify things, but it wasn't ready for release.

In the meantime, just bookmark http://router.asus.com/Tools_NtpdStats.asp or https://router.asus.com/Tools_NtpdStats.asp so you can still access the page, it just won't show up at the Tools page.

Edit: Had to check, before I asked the wrong person, as my memory is playing hide and seek, but I found the post a few pages back. Unfortunately, he's probably busy with the latest release of AB-Solution and the user feedback, so this will probably have to wait...

I just made a complete installer script for all that and it appers to work.
Not ready for release though.
 
Last edited by a moderator:

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top