About button handler

Discuss the technical details of Gargoyle and ongoing development

Moderator: Moderators

Cezary
Posts: 133
Joined: Thu Sep 11, 2008 12:57 pm
Location: Poland
Contact:

About button handler

Postby Cezary » Sun Nov 28, 2010 4:05 am

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.

User avatar
DoesItMatter
Moderator
Posts: 1373
Joined: Thu May 21, 2009 3:56 pm

Re: About button handler

Postby DoesItMatter » Fri Dec 03, 2010 11:45 am

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?
:twisted: Soylent Green Is People! :twisted:
2x Asus RT-N16 = Asus 3.0.0.4.374.43 Merlin
2x Buffalo WZR-HP-G300NH V1 A0D0 = Gargoyle 1.9.x / LEDE 17.01.x
2x Engenius - ESR900 Stock 1.4.0 / OpenWRT Trunk 49400

Cezary
Posts: 133
Joined: Thu Sep 11, 2008 12:57 pm
Location: Poland
Contact:

Re: About button handler

Postby Cezary » Sun Dec 26, 2010 4:17 pm

Eric: button handler required both min and max value. Without the max is executed it immediately.

User avatar
DoesItMatter
Moderator
Posts: 1373
Joined: Thu May 21, 2009 3:56 pm

Re: About button handler

Postby DoesItMatter » Sun Jan 02, 2011 5:00 pm

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!
:twisted: Soylent Green Is People! :twisted:
2x Asus RT-N16 = Asus 3.0.0.4.374.43 Merlin
2x Buffalo WZR-HP-G300NH V1 A0D0 = Gargoyle 1.9.x / LEDE 17.01.x
2x Engenius - ESR900 Stock 1.4.0 / OpenWRT Trunk 49400

Eric
Site Admin
Posts: 1436
Joined: Sat Jun 14, 2008 1:14 pm

Re: About button handler

Postby Eric » Mon Jan 03, 2011 12:30 pm

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.

User avatar
DoesItMatter
Moderator
Posts: 1373
Joined: Thu May 21, 2009 3:56 pm

Re: About button handler

Postby DoesItMatter » Mon Jan 03, 2011 7:35 pm

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!
:twisted: Soylent Green Is People! :twisted:
2x Asus RT-N16 = Asus 3.0.0.4.374.43 Merlin
2x Buffalo WZR-HP-G300NH V1 A0D0 = Gargoyle 1.9.x / LEDE 17.01.x
2x Engenius - ESR900 Stock 1.4.0 / OpenWRT Trunk 49400

argus
Posts: 4
Joined: Fri Jun 03, 2011 9:59 pm

Re: About button handler

Postby argus » Fri Jun 03, 2011 10:09 pm

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?

User avatar
DoesItMatter
Moderator
Posts: 1373
Joined: Thu May 21, 2009 3:56 pm

Re: About button handler

Postby DoesItMatter » Mon Jun 06, 2011 11:19 am

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.
:twisted: Soylent Green Is People! :twisted:
2x Asus RT-N16 = Asus 3.0.0.4.374.43 Merlin
2x Buffalo WZR-HP-G300NH V1 A0D0 = Gargoyle 1.9.x / LEDE 17.01.x
2x Engenius - ESR900 Stock 1.4.0 / OpenWRT Trunk 49400

argus
Posts: 4
Joined: Fri Jun 03, 2011 9:59 pm

Re: About button handler

Postby argus » Sat Jul 09, 2011 2:00 am

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

hypersonic
Posts: 1
Joined: Sun Nov 05, 2017 9:49 am

Re: About button handler

Postby hypersonic » Sun Nov 05, 2017 10:00 am

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'


Return to “Gargoyle Development”

Who is online

Users browsing this forum: No registered users and 2 guests