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!

@JGrana here you're. I don't know how it works. I simply compiled in SHM clock as suggested by ASAT.

https://github.com/kvic-z/goodies-asuswrt/blob/master/ntpd_SHM.tar.gz

For testing, Entware has a ntpd package including all clock drivers. Worth a try in case the above doesn't work out for you.

Good news and bad news.... The good news is that the version you recompiled did show GPS or NMEA as a refid when I ran ntpq -p.

The bad news - it also showed no data being received. Even worse, I discovered that I was NOT running Entware-ng. The gpsd software I downloaded was through ipkg. It ran fine. I then tried to get the latest ntpd (as recommended above). No file found. This is when I realized I was way behind. I then installed Entware-ng. Good news - there is a more recent ntdp package. Bad news, there is no gpsd. And, the gpsd I had previously loaded no longer runs....

At this point I am going to take a breather (and clean up the router!!!). I have been doing some work on a new toy - a Banana Pi. I have ntpd and gpsd running fine with a GPS USB dongle.

Kvic - many thanks for your help!
 
In regards to the original stock ASUS ntp client, is it possible to disable it now that I will be using this implementation of ntp? If so, what would be the best method to accomplish this? I tried adding the following to my wan-start script:

# Immediately disable the router's NTP client program
killall ntp && sleep 1
nvram set ntp_ready=1
nvram unset ntp_server0
nvram unset ntp_server1
nvram unset ntp_server_tried

However, my system date was way off (July 31 forgot the year it showed) so this implementation of ntp would not sync. I had to reenable stock NTP from the GUI to get the time sync'ed correctly. Then, I was able to stop it and start up the custom ntp solution and it sync'ed no problem.

I am not sure if this means I need to leave stock NTP enabled for system boots. It seems like this implementation of ntp is not able to sync up on power-up/reboot and if you disable the stock version of ntp you will not be able to sync with this custom implementation until you change the time or as I did enable/disable stick ntp once the router is back up.

Running 68U w/ 380.57 firmware.
 
In regards to the original stock ASUS ntp client, is it possible to disable it now that I will be using this implementation of ntp? If so, what would be the best method to accomplish this?

Glad to see you thinking about this problem.

The stock NTP is required to set the correct time on boot as these routers do not have a RTC aka real-time clock. So we don't want to disable the stock NTP from GUI nor setting NVRAM values.

Once the router is booted up (with system time initialised). We no longer want to have the stock NTP and the custom NTPD running at the same time. The best moment to disable the stock NTP is when NTPD is launched. This is exactly what implemented in the package you download in #1.

Specifically in the launch script of NTPD, we kill off the stock NTP process first and then run NTPD. You can look there if you're curious.
 
Nice, enjoy!

If people like to experiment, you may delete the three lines containing "jquery" sub-string in /www/Tools_NtpdStats.asp. Do a backup of the file before the experiment..

I think this might work for all versions (<378.55, 378.55 and >378.55).

Running 380_57, either commenting out all three lines, or just the one "jQuery.noConflict();" line, both result in fixing the top, I can get to the tabs, however the "refresh" button on the bottom instead says "Are you sure you want to" and then is cut off below the button.

Also, thanks for this VERY cool tool. Very nice.
 
Last edited:
Running 380_57, either commenting out all three lines, or just the one "jQuery.noConflict();" line, both result in fixing the top, I can get to the tabs

You're absolutely right. jQuery call/module is actually not needed for this page. I came to the same realisation later. I was a web dev for 7 days when first creating this :D

however the "refresh" button on the bottom instead says "Are you sure you want to" and then is cut off below the button.

To support multi-lingual, ASUS uses numbers to represent actual text in ASUSWRT. The text of user select language will be substituted by httpd when the page is loaded.

We could imagine across different firmware versions, the same number may represent a different string. To be more exact, there is a better way for ASUS to preserve the mapping of numbers to text. They probably don't care and they may be right for a closed platform such as ASUSWRT.

To keep things simple for us, we can replace the number with an actual string in Tools_NtpdStats.asp e.g. look for the below snippet and have "value=" replace with "Refresh" instead of the numeric representation.

Code:
<input type="button" onClick=reload() value="Refresh" class="button_gen">

I may do a new packaging with the above two changes in a future time. To keep people's life easier with firmware upgrades..

Also, thanks for this VERY cool tool. Very nice.
:)
 
You're absolutely right. jQuery call/module is actually not needed for this page. I came to the same realisation later. I was a web dev for 7 days when first creating this :D
I'm not complaining at all. Did you sleep during those 7 days? :) Seems like you've accomplished a lot.
I may do a new packaging with the above two changes in a future time. To keep people's life easier with firmware upgrades..
Yeah ... I was kinda wondering about that. It seems to me that the really difficult part of being a software author of this sort is figuring out how to upgrade when new features are added or bugs are stomped.
 
I'm going to update ntp.conf with:
Code:
restrict br0
interface listen br0
So, I noticed I get an error message about "restrict br0" in my log on start. Restarting ntpd though, doesn't produce the error.

Digging into the ntp documentation, I found that an interface is not a legal argument for restrict. Restrict can only be the address of a host or network, or a valid hostname. (https://www.eecis.udel.edu/~mills/ntp/html/accopt.html#restrict) so "restrict br0" should never be valid.

Your lines;
Code:
interface ignore wildcard
interface listen br0
take care of only listening on br0 (if I understand the documentation correctly). I would suggest
Code:
restrict 127.0.0.1
restrict -6 ::1
restrict 127.127.1.0
in place of
Code:
restrict br0
as suggested by the ntp.conf file supplied with FreeBSD.

This brings up my next question; how much extra memory would it take to include IPv6 support? :) Not at all necessary of course, perhaps you could offer it as an option (ntpv6d or some such)? Your current IPv4 only implementation doesn't choke on the "restrict -6 ::1" line or IPv6 addresses, so you wouldn't need two different ntp.conf files.
 
And while I'm at it ... in Tools_NtpdStats.asp replace
Code:
<title><#495#> - System Information</title>
with
Code:
<title><#523#> - NTP Daemon Performance Stats</title>
to make the browser tab correct. :)

Unless the <#xxx#> does truly change between firmware releases (and perhaps between models!). In which case you'll have to skip the router name in the title.
 
Last edited:
I also saw the error on "restrict br0" though we thought it was okay upon an earlier discussion. Apparently that was not the case. One reason I was not keen on this is that the custom NTPD is used in LAN behind firewall.

I think using IP addresses like you suggested may work but I haven't tried myself. Also for people allowing computers on your LAN to connect to this NTPD might want to put a LAN subnet address there (or simply not put any restriction).

...the title page. You're right spot on it. I changed my local copy to simply like this
Code:
<title>Tools - NTP Daemon</title>

:)
 
kvic - a quick note. zyxmon and ryzhovau have both ntpd (with SHM support) and now gpsd available with Entware-ng. I installed both this morning on my AC88U running 380.57.
NTPD now sees the GPS and gets the time information over USB using gpsd.

I then did a modified install of your tools. I added rrdtool, ntpstats (needed a minor change to point to /opt/sbin instead of /jffs/bin for ntpq), copied the www directory etc. and made the minor changes above to Tools_NtpdStats.asp. Everything is running well.

BTW, having ntpstats run every 5 mins from cron was causing lots of lines in my syslog.log file. Instead of running from cron, I changed the script to a "while true do......the script..... sleep 300 done" daemon. I start it in the background from services-start.
 
kvic - a quick note. zyxmon and ryzhovau have both ntpd (with SHM support) and now gpsd available with Entware-ng. I installed both this morning on my AC88U running 380.57.
NTPD now sees the GPS and gets the time information over USB using gpsd.

Nice! You proved it works. According to ASAT, then you're the first guy on this forum. :D

Have you got the chance to re-try the ntpd version in #39? I expect it's going to save you some RAM. If it doesn't, and you happen to know the driver currently works, I might be able to custom compile a version for you.

BTW, having ntpstats run every 5 mins from cron was causing lots of lines in my syslog.log file. Instead of running from cron, I changed the script to a "while true do......the script..... sleep 300 done" daemon. I start it in the background from services-start.

I recall seeing that too. I've syslog-ng from Entware installed and replaced the stock syslog. Hence, all my cron job logs are in its own file. It's less a nuisance as it won't clog the main syslog. You may spend sometime on such a project.

Another way is to install "watch' from Entware. Use watch to run the ntpstat script every 5 minutes. People can give it a try too..

Thanks for the update!
 
Nice! You proved it works. According to ASAT, then you're the first guy on this forum. :D

Have you got the chance to re-try the ntpd version in #39? I expect it's going to save you some RAM. If it doesn't, and you happen to know the driver currently works, I might be able to custom compile a version for you.



I recall seeing that too. I've syslog-ng from Entware installed and replaced the stock syslog. Hence, all my cron job logs are in its own file. It's less a nuisance as it won't clog the main syslog. You may spend sometime on such a project.

Another way is to install "watch' from Entware. Use watch to run the ntpstat script every 5 minutes. People can give it a try too..

Thanks for the update!

Ok, I have redone my testing using the ntpd version in #39. Works fine, exactly like the stock Entware version. In a week or so, I will try to enable PPS support (through USB). Again, I will use your version to see if it works.

Summary - your latest version and Entware-ng's gpsd work well together on my RT-AC88u.
You might want to update your wiki and mention gpsd if folks want to add GPS using the routers USB port. The precision on USB is not the greatest, but it is fun ;-)

Thanks!
 
Finally compiled a version for MIPS routers. Surprisingly code size is quite a bit bigger than ARM at the moment (but shall still be lot better than stock version from Entware). Interested RT-N66/AC66 users could give it a try.

Also included feedback/changes discussed in this thread. Please refer to #1 for Installation Guide and change log.

@JGrana I added a new section on the Guide about GPS dongle, and linked to your post. Interested folks may reach out to you in future...
 
Could you please check what is the USB-to-serial driver that it is loading? Type 'dmesg' and look for /dev/ttyUSB0.

Sure, it was reported as ttyACM0:
usb 3-2: new full speed USB device using ohci_hcd and address 2
cdc_acm 3-2:1.0: ttyACM0: USB ACM device
usbcore: registered new interface driver cdc_acm
cdc_acm: v0.26:USB Abstract Control Model driver for USB modems and ISDN adapter

The device is an older GiSTEQ PhotoTracker GPS module with a USB interface I had in a drawer for some time (many cameras now have GPS built in now).
 
Finally compiled a version for MIPS routers. Surprisingly code size is quite a bit bigger than ARM at the moment (but shall still be lot better than stock version from Entware). Interested RT-N66/AC66 users could give it a try.

Also included feedback/changes discussed in this thread. Please refer to #1 for Installation Guide and change log.

@JGrana I added a new section on the Guide about GPS dongle, and linked to your post. Interested folks may reach out to you in future...

Looks good kvic. The one thing I would add for more detail is how to startup gpsd.

Plug in the USB GPS module, look for the tty device in dmesg. In my case, it was ttyACM0.

Then, start gpsd with this command line:

gpsd -n -P /opt/var/run/gpsd.pid -S 2947 /dev/ttyACM0

Entware-ng creates an init.d file (S62gpsd) with this ARGS line. You should check the tty device there as well to make sure gpsd attaches to the correct device.
 
it was reported as ttyACM0
Your GPS receiver is being presented to the system as a USB modem (ttyACM0) and it is apparently working just fine for you.

Mine shows as ttyUSB0 because I've modified the kernel configuration to disable the USB modem driver and enable the USB-to-serial drivers: FTDI and CH341. I can connect any generic NEMA device, or an Arduino, for example.
 
Your GPS receiver is being presented to the system as a USB modem (ttyACM0) and it is apparently working just fine for you.

Mine shows as ttyUSB0 because I've modified the kernel configuration to disable the USB modem driver and enable the USB-to-serial drivers: FTDI and CH341. I can connect any generic NEMA device, or an Arduino, for example.

Interesting now. I have plugged in a Garmin 18x puck, through a Prolific RS-232 to USB converter. The kernel reports it as ttyUSB0 - and attaches the GSM modem driver. As a result, no data... I just got lucky with the GiSTEQ GPS device.

Anyway to force it to NOT use the GSM modem driver and instead plain or serial port?
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

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

Staff online

Top