Page 1 of 1

About button handler

Posted: Sun Nov 28, 2010 4:05 am
by Cezary
Now in ar71xx target we have button handler. I suggest add in /etc/config/system something like:

Code: Select all

config 'button'
	option button BTN_0
	option action released
	option handler 'reboot'
	option min 5
	option max 10

config 'button'
	option button BTN_0
	option action released
	option handler 'firstboot && reboot'
	option min 30
	option max 120
After push button BTN_0 (reset):
5-10s - reboot
30-120 - restore deafults

I also use

Code: Select all

config 'button'
	option button BTN_1
	option action released
	option handler '/sbin/wifionoff'
	option min 0
	option max 2
to toggle wifi (BTN_1 = qss in tplink 1043, wps in wrt160nl)

/sbin/wifionoff:

Code: Select all

#!/bin/sh
SW=$(uci -q get wireless.@wifi-device[0].disabled)
[ "$SW" == "1" ] && uci set wireless.@wifi-device[0].disabled=0
[ "$SW" == "1" ] || uci set wireless.@wifi-device[0].disabled=1
wifi
Edit: or configure via gui action and time associated with button. Better solution.

Re: About button handler

Posted: Fri Dec 03, 2010 11:45 am
by DoesItMatter
So this currently isn't handled in the GUI, but if we wanted to add
this functionality, we could just edit this ourselves?

Now as far as us editing on our own, if we do a 'reset' by the button,
of course these settings won't come back automatically, so we'd just
have to go in again, after re-configuring, and add these lines again?

is the BTN_0 common across all AR71x series routers?

I.E. - I have a WZR-HP-G300NH

If I added the first config portion lines, that would give me the
ability to do rebooting and a hard-reset of my router?

Re: About button handler

Posted: Sun Dec 26, 2010 4:17 pm
by Cezary
Eric: button handler required both min and max value. Without the max is executed it immediately.

Re: About button handler

Posted: Sun Jan 02, 2011 5:00 pm
by DoesItMatter
Cezary wrote:Eric: button handler required both min and max value. Without the max is executed it immediately.
Cezary,

How do we test what button is Button 0 and Button 1?

Is there a way to do this via command line?

I have a WZR-HP-G300NH and would like to add this in myself
to see if it works, then maybe it can be added officially!

Thanks!

Re: About button handler

Posted: Mon Jan 03, 2011 12:30 pm
by Eric
The main thing is determining the right names for the buttons, after that it's easy. In both the wrt160NL and the TP-link routers BTN_0 is the reset button and BTN_1 is QSS/Arrow button, e.g. "the other one". I'm willing to bet BTN_0 is the the right one on the WZR-HP-G300NH since it's using the same basic hardware architecture, but I can't be sure.

Here's what you can do: ssh into the router and cd into the /etc/init.d/hotplug.d/button directory. Then edit the 00-button script by adding the following to lines to the very bottom of the file:

Code: Select all

logger $ACTION       
logger $BUTTON 
Note that this is case sensitive!!!

Press and release one of the buttons. Then run:

Code: Select all

logread
This will show the system log. You should see four lines indicated by "user.notice root:" in the system log which will be the output. The button name will be indicated on the 2nd and 4th lines.

Re: About button handler

Posted: Mon Jan 03, 2011 7:35 pm
by DoesItMatter
OK - The WZR-HP-G300NH actually has 3 buttons on it!

Reset Button - Bottom of unit -

Jan 3 15:30:45 Gargoyle user.notice root: pressed
Jan 3 15:30:45 Gargoyle user.notice root: BTN_0
Jan 3 15:30:46 Gargoyle user.notice root: released
Jan 3 15:30:46 Gargoyle user.notice root: BTN_0

----------------------------------------------

AOSS Button - Front Panel Top of unit -

Jan 3 15:29:47 Gargoyle user.notice root: pressed
Jan 3 15:29:47 Gargoyle user.notice root: BTN_1
Jan 3 15:29:48 Gargoyle user.notice root: released
Jan 3 15:29:48 Gargoyle user.notice root: BTN_1

-------------------------------------------------

USB Eject Button - Back Panel Top of unit (USB Eject!)

Jan 3 15:30:18 Gargoyle user.notice root: pressed
Jan 3 15:30:18 Gargoyle user.notice root: BTN_2
Jan 3 15:30:18 Gargoyle user.notice root: released
Jan 3 15:30:18 Gargoyle user.notice root: BTN_2

-----------------------------------------------------

So Definitely could setup the Reset pretty easily.

I wonder, if there could be a menu option somewhere,
to assign functionality to each of the buttons?

Like AOSS - turn wireless on/off or maybe USB Eject = Reboot

Just throwing out some ideas

----------------------------------------------------

Code: Select all

config 'button'
   option button BTN_2
   option action released
   option handler 'reboot'
   option min 5
   option max 10
OK - I tried the above code in etc/config/system

Worked! I held in the USB Eject (BTN_2) for 7 seconds,
and the router rebooted - sweet!

Re: About button handler

Posted: Fri Jun 03, 2011 10:09 pm
by argus
Will the wireless on/off via the QSS button be implemented in future version of the gui for the TP Link WR1043ND ?
Any chance of a step by step description of implementing this manually for the newbs like me?

Re: About button handler

Posted: Mon Jun 06, 2011 11:19 am
by DoesItMatter
Argus,

See Eric's post above mine.

He gives info on how you can do your own testing to determine
which button triggers what responses.

Once you find that information out, you can edit the config files
yourself and program the buttons however you wish.

It's not too hard, just re-read the whole post again.

You need to be able to putty into the router and vi edit the file.

Re: About button handler

Posted: Sat Jul 09, 2011 2:00 am
by argus
I managed to get this going on my WR1043ND, the code I used was as follows:

Code: Select all

/etc/config/system

config 'button' 'wifionoff'
	option 'button' 'BTN_1'
	option 'action' 'released'
	option 'handler' '/sbin/wifionoff'
	option 'min' '0'
	option 'max' '2'

Code: Select all

/sbin/wifionoff

#!/bin/sh
SW=$(uci -q get wireless.@wifi-device[0].disabled)
[ "$SW" == "1" ] && uci set wireless.@wifi-device[0].disabled=0
[ "$SW" == "1" ] || uci set wireless.@wifi-device[0].disabled=1
wifi
and finally to make it executable:

Code: Select all

chmod +x /sbin/wifionoff

Re: About button handler

Posted: Sun Nov 05, 2017 10:00 am
by hypersonic
I did the same than argus, but I needed a slightly different /etc/config/system for my WR1043ND v2:

Code: Select all

config button 'wifionoff'
        option button 'rfkill'
        option action 'released'
        option handler '/sbin/wifionoff'
        option min '0'
        option max '2'