1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

script for wifi button LED ?

Discussion in 'Tomato Firmware' started by Ryndyn, Jan 9, 2018.

  1. Ryndyn

    Ryndyn New Member Member

    Advanced Tomato, latest version on R7000, and thanks to all the developers, it's just great!

    I am looking for a script so the WiFi button's LED is lit when wifi is up, and off when wifi is off. (Like original factory behavior.)

    Advanced Tomato turned the Wifi button's LED off, so I turned it back on with this:

    gpio enabled 15

    ... but when I toggle wifi off... and back on... the button's LED stays off instead of coming back on when wifi gets enabled again.

    I need the button lit when wifi is up so it's easy to find in the dark when I go to toggle wifi off. I did read this thread but I don't think they were talking about the wifi button and am way too noobian to extrapolate from the code there how I might build a script to do what I need. Thanks for any help!
     
    Last edited: Jan 9, 2018
  2. Ryndyn

    Ryndyn New Member Member

    No one?

    I titled this query poorly as the wifi button doesn't 'run scripts' like the WPS button. I'm just looking for OEM behavior of the wifi button... nothing special. If anyone could point me in the right direction -- a fix I could pursue -- I'd much appreciate it. I have spent 3 solid days looking for a script but the major interest is in turning off LEDs and changing behavior of the WPS button... not restoring OEM behavior to the Wifi button.
     
  3. AndreDVJ

    AndreDVJ Addicted to LI Member

    There are a couple of issues.
    • I look at lights of each radio so I know when Wi-Fi is on or off.
    • The wi-fi LED itself, is AOSS for Tomato (led aoss on|off - OR - gpio enable|disable 15).
    • The wi-fi button, became the "WPS/AOSS button" in Tomato.
    • The WPS button does nothing, though its LED is controllable (gpio enable|disable 14)
    The 2.4/5Ghz lights should go on or off.
     
  4. Ryndyn

    Ryndyn New Member Member

    Thanks so much for your reply, Andre.

    The wifi LED iindeed behaves as factory (on when wifi is on, off when wifi is off). So that's good. But the reason I want the wifi button lit is not to see if wifi is up or not, it's to see the button itself to turn wifi off at night in the dark. I can feel by braille but the factory behavior of the lit button is preferable and easier.

    To this point, when I run gpio enable 15 the wifi button LED does indeed light (not the wifi LED as you seemed to state above??). My issue is that once I use it to turn wifi off, the button's LED stays off even when I press it in the morning to turn wifi back on.

    It sounds like from what you're saying I need to find a script for the WPS button, because "that became the wifi button in Tomato" .... but I found no script that will enable the button LED when wifi is turned back on. Again, everyone seems interested in turning LEDs off all the time, or on all the time... but not off or on depending on if wifi is up or not.

    But thanks for clarifying that the wifi button became the WPS button because maybe I missed something, not knowing that.
     
  5. Ryndyn

    Ryndyn New Member Member

    This code was posted by yaqui (in the thread I linked to in OP) to turn on LED when wifi is up, but not sure which LED, and wondered if a coder here would know how to modify it to turn wifi button LED on when wifi is up?

    Code:
    sleep 5
    I=`nvram get wl0_ifname`
    while sleep 1; do
    if [ "`wl assoclist`" != "" ]; then
    XFER=`ifconfig $I|grep bytes`
    if [ "$XFER" != "$PXFER" ]; then
    LED="amber on white on"
    PXFER=$XFER
    else
    LED="amber on white off"
    fi
    else
    LED="amber off white off"
    fi
    if [ "$LED" != "$PLED" ]; then
    led $LED
    PLED=$LED
    fi
    done
    
     
    Or perhaps there's a less complicated solution, like setting gpio enabled 15 to run each day at noon to turn the wifi button's LED back on? or does that require a router reboot?
     
    Last edited: Jan 10, 2018
  6. Sean B.

    Sean B. LI Guru Member

    The NVRAM variable wl0_radio is used to set the 2.4ghz wireless state, 1=enabled 0=disabled . So putting something like this is in Administration->Scheduler set to run everyday at whatever time interval you'd like should do what you're looking for:

    Code:
    #!/bin/sh
    RADIO=`nvram get wl0_radio`
    LAST=/etc/wstate_save
    
    if [ ! -e $LAST ]
      then
        echo $RADIO > $LAST
    fi
    
    if [ `cat $LAST` != $RADIO ]
      then {
        logger "Wireless radio state change detected"
        if [ `cat $LAST` == 0 ] && [ $RADIO != 0 ]
          then
            logger "Turning on Wi-Fi button LED"
            gpio enable 15
            echo $RADIO > $LAST
        elif [ `cat $LAST` == 1 ] && [ $RADIO != 1 ]
          then
             logger "Turning off Wi-Fi button LED"
             gpio disable 15
             echo $RADIO > $LAST
        fi }
    fi
    When run, the script checks whether or not the file /etc/wstate_save exists. If it doesn't ( such as after a reboot of the router ) the script creates it and enters the current 2.4ghz radio state value. If the file /etc/wstate_save file exists, the script compares the value it contains against the current NVRAM value for wl0_radio. If they match it does nothing, if they don't it enables or disables the LED GPIO depending on the change detected and makes an entry in the system log of doing so.

    If pressing the Wi-Fi button disables Wi-Fi without the firmware detecting so ( IE: The 2.4ghz radio still shows as enabled in the web interface ), then using the specified NVRAM variable likely won't work. However, the script can be easily modified to use an alternate form of detection.
     
    Last edited: Jan 11, 2018
    Monk E. Boy and Ryndyn like this.
  7. Ryndyn

    Ryndyn New Member Member

    Sean, thank you SO MUCH for this! I believe your last paragraph there might be true, or I might have done something wrong.

    At 10am I pasted the code into the Scheduler to run at 10:15am. I also put gpio enable 15 in the scripts section under init, so that when, after saving and rebooting, the router would boot with wifi up and the wifi button LED on, to save that as the 'state' to compare against....

    After rebooting the button's LED was on, as was wifi... waited a minute or two, toggled wifi off with the button (thereby making the button's light go off), then after a moment, toggled wifi back on at 10:08.

    The script apparently ran at 10:15 and I waited until 10:17, but the button did not light up.

    Toggled off wifi, connected Ethernet, and looked in the GUI to see if the 2.4gHz radio was grayed out or disabled in the GUI. It was not. Did I do something wrong?

    EDIT: In thinking on this I believe I did do something wrong... I didn't let the script run initially before toggling wifi off/on, so when the script ran, it saved the button off status with wifi on as 'the norm'. Am trying it again...

    EDIT2: This time I set the script to run 'every 15m' just to check if it works (planning on having it run only once a day). The first time it ran I had just rebooted minutes before, so button LED was lit and wifi was up. Before it ran the second time 15m later, I toggled wifi off, then back on, so now the wifi button was off. Script ran but button LED stayed off. But maybe I'm still doing something wrong?
     
    Last edited: Jan 11, 2018
  8. Sean B.

    Sean B. LI Guru Member

    Sounds as if the WiFi button is a hardware only feature and the firmware is not aware of it. I'll modify the script to detect WiFi status from a different source shortly when I have a few minutes.
     
    Ryndyn likes this.
  9. Ryndyn

    Ryndyn New Member Member

    I cannot thank you enough, Sean. Much appreciated.

    EDIT: I feel like an idiot, but I came up with a possible alternate solution, though I don't know if this is bad for the router's longevity or not. Maybe code is better?

    In the LED/Buttons page the wifi button is set to toggle wifi if pressed 0-2 seconds, then I can also set it to reboot if pressed 4-6 seconds... So in A.M. I can turn wifi back on by rebooting the router which will read gpio enabled 15 in scripts, and light the wifi button's LED [along with turning on wifi]. But is this a bad idea?
     
    Last edited: Jan 11, 2018
  10. Sean B.

    Sean B. LI Guru Member

    Sorry for the delay. I forgot all about the buttons section as I never use it, it's a much better avenue for this purpose than the Scheduler. I'm not sure what way the firmware uses to disable wireless when the " toggle wireless " option is selected for the button, as I have not reviewed that section of the code. However, if we change the button from that to the " run custom script " option and disable the radio ourselves we can then associate the LED on/off state a long with it. Set the button to " run custom script " and then put this in the custom script box and see how it works for you:

    Code:
    #!/bin/sh
    RSTATE=`wl -i eth1 radio`
    ROFF="wl -i eth1 radio off"
    RON="wl -i eth1 radio on"
    LOFF="gpio disable 15"
    LON="gpio enable 15"
    
    if [ $RSTATE == 0x0000 ]
      then
        logger "Wireless button: Disabling 2.4ghz radio."
        $ROFF
        $LOFF
          elif [ $RSTATE == 0x0001 ]
            then
              logger "Wireless button: Enabling 2.4ghz radio."
              $RON
              $LON
                else
                  logger "Wireless button: Unknown error! No action taken."
    fi
     
    Last edited: Jan 13, 2018
    Ryndyn and AndreDVJ like this.
  11. Ryndyn

    Ryndyn New Member Member

    BRILLIANT!!!! Works exactly like stock now... button LED on when wifi up, button LED off when wifi off.

    I know this took a lot of your personal time and I am so grateful and appreciative! I purposely chose the R7000 for this feature, and while I love everything else about Tomato it was a bummer losing that stock behavior for the wifi button. Now you've restore it, no reboot required!

    A million thanks, Sean B!!!!!
     
  12. Ryndyn

    Ryndyn New Member Member

    PS Is there a way for me to edit the title of the thread to add [SOLVED] ??
     
  13. Sean B.

    Sean B. LI Guru Member

    You're very welcome, glad I could help!
     
    Ryndyn likes this.

Share This Page