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

Switch wifi on/off via url

Discussion in 'Tomato Firmware' started by fredz, Jan 27, 2014.

  1. fredz

    fredz Reformed Router Member

    Is there a way to switch the wifi on a tomato router off or on programmatically? Meaning using a certain URL, or some other way? I have multiple router and at certain points I need to switch the wifi on them all off at once. If there's an url switch like IP/wifi.asp?on or IP/wifi.asp?off that would be very interesting. Any ideas?
     
  2. mvsgeek

    mvsgeek Addicted to LI Member

    If the requirement is to do it at specific times of the day, you could create a cron job to run a script. Of course if you shut down the radio and your only connection to the routers is via wireless, you won't be able to restart it:eek:

    Here's a little script to disable wifi for a specific period - rather than use cron, I run it on demand using a PuTTy SSH connection.

    Code:
    #!/bin/sh
    # Script to cycle wireless driver without rebooting
    
    naptime="60"
    
    if [ "$1" != "" ]; then
         naptime="$1"
    fi
    
    logger shutting down radio for "$naptime" seconds...
    wl down
    sleep "$naptime" 
    logger restarting radio...
    wl up
    
    exit 0
    
     
  3. fredz

    fredz Reformed Router Member

    Thanks but it's not to do with a specific time of day...
     
  4. jerrm

    jerrm Network Guru Member

    Something like this could be saved as radio.sh under /www/user:
    Code:
    #!/bin/sh
    echo "<html><head><title>Radio Control</title></head><body>"
    if [ "$QUERY_STRING" = "on" ]; then
      echo "Turning Radio On"
      wl up
    elif [ "$QUERY_STRING" = "off" ]; then
      echo "Turning Radio Off"
      wl down
    else
      echo "Nothing to do!"
    fi
    echo "</body></html>"
    
    Then called as http://routerip/user/radio.sh?off or http://routerip/user/radio.sh?on. You will still need to login with username/password, but tomato will accept credentials in the url if you just have to script it and are OK with the security aspects.
     
    szpunk likes this.
  5. fredz

    fredz Reformed Router Member

    That's great, jerrm, just what I needed! Is there a way to keep this in memory when I reboot. Do I need a usb stick? The router is an RT-AC66U.
    What's the difference between putting it under /www/user as opposed to /var/wwwext?
     
  6. jerrm

    jerrm Network Guru Member

    I use USB, with an init script that creates links to the USB files needed under the /www/user. You could do the same with JFFS or CIFS.

    Alternatively, for something this small, you could use nvram setfile2nvram, or create the script in init. Between the two, I would probably create it in init - but only because I like anything I do to be visible, something like:
    Code:
    s=/www/user/radio.sh
    cat << EOF > $s
    #!/bin/sh
    echo "<html><head><title>Radio Control</title></head><body>"
    case "\$QUERY_STRING" in
    on) echo "Turning Radio On"; wl up;;
    off) echo "Turning Radio Off";wl down;;
    *) echo "Nothing to do!";;
    esac
    echo "</body></html>"
    EOF
    chmod +x $s
    Then call as http://routerip/user/radio.sh?off or http://routerip/user/radio.sh?on. You will still need to login with username/password, but tomato will accept credentials in the url if you just have to script it and are OK with the security aspects.
    They are the same. User is simply a link to wwwext. Just a little friendlier.
     
    Last edited: Jul 16, 2014
  7. fredz

    fredz Reformed Router Member

    Thanks. How do you create it in init exactly? Is init a file you can edit with vi?
     
  8. jerrm

    jerrm Network Guru Member

    Paste what I posted into the init script section of the GUI.
     
  9. fredz

    fredz Reformed Router Member

    Last edited: Jan 28, 2014
  10. jerrm

    jerrm Network Guru Member

  11. fredz

    fredz Reformed Router Member

    Well, the script executes, but the radio state of the wlan doesn't change... Nothing happens.

    When turning it on, it displays
    Turning Radio On wl: Radio Off

    When turning off, it displays
    Turning Radio Off

    But nothing happens to the wifi radio.
     
  12. fredz

    fredz Reformed Router Member

    Fixed it. It should be "wl radio on" and "wl radio off"

    Odd thing is only the 2.4 GHz switches, not the 5 GHz
     
  13. jerrm

    jerrm Network Guru Member

    Odd - either command works on my RTN66U and Belkin test units, but glad you got it working.

    For the 5GHz adapter, assuming it is eth2, try "wl -i eth2 radio off."
     
    Last edited: Jan 29, 2014
  14. fredz

    fredz Reformed Router Member

    Well, actually wl up and wl down also function. But oddly enough, the 5 GHz LED always stays on on the device, even with wl down and wl -i eth2 radio off. It stays on, but the wifi switches off anyway. So I suppose this is some kind of bug. (this also happens when I switch it off over the webinterface.)
    I also couldn't find out the difference between "wl radio on" and "wl up". They do different things, but what exactly is unknown. Even the man file isn't very clear:

    up reinitialize and mark adapter up (operational)
    down reset and mark adapter down (disabled)
    radio Set the radio on or off.
    "on" or "off"

    I want to switch it off so there isn't any "radiation" anymore. I am now giving both commands, but would like to know the difference.
     
    Last edited: Jan 29, 2014
  15. koitsu

    koitsu Network Guru Member

    If I remember correctly (someone please correct me if I'm wrong, but I did dig around the TomatoUSB source for a bit), the wl binary is also closed-source, much like the wireless driver, which means all we know is what the usage syntax says. If there's a bug/oddity there or something that isn't to your liking, there isn't much folks can do about it; we're at the mercy of Broadcom.
     

Share This Page