Results 1 to 13 of 13

Thread: How to disable the radio whenever possible

  1. #1

    How to disable the radio whenever possible

    Hi!
    I wanted to switch off the radio by using the ez-setup button.
    Here is how I approached the question.

    login (via telnet or ssh)
    create /usr/local/sbin/ez-setup :
    ----
    #!/bin/sh
    TIMEOUT=45
    if [ $(wl radio) = "0x0000" ]; then wl radio off; exit; fi
    wl radio on
    C=$TIMEOUT
    while [ $C -gt 0 ]; do
    printf "\x02" > /dev/gpio/out
    sleep 1
    printf "\x00" > /dev/gpio/out
    sleep 1
    if [ $(wl radio) = "0x0001" ]; then exit; fi
    if [ $(wl assoclist | wc -l) -gt 0 ]; then
    C=$TIMEOUT
    else
    C=$(($C-1))
    fi
    done
    wl radio off
    ----
    then
    chmod +x /usr/local/sbin/ez-setup
    echo "sleep 25; wl radio off" >> /usr/local/sbin/post-boot
    flashfs save && flashfs commit && flashfs enable && reboot

    After you turn on the WL500gp, the radio is switched off. To turn it on, you have to press the ez-setup button for a few seconds. The power led starts flashing (I could not control the air led that is always on, even if the radio is off, at least with the firmware version I am using). If within 90 seconds (2*45, but you can change this value) one client connects to the ssid the connection is maintained otherwise the radio is turned off again.
    As long as at least one client is connected, the radio is kept on.
    After all clients are disconnected the radio is turned off again.
    If you have comments or suggestions, feel free to open a discussion.
    Cheers,
    Luca

  2. #2
    clever

    I may have to try this sometime...

  3. #3

    Question NICE SOLUTION but ...PLEASE COULD YOU...

    Hi all ,especially knulp79 ,
    I am interested in your solution with wifi radio on /off part on this WL-500gP V2 (oleg last firm 10),
    but I dont understand the right commands step by step to do it right.

    so COULD you PLEASE write a small TUTORIAL how to make this your idea easy for non linux programming people ?

    just write where can I find the command line and so on ...

    mabye all thru putty ? or some part thru system setup /system command thru web router managememnt ?? ...

    mabye not write create a file ...but exactly mkdir ... THANKS for your HELP to make this tutorial easy for SMART PEOPLE ...

    OR ANYONE who understand or have these 5min to write it on base of knulp79

    THANKS ,thanks thanks a lot ...

    I think I am not alone who is looking for it ... )

  4. #4

    step by step

    Hi!
    I am sorry if my instructions are not very straightforward.
    I'll try to do my best.
    You must access the "command line" of your wl500gp. You can do it via ssh or via telnet. I thought it was clear enough. If you expected me to write "putty", please consider that putty is just one of the many ssh clients, and that you need some prior work to enable ssh while telnet is present by default (double-check that it is enabled in the web panel). To make the long story short, get access to the prompt in some way, there are a few tutorials in this forum.
    Create a file called /usr/local/sbin/ez-setup with the content below. A way to do it is to type "vi /usr/local/sbin/ez-setup". This editor, vi, is not the most intuitive for novices but you can find some tutorial online. The key commands are "i" to enter the insert text mode, ESC to go back to the command mode, and ":wq" to write and quit.
    ----
    #!/bin/sh
    TIMEOUT=45
    if [ $(wl radio) = "0x0000" ]; then wl radio off; exit; fi
    wl radio on
    C=$TIMEOUT
    while [ $C -gt 0 ]; do
    printf "\x02" > /dev/gpio/out
    sleep 1
    printf "\x00" > /dev/gpio/out
    sleep 1
    if [ $(wl radio) = "0x0001" ]; then exit; fi
    if [ $(wl assoclist | wc -l) -gt 0 ]; then
    C=$TIMEOUT
    else
    C=$(($C-1))
    fi
    done
    wl radio off
    ----
    Then you have to enter the following instructions at the command line.
    chmod +x /usr/local/sbin/ez-setup
    echo "sleep 25; wl radio off" >> /usr/local/sbin/post-boot
    flashfs save && flashfs commit && flashfs enable && reboot
    The first one makes the script above executable. The second switches off the radio by default after the device is booted. The third line saves the new configuration (otherwise it is lost after reboot) and reboots the device.
    Everything should be configured now.
    I am writing this lines without access to the device, so let me know if something does not work (e.g. you can't create /usr/local/sbin/ez-setup because /usr/local/sbin/ does not exist).
    I hope it helps.
    Cheers,
    Luca

  5. #5
    Nice tutorial79 knulp..
    I suppose you can also run this script to execute something else?

    (thinking of a way to stop/start HellaNZB, so I don't have to login to to that.)

  6. #6
    it is possible to modify the script ?!
    when you turn on (reboot) the router the radio to be on (work) by default - and to close only if no one connect to the ssid in a value of time ???!


    Pls , any suggestions ?

    i will appreciate
    Last edited by xplay; 09-11-2008 at 23:23.

  7. #7
    Join Date
    Apr 2008
    Location
    ãîðîä ñàìîâàðîâ è ïðÿíèêîâ
    Posts
    1,492
    knulp79
    Can you explain me, please, how can I program the EZ button by any user code, not only for switch on/off radio.

  8. #8
    Join Date
    Apr 2009
    Location
    Sofia,Bulgaria
    Posts
    29
    Hi,

    I'm not sure what this code is doing and is it necessary ?
    Code:
    while [ $C -gt 0 ]; do
    printf "\x02" > /dev/gpio/out
    sleep 1
    printf "\x00" > /dev/gpio/out
    sleep 1
    I wrote myself a short code , which can be used also if you have enabled cron. In the /usr/local/sbin/ez-setup file I wrote simple code just to switch on/off the wireless. If you remove thecomments it is only 4-5 rows.
    Code:
    #!/bin/sh
    WLAN=`wl isup`
    time=`/bin/date '+%b %e %H:%M:%S'`
    if [ "$WLAN" = "0" ]; then
        echo "$time: Wireless was down, powering up!" >> /tmp/var/log/ez-setup.log && wl radio on
        echo "$time : You have 5 minutes to  connect to the router before wireless automatically shuts down" >> /tmp/var/log/ez-setup-pressed
        sleep 300
        echo "$time : End of 5 minutes" >> /tmp/var/log/ez-setup.log
        rm /tmp/var/log/ez-setup-pressed
     else
        echo "$time: Wireless was up, powering down!" >> /tmp/var/log/ez-setup.log && 
        wl radio off
    fi
    When I press the ez-setup, it starts/stops the wireless and creates "flag" file in order to mark that the button was pressed.

    Then in the cron I start the following script to disable the wireless if it is not used. The purpose of the "flag" file is to assure that the wireless will be on for at least 5 minutes, so we can connect. Without it it may happen that we will switch on the wireless and in 10 seconds cron may stop it.
    You may put this code in a script and start it every 5 minutes using cron.
    Code:
    #!/bin/sh
    
    time=`/bin/date '+%b %e %H:%M:%S'`
    
    WLAN=`wl isup`
    if [ "$WLAN" = "0" ]; then
    #echo "$time : Wireless is already down ! " >> /opt/var/log/ez-setup.log
    exit
    fi
    
    if [ -f /tmp/var/log/ez-setup-pressed ]; then 
    #echo "$time : Stop file still exists" >> /opt/var/log/ez-setup.log 
    exit
    fi
    
    if [ $(wl assoclist | wc -l) -gt 0 ]; then 
    #echo "$time : Wireless devices still connected" >> /opt/var/log/ez-setup.log 
    exit
    fi
    
    echo "$time : Wireless automatically down " >> /tmp/var/log/ez-setup.log 
    wl radio off
    Last edited by zerg; 26-09-2009 at 21:10.

  9. #9

    wifi led working disable other

    Hy in this new (latest version) of oleg wifi led it turns off and on with the wireless device , so i do not need the power led to blink, wich line i take it out from the original code here to stop the power led blinking ??


    10x

    BTW , great work with ez button

  10. #10

    How to turn wireless on / off with EZ-SETUP button

    Quote Originally Posted by tmsulica View Post
    Hy in this new (latest version) of oleg wifi led it turns off and on with the wireless device , so i do not need the power led to blink, wich line i take it out from the original code here to stop the power led blinking ??
    I don't know what you mean by the original code.
    I'm using 1.9.2.7-d-r740 and the wireless led turns on/off automatically with 'wl radio on' and 'wl radio off' commands.

    Here's a simple script which turns wireless on/off and logs the event to syslog when ez-setup is pressed:

    Code:
    #!/bin/sh
    WLAN=`wl isup`
    if [ "$WLAN" = "0" ]; then
        logger -t EZ-SETUP "button pressed: wireless turned ON" && wl radio on
     else                                                                     
        logger -t EZ-SETUP "button pressed: wireless turned OFF" && wl radio off
    fi
    Edit: and the script in question is of course /usr/local/sbin/ez-setup
    Last edited by RDF; 24-01-2010 at 10:27. Reason: edit2: changed to use logger instead of directly echoing to syslog.log

  11. #11
    The power led starts flashing (I could not control the air led that is always on, even if the radio is off, at least with the firmware version I am using). If within 90 seconds (2*45, but you can change this value) one client connects to the ssid the connection is maintained otherwise the radio is turned off again.
    As long as at least one client is connected, the radio is kept on.
    By original I mean from the first post here, and he says that he could not control air led so he is making the power led flashing, i don't want power led to flas, so I wonder which line comands the led ( POWER LED) to flas so i can take it out, so only air led go on or of , as the state is.
    10x for answer anyway!

  12. #12

    segmentation fault

    Hi there,
    THIS is exactly what I was looking for! Thanks, Knulp79 and RDF.

    The RDF's script works for me, but I would appreciate to power the wifi off after the connection is lost for a set time. The Knulp79's script supposedly does that but I always get "Segmentation fault" message when I run it. What's wrong? (I am a beginner to Linux and have no idea about what is Cron so I can't try the zerg's code).

    One remark (confused me for quite some time): the "wl radio on/off" command is NOT equal to "Enable Radio" in Advanced Wireless configuration menu! The command only works when that one is set to Yes. If it is set to No, then the script only powers on/off the AIR led, but the wireless doesn't start.

  13. #13
    I tried what other people suggested and here is what works for me.

    I am using the "cron approach" as suggested by zerg, since cron is already part of the firmware I use (1.9.2.7-d-r2381). I created the following 4 files, none of them existed before
    /usr/local/sbin/ez-setup
    /usr/local/sbin/cron.stop-wlan
    /usr/local/sbin/post-boot
    crontab

    First file is for tunring wlan on/off with the EZ-SETUP button. Second file is used by cron daemon for peridical checking whether wlan is idle and turning it off in that case. Third file is used for starting cron daemon and creating the required ez-setup log file: Fourth file is configuration from crond.

    These files then need to be saved to be available after reboot.

    In the rest of the post, I will be verbose (enough, hopefully) for non-linux guys to be able to get it done. I do assume, though, that you know how to login to the router via telnet or ssh. If this is a problem, I can provide instructions upon request. Befroe anythign else, some words on the vi editor.

    QUICK'n'DIRTY VI GUIDE

    Files are created with the vi editor, which is rather cumbersome, but here is a quick'n'dirty vi survival guide (google also for "vi cheatsheet"):
    1) vi foo - create new/edit existing file "foo"

    2) Once editing a file, vi can work in command mode and insert mode. Vi starts in command mode, bottom line in the file indicates which teh current mode. Switching between the modes is done with commands:
    2a) i - switch from command to insert mode
    2b) o - switch from command to insert mode (new line)
    2c) ESC - switch from insert to command mode


    3) In command mode, one can move around in the file, copy/paste/delete text, enter the insert mode, save changes/file, and exit vi with commands:
    3a) arrow keys - move around teh text in the file
    3b) x - delete a character
    3c) dw - delete a word
    3d) dd - dele the whole line of text
    3e) J - delete the "newline" character, i.e. join lines
    3f) yy - copy the whole line of text
    3g) p - paste copied line in the next row
    3h) i - switch to insert mode
    3i) o - open new line and switch to insert mode
    3j) u - undo last command
    3k) :w - save changes
    3l) :q - exit vi editor
    3m) :q! - exit vi editor WITHOUT SAVING CHANGES
    3n) :wq - save changes and exit vi

    4) in insert mode, anything one types is added to the text in the file.USeful commands
    4a) ESC - exit insert mode
    4b) Shift+Insert - paste the text you copied from somewhere else (not the vi editor), eg. the code from this post


    BACK TO BUSINESS

    First, check if there is a /usr/local/sbin/ directory with directory listing command:
    ls /usr/
    ls /usr/local

    I had to create it with the command
    mkdir /usr/local/sbin

    Change to the /usr/local/sbin/ directory with:
    cd /usr/local/sbin/

    1) EZ-SETUP

    Here is command sequence for creating the ez-setup file
    1.1.) vi ez-setup - create/open file with vi editor
    1.2.) i - enter the vi insert mode
    1.3.) copy my ez-setup code provided below in the post
    1.4.) Shift+Insert - paste the copied code into your vi editor, i.e. your file
    1.5.) ESC - exit vi insert mode
    1.6.) :wq - save file and quit vi editor


    My ez-setup file to copy and paste.

    #!/bin/sh
    WLAN=`wl isup`
    time=`/bin/date '+%b %e %H:%M:%S'`

    if [ ! -f /tmp/var/log/ez-setup.log ] ; then
    echo "$time: EZ-SETUP - Created ez-setup log file." > /tmp/var/log/ez-setup.log
    fi

    if [ "$WLAN" = "0" ]; then
    echo "$time: EZ-SETUP - Wireless was down, powering up!" >> /tmp/var/log/ez-setup.log && wl radio on
    if [ ! -f /tmp/var/log/ez-setup-pressed ] ; then
    echo "$time: EZ-SETUP - You have 2 minutes to connect to the router before wireless automatically shuts down" > /tmp/var/log/ez-setup-pressed
    else
    echo "$time: EZ-SETUP - You have 2 minutes to connect to the router before wireless automatically shuts down" >> /tmp/var/log/ez-setup-pressed
    fi
    sleep 120
    time=`/bin/date '+%b %e %H:%M:%S'`
    echo "$time: EZ-SETUP - End of 2 minutes" >> /tmp/var/log/ez-setup.log
    rm /tmp/var/log/ez-setup-pressed
    else
    echo "$time: EZ-SETUP - Wireless was up, powering down!" >> /tmp/var/log/ez-setup.log && wl radio off
    fi




    2) CRON.STOP-WLAN

    Here is command sequence for creating the cron.stop-wlan file
    2.1.) vi ez-setup - create/open file with vi editor
    2.2.) i - enter the vi insert mode
    2.3.) copy my cron.stop-wlan code provided below in the post
    2.4.) Shift+Insert - paste the copied code into your vi editor, i.e. your file
    2.5.) ESC - exit vi insert mode
    2.6.) :wq - save file and quit vi editor

    My cron.stop-wlan file to copy and paste.

    #!/bin/sh

    time=`/bin/date '+%b %e %H:%M:%S'`

    if [ ! -f /tmp/var/log/ez-setup.log ] ; then
    echo "$time : CRON - Created ez-setup log file." > /tmp/var/log/ez-setup.log
    fi

    WLAN=`wl isup`
    if [ "$WLAN" = "0" ]; then
    #echo "$time : CRON - Wireless is already down ! " >> /tmp/var/log/ez-setup.log
    exit
    fi

    if [ -f /tmp/var/log/ez-setup-pressed ]; then
    #echo "$time : CRON - Stop file still exists" >> /tmp/var/log/ez-setup.log
    exit
    fi

    if [ $(wl assoclist | wc -l) -gt 0 ]; then
    #echo "$time : CRON - Wireless devices still connected" >> /tmp/var/log/ez-setup.log
    exit
    fi

    echo "$time : CRON - Wireless automatically down " >> /tmp/var/log/ez-setup.log
    wl radio off



    3) POST-BOOT

    Here is command sequence for creating the post-boot file
    3.1.) vi ez-setup - create/open file with vi editor
    3.2.) i - enter the vi insert mode
    3.3.) copy my post-boot code provided below in the post
    3.4.) Shift+Insert - paste the copied code into your vi editor, i.e. your file
    3.5.) ESC - exit vi insert mode
    3.6.) :wq - save file and quit vi editor

    My post-boot file to copy and paste.

    #!/bin/sh
    /usr/sbin/crond
    time=`/bin/date '+%b %e %H:%M:%S'`
    if [ ! -f /tmp/var/log/ez-setup.log ] ; then
    echo "$time: REBOOT - Created ez-setup log file." > /tmp/var/log/ez-setup.log
    fi

    4) CRONTAB

    Here is command sequence for creating the crontab file
    4.1.) crontab -e - create/open file with vi editor
    4.2.) i - enter the vi insert mode
    4.3.) copy my post-boot code provided below in the post
    4.4.) Shift+Insert - paste the copied code into your vi editor, i.e. your file
    4.5.) ESC - exit vi insert mode
    4.6.) :wq - save file and quit vi editor

    My crontab file to copy and paste – only one line. It checks every 5 minutes whether to stop wlan, you can change 5 to a different period (google for " man 5 crontab")

    */5 * * * * /usr/local/sbin/cron.stop-wlan


    5) MAKE FILE EXECUTABLE
    the 3 scripts in the /usr/local/sbin directory have to be made executable with

    chmod +x /usr/local/sbin/ez-setup
    chmod +x /usr/local/sbin/cron.stop-wlan
    chmod +x /usr/local/sbin/post-boot

    6) SAVE FILES
    Use these commands to save files, so that they are availabe after reboot

    echo "/var/spool/cron/crontabs/admin" > /usr/local/.files
    flashfs save && flashfs commit && flashfs enable && reboot


    I think this is it. Feedback welcome.
    Last edited by skoskila; 10-12-2011 at 23:46.

Similar Threads

  1. help pls! radio doesn't work in 1.9.7.5 firmware
    By anpspb in forum WL-500gP Q&A
    Replies: 12
    Last Post: 26-01-2008, 20:41
  2. How can I disable radio?
    By maradamc in forum WL-500gP Firmware Discussion
    Replies: 6
    Last Post: 22-01-2008, 22:19
  3. Scripting or automatic disable Radio
    By airone in forum WL-500g Q&A
    Replies: 2
    Last Post: 15-12-2005, 15:39
  4. Disable radio
    By Marrik in forum WL-500g Q&A
    Replies: 8
    Last Post: 26-02-2005, 17:04
  5. The right way to disable radio (physical)
    By mamici in forum WL-500g Q&A
    Replies: 2
    Last Post: 04-11-2004, 15:41

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •