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!

[RT-AC87U] Custom script - radio manipulation - [solved]

Discussion in 'Asuswrt-Merlin' started by Tostaki, May 19, 2017.

  1. Tostaki

    Tostaki New Around Here

    Joined:
    May 19, 2017
    Messages:
    9
    Location:
    France
    EDIT: tested and fully explained solution on post #14

    Hello,

    I wanted to add a custom "night mode" to my RT-AC87U router. My target is to shutdown the wireless adapters and the leds at night. A custom script + a cron job does the job.
    This solution enables me get the wifi harware button not turning off the scheduling each time it is pressed.

    I just need help to get it working for the 5G network. At this time only the 2.4G one works with the following command. I did not found the 5G interface

    Does anybody knows how to deal with the 5g adapter ?

    Trying to list the interfaces gave me the following
    Code:
    [email protected]:/# lshw
    -sh: lshw: not found
    
    [email protected]:/# wl status
    SSID: "myssid"
    Mode: Managed   RSSI: 0 dBm   SNR: 0 dB   noise: -91 dBm   Channel: 9l
    BSSID: F0:79:59:D4:XX:XX   Capability: ESS ShortSlot RRM
    Supported Rates: [ 1(b) 2(b) 5.5(b) 6 9 11(b) 12 18 24 36 48 54 ]
    VHT Capable:
       Chanspec: 2.4GHz channel 11 40MHz (0x180b)
       Primary channel: 9
       HT Capabilities:
       Supported MCS : [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 32 ]
       VHT Capabilities:
       Supported VHT (tx) Rates:
           NSS: 1 MCS: 0-9
           NSS: 2 MCS: 0-9
           NSS: 3 MCS: 0-9
       Supported VHT (rx) Rates:
           NSS: 1 MCS: 0-9
           NSS: 2 MCS: 0-9
           NSS: 3 MCS: 0-9

    My full script which does not work entirely
    Code:
    #!/bin/sh
    
    show_help()
    {
        echo "Arrete et relance le wifi par script. Les leds suivent la meme logique"   
        echo "usage:"
            echo "nightmode -on         wifi off, leds off"
            echo "nightmode -off        wifi on, leds on"
            echo ""
    }
    
    option="${1}"
    case ${option} in
    
                    -on)
                #2.4G network                   
                wl -i eth1 radio off
                #5G network - does not work on RT-AC87U - wl driver adapter not found
                wl -i eth2 radio off
                logger ****Wifi off****
                nvram set led_disable=1
                service restart_leds
    
                    ;;
    
                    -off)
                #2.4G network                   
                wl -i eth1 radio on
                #5G network - does not work on RT-AC87U - wl driver adapter not found
                wl -i eth2 radio on
                logger ****Wifi on****
                nvram set led_disable=0
                service restart_leds
                    ;;
    
                    *) show_help
                    exit 1
                    ;;
    esac
     
    Last edited: May 30, 2017
    TheUntouchable likes this.
  2. TheUntouchable

    TheUntouchable Regular Contributor

    Joined:
    May 17, 2017
    Messages:
    93
    Location:
    Germany
    Thanks for that script, I personally like the led off feature a lot and will use your script without the wlan feature! Sadly I can't help you any further with the 5GHz WLAN problem :(
     
  3. Tostaki

    Tostaki New Around Here

    Joined:
    May 19, 2017
    Messages:
    9
    Location:
    France
    You're welcome.
    The Led part is taken from the AsusMerlin Wiki :)

    About radio, I tried different option without success so far.

    By the way, I noticed a weird beahvior of Dropbear SSH server. The password I set on the router was not accepted to login ssh. Changing the password to something dummy simple, worked. Here the examples :

    Password type : "Mickey mous is the world best know mouse" => fail to login sshd
    Password type : "admin" => succeed to login sshd
     
    TheUntouchable likes this.
  4. RMerlin

    RMerlin Part of the Furniture

    Joined:
    Apr 14, 2012
    Messages:
    24,229
    Location:
    Canada
    Password is limited to 16 characters.
     
    amplatfus likes this.
  5. Tostaki

    Tostaki New Around Here

    Joined:
    May 19, 2017
    Messages:
    9
    Location:
    France
    Thank you @RMerlin for the password feedback.

    Any idea about the eth interface for 5G network ?

    Thx
     
  6. Jack Yaz

    Jack Yaz Very Senior Member

    Joined:
    Apr 20, 2017
    Messages:
    623
    At a guess, I think its like vlan4000 for 5ghz on 87U, though I didn't have much luck with it. The guests appear to fall into line with w1.1 etc!
     
  7. Tostaki

    Tostaki New Around Here

    Joined:
    May 19, 2017
    Messages:
    9
    Location:
    France
    I tested without luck eth1.0, eth1.1 and eth 1.2.
    After a carefull read of a first test report by @RMerlin it appears, 5G network is on a dedicated CPU (Qantenna). A simple ifconfig does not list the interface...
     
  8. Zirescu

    Zirescu Very Senior Member

    Joined:
    Jul 16, 2013
    Messages:
    668
    Location:
    Kelowna, BC
    Why not use the built-in wireless scheduler under the Wireless Professional tab?
     
  9. Tostaki

    Tostaki New Around Here

    Joined:
    May 19, 2017
    Messages:
    9
    Location:
    France
    I am know using the built-in feature. But this is the moot point here.

    As soon as my kids are overriding the schedule using the front panel button, the scheduling is disabled. As this is the design of the feature by construction, I was looking for a workaround. The custom script seems to be a good idea as soon as I found the way to control the 5G network through command line.
     
  10. CivHunter

    CivHunter Occasional Visitor

    Joined:
    Jun 20, 2013
    Messages:
    32
    Would the parental controls give the results you are looking for? Limiting the hours of access for your kids devices?
     
  11. Zirescu

    Zirescu Very Senior Member

    Joined:
    Jul 16, 2013
    Messages:
    668
    Location:
    Kelowna, BC
    See here: #5
     
  12. Tostaki

    Tostaki New Around Here

    Joined:
    May 19, 2017
    Messages:
    9
    Location:
    France
    Thank you @Zirescu

    The solution is then

    Code:
    #!/bin/sh
    #This script works on RT-AC87U which has 2 different CPU for 2.4 and 5.0 wireless networks
    show_help()
    {
        echo "Arrete et relance le wifi par script. Les leds suivent la meme logique"   
        echo "usage:"
            echo "nightmode -on         wifi off, leds off"
            echo "nightmode -off        wifi on, leds on"
            echo ""
    }
    
    option="${1}"
    case ${option} in
    
          -on)
              #5.0G AP control
              qcsapi_sockrpc rfenable 0 wifi0
              #2.4G AP control
              wl -i eth1 radio off
    
              logger ****Wifi is off****
             
              nvram set led_disable=1
              service restart_leds
             
              logger ****Leds are off****
    
                    ;;
        -off)
             #5.0G AP control
             qcsapi_sockrpc rfenable 1 wifi0
             #2.4G AP control               
             wl -i eth1 radio on
             
             logger ****Wifi is on****
             
             nvram set led_disable=0
             service restart_leds
             
             logger ****Leds are on****
                    ;;
    
       *) show_help
                    exit 1
                    ;;
    esac
    I'll test this asap and let you know.
     
    Last edited: May 23, 2017
    TheUntouchable likes this.
  13. Tostaki

    Tostaki New Around Here

    Joined:
    May 19, 2017
    Messages:
    9
    Location:
    France
    The idea is not to prevent kids from using Wifi. They are old enough and responsible to be allowed. The idea is to get a scheduling which is "kill switch proof". Wifi is really useful but at some time we do not need to get it on.
     
  14. Tostaki

    Tostaki New Around Here

    Joined:
    May 19, 2017
    Messages:
    9
    Location:
    France
    Here we go, my final solution implemented

    As a reminder, my need which is shared with some other users : Use the front panel button "Wifi" as a toggle which only overides the schedule of the radio availability.
    As a built-in feature, the button disable any scheduling as soon as the button is pressed.

    The solution comes with the custom scripts with the help of cron jobs.
    Pros:
    - The wifi button is just an overide of the schedule
    - More flexibility in the scheduling (for instance vacation time
    - Capability to manage the leds the same way
    Cons:
    - Scheduling more complex as you must know the cron syntax
    - Must use command line and SSH to do the sceduling
    - If you manage the leds in a Nightmode, overiding the scedule may lead to bizarre behavior

    The desired features:
    - Ability to schedule wifi
    - Ability to schedule leds
    - Perform action only if needed (do not turn off wifi if already off for instance)

    Everything is shared on Github (Will be updated there)


    I first start to implement it in a whole big shell script. This was a bas idea as the flexibility is not there. I cut my scripts into 3 pieces : radio control, led control, nightmode combining the 2 first ones. This allows to reuse each script standalone if you want.

    1st script : radio_ctrl.sh
    Code:
    #!/bin/sh
    # file: radio_ctrl.sh
    # location: /jffs/scripts/
    # device: RT-AC87U
    #
    # Purpose : Turn on/off the wifi interfaces on 2.4 & 5.0 networks
    #
    # Date: 2017-05
    # Version 1.0
    #
    #
    #
    
    status=`qcsapi_sockrpc rfstatus wifi0`
    action="${1}"
    
    show_help()
    {
        echo "Turns on / off wifi on RT-AC87U"   
        echo "usage:"
        echo "radio_ctrl.sh -on        wifi on on both interfaces"
        echo "radio_ctrl.sh -off    wifi off on both interfaces"
        echo "radio_ctrl.sh -status    returns status of the 5G interface"
        echo "Any other option displays this help"
        echo ""
    }
    
    case ${action} in
    
            -on)
                if [ $status = "Off" ]
                then
                    qcsapi_sockrpc rfenable 1 wifi0 &>/dev/null
                    wl -i eth1 radio on &>/dev/null
                    logger "$0: Wifi is on"
                else
                    logger "$0: Wifi is already in requested status - nothing done"
                fi
            ;;
            -off)
                if [ $status = "On" ]
                then
                    qcsapi_sockrpc rfenable 0 wifi0 &>/dev/null
                    wl -i eth1 radio off &>/dev/null
                    logger "$0: Wifi is off"
                else
                    logger "$0: Wifi is already in requested status - nothing done"
                fi
            ;;
            -status)
                echo "wifi status is $status"      
            ;;
            *)
                show_help
                exit 1
            ;;
    esac
    exit 0
    
    2nd script : led_ctrl.sh
    Code:
    #!/bin/sh
    # file: led_ctrl.sh
    # location: /jffs/scripts/
    # device: RT-AC87U
    #
    # Purpose : Turn on/off the led panel of the router
    #
    # Date: 2017-05
    # Version 1.0
    #
    #
    #
    
    status_led=`nvram get led_disable`
    status_wifi=`qcsapi_sockrpc rfstatus wifi0`
    action="${1}"
    
    show_help()
    {
        echo "Turns on / off leds on RT-AC87U"   
        echo "usage:"
        echo "led_ctrl.sh -on        leds on"
        echo "led_ctrl.sh -off        leds off"
        echo "led_ctrl.sh -status    returns leds status"
        echo "led_ctrl.sh -align    Align led status to the wifi status to match overided turn on/off - called at nigth through cronjob"
        echo "Any other option displays this help"
        echo ""
    }
    
    case ${action} in
    
            -on)
                if [ $status_led = "1" ]
                then
                    nvram set led_disable=0 &>/dev/null
                    service restart_leds &>/dev/null
                    logger "$0: Leds are on"
                else
                    logger "$0: Leds are already in requested status - nothing done"
                fi
            ;;
            -off)
                if [ $status_led = "0" ]  
                then
                    nvram set led_disable=1 &>/dev/null
                    service restart_leds &>/dev/null
                    logger "$0: Leds are off"
                else
                    logger "$0: Leds are already in requested status - nothing done"
                fi
            ;;
            -status)
                if [ $status_led = "0" ]
                then
                    echo "Leds status is on"
                elif [ $status_led = "1" ]
                then
                    echo "Leds status is off"
                else
                    echo "Leds status is unknown"
                fi
            ;;
            -align)
                if [ $status_led = "0" ] && [ $status_wifi = "Off" ]
                then
                    nohup $0 -off &>/dev/null
                elif [ $status_led = "1" ] && [ $status_wifi = "On" ]
                then
                    nohup $0 -on &>/dev/null
                else
                    :
                fi
            ;;
            *)
                show_help
                exit 1
            ;;
    esac
    exit 0
    

    3rd script : nightmode.sh
    Code:
    #!/bin/sh
    # file: nightmode.sh
    # location: /jffs/scripts/
    # device: RT-AC87U
    #
    # Purpose : schedule wifi radio in a kill switch proof way to replace the built-in feature
    # which disable scheduling as soon as the front panel button is pressed
    #
    # Date: 2017-05
    # Version 1.0
    #
    # Features
    #    - Turn on / off wifi 2.4G and 5.0G
    #    - Turn on / off leds
    #
    #
    
    status=`qcsapi_sockrpc rfstatus wifi0`
    
    show_help()
    {
        echo "Turns on / off wifi and leds on RT-AC87U"   
        echo "usage:"
        echo "nightmode.sh -on            wifi off, leds off"
        echo "nightmode.sh -off            wifi on, leds on"
        echo ""
    }
    
    option="${1}"
    case ${option} in
    
            -on)
                #nightmode is on
                /jffs/scripts/radio_ctrl.sh -off
                /jffs/scripts/led_ctrl.sh -off      
            ;;
            -off)
                #nightmode is off
                /jffs/scripts/radio_ctrl.sh -on
                /jffs/scripts/led_ctrl.sh -on
            ;;
            *)
                show_help
                exit 1
            ;;
    esac
    exit 0

    The next step is to add the appropriate schedule is crontab. To get it working after each reboot, I added the following commands in a file called by the system right after the boot-up of the services.

    Code:
    #!/bin/sh
    # file: services-start
    # location: /jffs/scripts/
    #
    # Purpose : start addtionnal services rigth after the router is ready
    #
    # Date: 2017-05
    # Version 1.0
    #
    #---------------------------------
    
    # Add nightmode to crontab
    # minute | hour | day of month | month | day of week
    # cru a <job_name> " * * * * * /jffs/scripts/<script>"
    
    # Nightmode enabled : all days at 22h30
    cru a nigthmode_start "30 22 * * * /jffs/scripts/nightmode.sh -on"
    # Nightmode disabled : all days at 7:30
    cru a nigthmode_stop "30 7 * * * /jffs/scripts/nightmode.sh -off"
    At the next reboot, you should check the crontab, the list should be updated.

    The first caveat came when, in nightmode, I decided to overide the schedule (you know about sending the last version of your slides deck to your boss before the early morning meeting...). The leds were off and I had no feedback about the status of the wifi. This may lead to toggle twice the wifi or forget to turn it off after "that" email is sent.

    As the wifi button has no action on the leds (for obvious reasons), the best way is to find out a way to align the leds on the wifi status. As soon as I trigger nigthmode, I have to look at the "overrided mode". I modified the led_ctrl.sh script for such a feature.

    Just adding the led alignement to cronjobs

    Code:
    #!/bin/sh
    # file: services-start
    # location: /jffs/scripts/
    #
    # Purpose : start addtionnal services rigth after the router is ready
    #
    # Date: 2017-05
    # Version 1.1
    #
    #---------------------------------
    
    # Add nightmode to crontab
    # minute | hour | day of month | month | day of week
    # cru a <job_name> " * * * * * /jffs/scripts/<script>"
    
    # Nightmode enabled : all days at 22h30
    cru a nigthmode_start "30 22 * * * /jffs/scripts/nightmode.sh -on"
    # leds aligned on wifi all the nigth
    cru a leds_align "*/2 0-7 * * * /jffs/scripts/led_ctrl.sh -align"
    # Nightmode disabled : all days at 7:30
    cru a nigthmode_stop "30 7 * * * /jffs/scripts/nightmode.sh -off"
    This modification leads to get the leds following the wifi status during nigth within 2 minutes. The leds_ctrl.sh script is modified to support the -align option. As far as I use it, this fullfil my expectation with a more complex schedule to take care of the kids' summer vacations.

    Hope this helps others

    Edit : add comment on github link)
     
    Last edited: Jun 12, 2017
    Nullity and TheUntouchable like this.
  15. Movin1

    Movin1 New Around Here

    Joined:
    May 25, 2017
    Messages:
    3
    Does this script result in the status of the wifi (on or off) being reflected in the manual 2.4G and 5G enable/disable selectors in the GUI?

    My post from another thread pasted below:

    I recently added a "radio off" and "radio on" script to my RT-AC68U, activated by a cron job. I did this to set up wifi on/off scheduling that isn't cancelled/disabled by adhoc manual toggling via the physical switch on the side of the router.

    This works well, however the enable/disable selectors in the gui for the respective 2.4ghz and 5ghz bands dont change to reflect the state of the wifi when it is turned on or off by the cron scheduled script.
    This doesn't bother me too much, but if there is something I can do to rectify it and make the operation more complete and polished, that would be great...
    Anybody got any ideas?
     
  16. Tostaki

    Tostaki New Around Here

    Joined:
    May 19, 2017
    Messages:
    9
    Location:
    France
    The toggle you are refering to, seems to be a higher level one. Thus its status is not updated by the scripts. (as far as I understand)

    Updated scripts on github
     

Share This Page