Wifi Presense for Original Asus Firmware

  • ATTENTION! As of November 1, 2020, you are not able to reply to threads 6 months after the thread is opened if there are more than 500 posts in the thread.
    Threads will not be locked, so posts may still be edited by their authors.
    Just start a new thread on the topic to post if you get an error message when trying to reply to a thread.


New Around Here
First-time poster. Please let me know if anything is in violation.

Created a few scripts to check for association of wireless devices and communicate the status back to a HomeSeer home automation system but it can easily be tailored for other systems. There a few other scripts like this on the internet but this runs on recent Broadcom based Asus Wifi routers and doesn't require merlin. One caveat, you will need to leave a USB device plugged into the router for this to work.

I did my best to condense it as much as possible but I'm not an expert -sh coder so please let me know if there are any errors. This script has been tested for the past few days on a GT-AX11000 and it appears to be working well. I also coded it to use makeshift arrays by using strings and grep. So it should scale to check association for several devices. I'll try to list all steps necessary for this to work properly. All of this will need to be entered from the SSH console, so you will need to become familiar with how to enable and access the console. Hint: Use Putty if windows or SSH if on a Mac.


1. Start by creating two directories
mkdir -p /jffs/scripts/wifipresence/supporting/
mkdir -p /jffs/scripts/wifipresence/online/
2. Create the post-mount script. This script will automatically run at boot when a USB device is connected.
cat > /jffs/post-mount
Paste the following
sleep 5
# add commands below to be run when the router boots if a USB device is connected
# copies script into roots crontab if it does not exist
if grep -q "/jffs/scripts/wifipresence/checkpresence.sh" "/var/spool/cron/crontabs/$(nvram get http_username)"; then exit; else cat /jffs/scripts/wifipresence/supporting/cronjob >> /var/spool/cron/crontabs/$(nvram get http_username); fi
Press Ctrl + C keys to exit cat

Make script executable
chmod a+x /jffs/post-mount
3. Create the script that is copied into root's crontab at boot
cat > /jffs/scripts/wifipresence/supporting/cronjob
Paste the following
*/5 * * * * i=0; while [ $i -le 58 ]; do /jffs/scripts/wifipresence/checkpresence.sh; let i=i+1; sleep 5; done
Press Ctrl + C keys to exit cat

4. Create the script that actually checks the association of particular devices on the WiFi network. Add your device names, mac addresses and device reference numbers to the script below before uploading.
cat > /jffs/scripts/wifipresence/checkpresence.shsleep 5; done
Paste the following

#logger "presencecheck started"

# String with space between the name of each WiFi device. No spaces in the name itself.
names="Phone1 Phone2"

# Mac address of each WiFi Device. Follow names format.
macs="11:22:33:44:55:66 11:22:33:44:55:77"

# HomeSeer device reference number of each WiFi Device. Follow names format.
refs="40 41"

# function to create a list of mac addresses associated to the WiFi
macaddress() {
    for iface in $(nvram get wl_ifnames); do
        wl -i $iface assoclist | sed 's/assoclist//g'

# find number of entries in name
iterations=$( echo "$names" | wc -w )

# directory where to store online status file

# address and parameters used to communicate status
curladdr="http://USERNAME:[email protected]/JSON?request=controldevicebyvalue&ref="

# value sent if device is online

# value sent if device is offline

# start index at 1

# iternate through name string
while [ "$i" -le "$iterations" ]


   # create variables used for awk print
    name=$( echo $names | awk '{print '\$$i'}' )
    mac=$( echo $macs | awk '{print '\$$i'}' )
    ref=$( echo $refs | awk '{print '\$$i'}' )

    # is mac address in list
    if (macaddress | fgrep "$mac" >/dev/null)


                        # if online file does not exist
                        if [ ! -f $dir$name ]


                                        # create the online file
                                        touch  $dir$name

                                        # communicate the status
                                        curl "$curladdr$ref$curlon" -k >/dev/null 2>&1

                                        # save status in the router's log
                                        logger "$name has connected to WiFi"



                        if [ -f  $dir$name ]


                                        # remove the online file
                                        rm -f $dir$name

                                        # communicate the status
                                        curl "$curladdr$ref$curloff" -k >/dev/null 2>&1

                                        # save status in the router's log
                                        logger "$name has disconnected from WiFi"



        let i=i+1


#logger "presencecheck finished"
Press Ctrl + C keys to exit cat

Make script executable
chmod a+x /jffs/scripts/wifipresence/checkpresence.sh

5. Set script active in NVRAM
nvram set script_usbmount="/jffs/post-mount"
nvram commit
Last edited:

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

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