Dismiss Notice

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

NTP Daemon for ASUSWRT/Merlin

Discussion in 'Asuswrt-Merlin' started by kvic, Nov 6, 2015.

  1. Fitz Mutch

    Fitz Mutch Senior Member

    Joined:
    May 27, 2016
    Messages:
    381
    Location:
    Portsmouth
    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
    
     
  2. GoNz0

    GoNz0 Very Senior Member

    Joined:
    Jul 14, 2013
    Messages:
    543
    Thanks, I have put the output below.
    Code:
    Jul 26 15:22:01 ntpd[1113]: ntpd [email protected] 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: Jul 26, 2017
  3. Fitz Mutch

    Fitz Mutch Senior Member

    Joined:
    May 27, 2016
    Messages:
    381
    Location:
    Portsmouth
    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: Jul 26, 2017
  4. GoNz0

    GoNz0 Very Senior Member

    Joined:
    Jul 14, 2013
    Messages:
    543
    I tried your script yesterday and it still failed to see the GPS?
     
  5. Fitz Mutch

    Fitz Mutch Senior Member

    Joined:
    May 27, 2016
    Messages:
    381
    Location:
    Portsmouth
    Last edited: Jul 27, 2017
  6. GoNz0

    GoNz0 Very Senior Member

    Joined:
    Jul 14, 2013
    Messages:
    543
    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 :(
     
  7. Fitz Mutch

    Fitz Mutch Senior Member

    Joined:
    May 27, 2016
    Messages:
    381
    Location:
    Portsmouth
    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=" [email protected]"
      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
    [​IMG]
    You don't want this.
     
    Last edited: Jul 31, 2017
  8. sfx2000

    sfx2000 Part of the Furniture

    Joined:
    Aug 11, 2011
    Messages:
    11,741
    Location:
    San Diego, CA
    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.
     
  9. Fitz Mutch

    Fitz Mutch Senior Member

    Joined:
    May 27, 2016
    Messages:
    381
    Location:
    Portsmouth
    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.
     
  10. sfx2000

    sfx2000 Part of the Furniture

    Joined:
    Aug 11, 2011
    Messages:
    11,741
    Location:
    San Diego, CA
    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: Jul 29, 2017
  11. GoNz0

    GoNz0 Very Senior Member

    Joined:
    Jul 14, 2013
    Messages:
    543
    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.
     
  12. Fitz Mutch

    Fitz Mutch Senior Member

    Joined:
    May 27, 2016
    Messages:
    381
    Location:
    Portsmouth
    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.
     
  13. GoNz0

    GoNz0 Very Senior Member

    Joined:
    Jul 14, 2013
    Messages:
    543
    So I can only expect PPS output on it?
     
  14. Fitz Mutch

    Fitz Mutch Senior Member

    Joined:
    May 27, 2016
    Messages:
    381
    Location:
    Portsmouth
    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.
     
  15. GoNz0

    GoNz0 Very Senior Member

    Joined:
    Jul 14, 2013
    Messages:
    543
    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)
     
  16. Fitz Mutch

    Fitz Mutch Senior Member

    Joined:
    May 27, 2016
    Messages:
    381
    Location:
    Portsmouth
    A few posts back I show my ntp.conf. And my ntpq -p shows only GPS_NMEA(0) and LOCAL(0). I use Orphan Mode to fail over to Local Clock when the GPS loses it's satellite fix or if it's unplugged. Also uploaded a picture of me. :)

    https://www.snbforums.com/threads/ntp-daemon-for-asuswrt-merlin.28041/page-16#post-338179
     
  17. GoNz0

    GoNz0 Very Senior Member

    Joined:
    Jul 14, 2013
    Messages:
    543
    I get the feeling it is to do with the USB modem driver it loads under as I can't get the GPS to show even with your conf file.
     
  18. MarCoMLXXV

    MarCoMLXXV Guest

    @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?
     
    eclp likes this.
  19. GoNz0

    GoNz0 Very Senior Member

    Joined:
    Jul 14, 2013
    Messages:
    543
    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
     
    MarCoMLXXV likes this.
  20. MarCoMLXXV

    MarCoMLXXV Guest

    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...

     
    Last edited by a moderator: Aug 5, 2017

Share This Page