Fitz Mutch
Senior Member
MOVED: https://www.snbforums.com/threads/usb-gps-instead-of-ntp.39806/
Here's a sample script to synchronize the router clock with a GPS receiver. I verified this works on my RT-N16 router w/stock firmware. So it likely works for all Asuswrt-Merlin routers.
On my u-blox GPS, I suppress all NEMA sentences except $GPZDA, so it outputs only the current date/time and hides my geographic location.
The best news is that NTP is not needed to set the router's clock. It's script only. He works with @kvic.
/jffs/scripts/clock-sync-gps.sh
If you have a u-blox 7 chip in your GPS, then here's how to enable reporting of the current date/time only. Prevents your geographic location from being reported to the router. If you download and install the u-center evaluation kit for your PC, it can generates these codes for you. If you un-comment the last line it will save these settings to flash memory, so you only need to run the script once.
/jffs/scripts/ublox7-gpzda.sh
If it don't work, you may need to disable the Asus USB modem drivers and programs.
/jffs/scripts/init-start
On my u-blox GPS, I suppress all NEMA sentences except $GPZDA, so it outputs only the current date/time and hides my geographic location.
The best news is that NTP is not needed to set the router's clock. It's script only. He works with @kvic.
/jffs/scripts/clock-sync-gps.sh
Code:
#!/bin/sh
GPS_DEVICE="/dev/ttyACM0"
NEMA_TYPE="GPZDA"
# search for NEMA sentence of type $GPZDA
READ_COUNT=50
read NEMA_DATA < $GPS_DEVICE
READ_ERROR=$?
while [ $READ_COUNT -ge 0 ] && [ $READ_ERROR -eq 0 ] && [ "${NEMA_DATA:0:6}" != "\$${NEMA_TYPE}" ]; do
let READ_COUNT--
read NEMA_DATA < $GPS_DEVICE
READ_ERROR=$?
done
# found a NEMA sentence of type $GPZDA
if [ "${NEMA_DATA:0:6}" == "\$${NEMA_TYPE}" ]; then
# compute the NEMA checksum
L1=${#NEMA_DATA}
let L2=$L1-3
CHECKSUMHEX=${NEMA_DATA##*\*}
CHECKSUM=$(/usr/bin/printf "%d" 0x${CHECKSUMHEX})
P=1; CHECKSUM_CALC=0
while [ $P -lt $L2 ]; do
let CHECKSUM_CALC^=$(/usr/bin/printf '%d' "'${NEMA_DATA:$P:1}")
let P++
done
# validate the NEMA checksum
if [ $CHECKSUM_CALC -eq $CHECKSUM ]; then
# parse current date/time from NEMA sentence of type $GPZDA
if [ "$NEMA_TYPE" == "GPZDA" ]; then
# 11111111112222222222333333
# 012345678901234567890123456789012345
# $GPZDA,132727.00,07,06,2017,00,00*61
UTC="${NEMA_DATA:23:4}${NEMA_DATA:20:2}${NEMA_DATA:17:2}${NEMA_DATA:7:2}${NEMA_DATA:9:2}.${NEMA_DATA:11:2}"
else
UTC=""
fi
# set the system clock
if [ -n "$UTC" ]; then
# /bin/echo $UTC
/bin/date -u -s $UTC
if [ $? -eq 0 ]; then
nvram set ntp_ready=1
fi
fi
fi
fi
If you have a u-blox 7 chip in your GPS, then here's how to enable reporting of the current date/time only. Prevents your geographic location from being reported to the router. If you download and install the u-center evaluation kit for your PC, it can generates these codes for you. If you un-comment the last line it will save these settings to flash memory, so you only need to run the script once.
/jffs/scripts/ublox7-gpzda.sh
Code:
#!/bin/sh
DEV_GPS=/dev/ttyACM0
# HOWTO: generate these UBX codes yourself
# download and install the u-center evaluation kit from u-blox website
# plug in the GPS to your computer and run the u-center software
# select menu: View -> Messages
# select tree: UBX -> CFG (Config) -> MSG (Messages)
# Disable: NMEA GxGGA
printf "\xB5\x62\x06\x01\x08\x00\xF0\x00\x00\x00\x00\x00\x00\x00\xFF\x23" >> $DEV_GPS
# Disable: NMEA GxGLL
printf "\xB5\x62\x06\x01\x08\x00\xF0\x01\x00\x00\x00\x00\x00\x00\x00\x2A" >> $DEV_GPS
# Disable: NMEA GxGSA
printf "\xB5\x62\x06\x01\x08\x00\xF0\x02\x00\x00\x00\x00\x00\x00\x01\x31" >> $DEV_GPS
# Disable: NMEA GxGSV
printf "\xB5\x62\x06\x01\x08\x00\xF0\x03\x00\x00\x00\x00\x00\x00\x02\x38" >> $DEV_GPS
# Disable: NMEA GxRMC
printf "\xB5\x62\x06\x01\x08\x00\xF0\x04\x00\x00\x00\x00\x00\x00\x03\x3F" >> $DEV_GPS
# Disable: NMEA GxVTG
printf "\xB5\x62\x06\x01\x08\x00\xF0\x05\x00\x00\x00\x00\x00\x00\x04\x46" >> $DEV_GPS
# Disable: NMEA GxGRS
printf "\xB5\x62\x06\x01\x08\x00\xF0\x06\x00\x00\x00\x00\x00\x00\x05\x4D" >> $DEV_GPS
# Disable: NMEA GxGST
printf "\xB5\x62\x06\x01\x08\x00\xF0\x07\x00\x00\x00\x00\x00\x00\x06\x54" >> $DEV_GPS
# Enable: NMEA GxZDA
printf "\xB5\x62\x06\x01\x08\x00\xF0\x08\x01\x01\x01\x01\x01\x00\x0C\x6F" >> $DEV_GPS
# Disable: NMEA GxGBS
printf "\xB5\x62\x06\x01\x08\x00\xF0\x09\x00\x00\x00\x00\x00\x00\x08\x62" >> $DEV_GPS
# Disable: NMEA GxDTM
printf "\xB5\x62\x06\x01\x08\x00\xF0\x0A\x00\x00\x00\x00\x00\x00\x09\x69" >> $DEV_GPS
# Disable: NMEA GxGNS
printf "\xB5\x62\x06\x01\x08\x00\xF0\x0D\x00\x00\x00\x00\x00\x00\x0C\x7E" >> $DEV_GPS
# Disable: NMEA GxTHS
printf "\xB5\x62\x06\x01\x08\x00\xF0\x0E\x00\x00\x00\x00\x00\x00\x0D\x85" >> $DEV_GPS
# Disable: NMEA GxVLW
printf "\xB5\x62\x06\x01\x08\x00\xF0\x0F\x00\x00\x00\x00\x00\x00\x0E\x8C" >> $DEV_GPS
# Save MSG (Messages) to flash memory
printf "\xB5\x62\x06\x09\x0D\x00\x00\x00\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00\x03\x1D\xAB" >> $DEV_GPS
If it don't work, you may need to disable the Asus USB modem drivers and programs.
/jffs/scripts/init-start
Code:
#!/bin/sh
deny_access() {
local FILEPATH="$1"
local FILENAME="$(/usr/bin/basename $FILEPATH)"
local FILEEXT="${FILENAME##*.}"
if [ "$FILEEXT" == "ko" ]; then
local MODULENAME="${FILENAME%.*}"
local FILEPATH="/lib/modules/$(/bin/uname -r)/$(/sbin/modprobe -l $MODULENAME)"
if [ -f "$FILEPATH" ] && [ ! -h "$FILEPATH" ]; then
/sbin/lsmod | /bin/grep -qF $MODULENAME && /sbin/modprobe -r $MODULENAME && /bin/sleep 1
/bin/mount -o bind /dev/null "$FILEPATH"
fi
else
if [ -f "$FILEPATH" ] && [ ! -h "$FILEPATH" ]; then
[ -n "$(/bin/pidof $FILENAME)" ] && /usr/bin/killall $FILENAME && /bin/sleep 1
/bin/mount -o bind /dev/null "$FILEPATH"
fi
fi
}
# disable automatic loading of USB modem drivers and programs
deny_access option.ko
deny_access usb_wwan.ko
deny_access drxvi314.ko
deny_access /usr/sbin/find_modem_node.sh
deny_access /usr/sbin/find_modem_type.sh
deny_access /usr/sbin/getrealip.sh
deny_access /usr/sbin/gobi_update.sh
deny_access /usr/sbin/modem_at.sh
deny_access /usr/sbin/modem_autoapn.sh
deny_access /usr/sbin/modem_enable.sh
deny_access /usr/sbin/modem_status.sh
deny_access /usr/sbin/modem_stop.sh
deny_access /usr/sbin/chat
# disable the Asus NTP CLIENT
[ -n "$(/bin/pidof ntp)" ] && /usr/bin/killall ntp && /bin/sleep 1
/bin/rm -f /var/run/ntp.pid
/bin/mkdir -p /var/run/ntp.pid
deny_access /usr/sbin/ntpclient
Last edited: