[SOLVED] toggle radio w/ QSS Button does not work TL-WR740N

Post new topic   Reply to topic    DD-WRT Forum Index -> Atheros WiSOC based Hardware
Author Message
daheist
DD-WRT Novice


Joined: 24 Feb 2012
Posts: 6

PostPosted: Fri Aug 17, 2012 19:05    Post subject: [SOLVED] toggle radio w/ QSS Button does not work TL-WR740N Reply with quote
Solution in post #3

Hello,
running this latest version
ftp://ftp.dd-wrt.com/others/eko/BrainSlayer-V24-preSP2/2012/07-20-12-r19519/tplink_tl-wr740nv2/tl-wr740n-webflash.bin (DD-WRT v24-sp2 (07/20/12) std - build 19519) on TP-Link TL-WR740N V2


    Router Webinterface (192.168.1.1) ->
    Services ->
    Services ->
    SES / AOSS / EZ-SETUP / WPS Button ->
    Turning off radio -> Enable


Does not work. Pressing the button seems to do something to the QSS-LED. QSS-LED turnes off but then turns on after 1-2 seconds. WiFi stays on.
Turn radio off at boot -> Enable does not work either. Maybe there is a connection between those two options?

Any idea how to fix it?

QSS Button on this router is gpio number 12.
"1" when not pressed
"0" when pressed


Last edited by daheist on Sun Aug 19, 2012 20:43; edited 3 times in total
Sponsor
daheist
DD-WRT Novice


Joined: 24 Feb 2012
Posts: 6

PostPosted: Sat Aug 18, 2012 17:23    Post subject: Reply with quote
No success so far.

I tried using the following script. I did not write it myself, but modified it to suit my router.

I put comments in the script behind the number sign '#' so that you can understand what I'm trying to do.

(Note that I use the QSS LED (gpio number 0) as W-LAN on/off indicator since you can not really control the W-LAN LED, which apparentely is gpio number 33. QSS button is gpio number 12)

# START OF SCRIPT

#!/bin/sh
while : ; do # This is the start of the loop
WIFI=`nvram get ath0_net_mode` # get mode in variable WIFI
sleep 1;
if [ "$(cat /proc/gpio/12_in )" = "0" ]; then # is QSS button pressed? If so, then...
if [ "$WIFI" == "disabled" ]; then # check if the ath0_net_mode is disabled, we need to turn wifi on then
nvram set ath0_net_mode=mixed # turn it on by setting mixed
/sbin/ifconfig ath0 up # bring interface up
/sbin/gpio disable 0 # light up QSS LED
echo "1" > /proc/gpio/12_in # I dontr really know what this does.
sleep 3

else # run this code if wifi is on and want to turn it off
nvram set ath0_net_mode=disabled # set mode to disabled
/sbin/ifconfig ath0 down # shut interface down
/sbin/gpio enable 0 # turn LED off
echo "1" > /proc/gpio/12_in
sleep 3

fi
fi
done & # end of loop

# END OF SCRIPT

Blue is the loop of the script that gets executed since the script is startet on startup of the router.
Green is the request where it checks whether the button is pressed (0) or not (1).
Red is the request whether wifi is on or not. if wifi is on (ath0_net_mode=mixed), it turns it off. If wifi is off (ath0_net_mode=disabled), it turns it on.

So, I saved it to run on startup. You might think it would work. At least thats what I tought.

What happens:
I turn the router on. After boot wifi is on. You can access network via wifi without problems. QSS LED on (don't ask me why). wifi LED is on.

Now I want to turn wifi off without having to access the webinterface. So I press the QSS button. *press*. QSS LED turns off. wifi LED stays on. wifi still visible. wifi connection breaks. wifi still visible. Computer tries to reconnect, but fails. Shortly after, wifi connection not visible anymore. wifi LED still on.

I try to turn it on again. Pressing QSS button. QSS LED turns on. wifi LED still on. wifi visible. Computer can't connect to network. Only solution is reboot of router.

End of Story.


I can turn wifi on/off via Webinterface. The wifi LED then does turn on and off accordingly. So in principle, it can be done. But not with my script. I need to know what has to be done or what the webinterface does to turn it on/off.

It seems like the wifi LED is a reliable indicator of whether the wifi is really (by that I mean the wifi hardware) on or off.

So what the heck do I want?
I want the QSS button to turn the wifi hardware on or off. And I want it to work reliable.


Last edited by daheist on Sun Aug 19, 2012 20:41; edited 1 time in total
daheist
DD-WRT Novice


Joined: 24 Feb 2012
Posts: 6

PostPosted: Sun Aug 19, 2012 20:39    Post subject: Reply with quote
Sucess!
The script works.

wifi can now be toggled on and off with the QSS button.

It was actually very easy. But it took me hours and I tried and tried and looked around with telnet and so on.

How did I find it out?
Simple. I ran the command "ps" which shows every process. With wifi on, there is a process "hostapd". Witout wifi, the process is gone. Killing the process turns wifi off. Creating the process turns wifi on.

Command to turn wifi off:
kill `ps | grep "hostapd" | awk '{print $1}'`

Command to turn wifi on:
hostapd -B /tmp/ath0_hostap.conf

That's it!
Running these commands really turns on and off the hardware. In idle and with wifi turned off the router is at 250mA @ 9V. In idle and with wifi turned on, the router is at 295mA @ 9V. And it turns on and off the wifi LED accordingly. Great! Exactly what I wanted.

Here is my corrected startup script. Line 2, 3 and 4 is for turning off wifi at startup. If you want wifi to be turned on at startup, simply delete those three lines from the code.

Code:

#!/bin/sh
nvram set ath0_net_mode=disabled
/sbin/ifconfig ath0 down
kill `ps | grep "hostapd" | awk '{print $1}'`
while : ; do
WIFI=`nvram get ath0_net_mode`
sleep 1;
if [ "$(cat /proc/gpio/12_in )" = "0" ]; then
 
  if [ "$WIFI" == "disabled" ]; then
   
    nvram set ath0_net_mode=mixed
    /sbin/ifconfig ath0 up
    hostapd -B /tmp/ath0_hostap.conf
    echo "1" > /proc/gpio/12_in
    sleep 3
      
  else
   
    nvram set ath0_net_mode=disabled
    /sbin/ifconfig ath0 down
    kill `ps | grep "hostapd" | awk '{print $1}'`
    echo "1" > /proc/gpio/12_in
    sleep 3
      
  fi

fi

done &


I have not done much testing, but first results seem promising. The router is not in everyday use yet, so I have no longterm experience with it.

Have fun, I hope it works for you too. Maybe even for TP Link TL-WR741N?
checho
DD-WRT Guru


Joined: 27 Feb 2007
Posts: 527
Location: Bulgaria

PostPosted: Mon Aug 20, 2012 19:26    Post subject: Reply with quote
Good. but with only two suggestions

First, instead of killing hostapd I would generally do stopservice lan and then startservice lan when I want it back. It is less dirty. The problem is that my solution does disable even the wired ports but if you are fine with that - proceed my way.

Second, I would never do nvram set from a script. Imagine if something (or you accidentally) does a nvram commit while ath0_net_mode is disabled? For example ttraff makes commit on some usage statistics or upnp commits some forwardings etc. If a commit occurs at a time when wifi is disabled, it will always be disabled on boot until you commit it manually to be on.
Borage
DD-WRT User


Joined: 26 Nov 2006
Posts: 422

PostPosted: Wed Dec 26, 2012 16:37    Post subject: Reply with quote
Thank you daheist for the information, I also found out that QSS LED turns off when the QSS button is pressed.

Will this issue be fixed in the future?
burcadoruciprian
DD-WRT Novice


Joined: 10 Aug 2012
Posts: 6

PostPosted: Sat Feb 02, 2013 7:26    Post subject: Reply with quote
Works like a charm. Thanks
BLACKDRAGON
DD-WRT Novice


Joined: 24 Feb 2010
Posts: 13

PostPosted: Sun Feb 03, 2013 19:44    Post subject: Reply with quote
I have a TL WR740N v3 and it doesn't work me.

When I push the QSS the light is always OFF and wifi not connect.

Thank you.
hoot_spoot
DD-WRT User


Joined: 07 Dec 2009
Posts: 110
Location: Earth.

PostPosted: Mon May 05, 2014 8:03    Post subject: [SOLVED] for v3, maybe Reply with quote
same device as previous poster, a v3, and the build is 23919 (latest). Script is copied into Startup Commands script box, saved, device rebooted, and it does not turn on when pressing the button.


------------------
[SOLVED]

On the v3, change the GPIO reference in the above script, from "12" to "1".


I tried to re-write the script:
But the radio is normally off, then when pressing the button, only is on for a few seconds then turns off again. :/

Code:
#!/bin/sh
/sbin/ifconfig ath0 down # turn the radio off
nvram set hostap_radio_status=off # set the saved value of the on/off variable to off
while : ; do # begin a loop
WIFI=`nvram get hostap_radio_status` # get the current value of the variable radio on/off
sleep 1;
if [ "$(cat /proc/gpio/1_in )" = "0" ]; then # if the status of the button is pushed-in on the back of the unit:

  WIFI=`nvram get hostap_radio_status` # get the current value of the variable radio on/off
 
  if [ "$WIFI" == "off" ]; then # if the current value of the radio is off
   
    /sbin/ifconfig ath0 up # turn the radio on
    nvram set hostap_radio_status=on # turn the variable radio_status to 'on'
    echo "1" > /proc/gpio/1_in # set the gpio value to 1 (off) 
    sleep 5
       
  else # otherwise if the variable for the radio is not 'off', e.g. 'on', then
     
    /sbin/ifconfig ath0 down # turn the radio off
    nvram set hostap_radio_status=on # turn the variable radio_status to 'off'
    echo "1" > /proc/gpio/1_in # set the gpio value to 1 (off) 
    sleep 5
       
  fi

fi

done &


I am sure i did something wrong with this script but I don't care for this geeky stuff.

_________________
various hw
pejakm
DD-WRT User


Joined: 11 Oct 2012
Posts: 63

PostPosted: Tue May 06, 2014 17:43    Post subject: Re: [SOLVED] for v3, maybe Reply with quote
hoot_spoot wrote:
same device as previous poster, a v3, and the build is 23919 (latest). Script is copied into Startup Commands script box, saved, device rebooted, and it does not turn on when pressing the button.


------------------
[SOLVED]

On the v3, change the GPIO reference in the above script, from "12" to "1".


I tried to re-write the script:
But the radio is normally off, then when pressing the button, only is on for a few seconds then turns off again. :/

Code:
#!/bin/sh
/sbin/ifconfig ath0 down # turn the radio off
nvram set hostap_radio_status=off # set the saved value of the on/off variable to off
while : ; do # begin a loop
WIFI=`nvram get hostap_radio_status` # get the current value of the variable radio on/off
sleep 1;
if [ "$(cat /proc/gpio/1_in )" = "0" ]; then # if the status of the button is pushed-in on the back of the unit:

  WIFI=`nvram get hostap_radio_status` # get the current value of the variable radio on/off
 
  if [ "$WIFI" == "off" ]; then # if the current value of the radio is off
   
    /sbin/ifconfig ath0 up # turn the radio on
    nvram set hostap_radio_status=on # turn the variable radio_status to 'on'
    echo "1" > /proc/gpio/1_in # set the gpio value to 1 (off) 
    sleep 5
       
  else # otherwise if the variable for the radio is not 'off', e.g. 'on', then
     
    /sbin/ifconfig ath0 down # turn the radio off
    nvram set hostap_radio_status=on # turn the variable radio_status to 'off'
    echo "1" > /proc/gpio/1_in # set the gpio value to 1 (off) 
    sleep 5
       
  fi

fi

done &


I am sure i did something wrong with this script but I don't care for this geeky stuff.


I've tried both 1 and 12, it doesn't work for me. I have v3 unit. Sad
pejakm
DD-WRT User


Joined: 11 Oct 2012
Posts: 63

PostPosted: Tue May 06, 2014 19:21    Post subject: Reply with quote
Okay, this is the script which works for me, but I can only toggle it directly from shell (via ssh) with command "gpio enable 1":

Code:

#!/bin/sh
/sbin/ifconfig ath0 down
nvram set hostap_radio_status=off
while : ; do
sleep 1;
if [ "$(cat /proc/gpio/1_in )" = "1" ]; then
  WIFI=`nvram get hostap_radio_status`
  if [ "$WIFI" == "off" ]; then
    /sbin/ifconfig ath0 up
    nvram set hostap_radio_status=on
    gpio disable 1
    sleep 5
  else
    /sbin/ifconfig ath0 down
    nvram set hostap_radio_status=off
    gpio disable 1
    sleep 5
  fi
fi
done &


When I press SES button, nothing happens, it does not trigger anything. :/
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Atheros WiSOC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum