* [[#​Hotplug_Buttons|Hotplug buttons]], using the hotplug daemon or procd in compatibility mode (hotplug itself was phased out with r36003).

+

* [[#​HID_buttons|HID buttons]], using ///​dev/​input/​event//​ with an application like triggerhappy.

+

+

+

| {{:​meta:​icons:​tango:​dialog-information.png?​nolink}} | **Kernel configuration**\\ If a target platform is known to support buttons, appropriate kernel modules are selected by default.\\ If a platform is not known to support buttons, you are required to install various kernel modules yourself such as ''​diag'',​ ''​input-gpio-buttons'',​ ''​gpio-button-hotplug'',​ and others.\\ However, installing various modules will not necessarily yield a successful result. |

+

+

===== procd buttons =====

+

native button handling in procd is handled by scripts in '''/​etc/​rc.button/​*'''​

+

+

These scripts receive the **same** environment as older style hotplug buttons received. ​ However, the script files have to be named after the button. ​ I am unaware of a way of getting the button name. (Other than using hotplug compatible scripts with procd ;)

1 - "​released"​ action is sent on release even if "​timeout"​ has been sent.

+

===== Hotplug Buttons =====

+

| {{:​meta:​icons:​tango:​48px-outdated.svg.png?​nolink}} | Note that after the introduction of **''​[[doc:​techref:​procd]]''​** into OpenWrt in [[https://​dev.openwrt.org/​changeset/​37132|r37132]] the package ''​hotplug2''​ has been removed from the default packages. ​ However at the time of writing, [[https://​dev.openwrt.org/​changeset/​37336|r37336:​ procd: make old button hotplug rules work until all packages are migrated]] is still in effect. ​ See also [[#​procd.buttons]] |

+

| FIXME | Please read the articles [[doc/​howto/​wifitoggle]],​ [[/​toh/​tp-link/​tl-wr741nd#​buttons]] and [[toh/​linksys/​nslu2/​nslu2.hardware.button]] and eventually merge them into this one article ​ |

+

+

==== Preliminary steps ====

+

+

The first step is to find out the internal name of the button you want to use: some images use generic names such as ''​BTN_1'',​ ''​BTN_2'',​ others have more specific ones like ''​reset'',​ ''​wps'',​ etc. Run the following:

Save and exit. Now press the button you want to use, then run ''​logread''​.

+

+

<code bash>

+

Jan 1 00:01:15 OpenWrt user.notice root: BTN_1

+

Jan 1 00:01:15 OpenWrt user.notice root: pressed ​

+

Jan 1 00:01:16 OpenWrt user.notice root: BTN_1 ​

+

Jan 1 00:01:16 OpenWrt user.notice root: released ​

+

</​code>​

+

+

''​BTN_1''​ is the name of the button you want to use. If you want or need to use another button, replace every instance of ''​BTN_1''​ in the rest of this document with the correct text. From now on, there are several possible approaches: the first uses the ''​00-button''​ script from the ''​atheros''​ target, the other a simpler shell script.

+

+

**notice**

+

+

If you want to run programs from hotplug'​s scripts you need to be sure ''​PATH''​ and the like are initialized properly, scripts invoked by hotplug only have a default env. Especially if you install stuff into nonstandard locations like /​opt/​usr/​bin. It's possible by adding ''​. /​etc/​profile''​ after ''#​!/​bin/​sh''​

+

+

<code bash>

+

#!/bin/sh

+

. /​etc/​profile

+

</​code>​

+

+

==== Using Atheros'​ 00-button + UCI ====

+

If you've installed the full version of ''​wget'',​ run the following:

Please note that after r34793 /​etc/​functions.sh -> /​lib/​functions.sh so if you are using an old version change it!

+

+

Save and exit, then issue these commands:

+

+

<code bash>

+

uci add system button ​ ​

+

uci set system.@button[-1].button=BTN_1

+

uci set system.@button[-1].action=pressed

+

uci set system.@button[-1].handler='​logger BTN_1 pressed'​

+

uci commit system ​

+

</​code>​

+

+

''​button''​ is the name as the button, ''​action''​ is the event (two values: ''​pressed''​ and ''​released''​),​ handler contains the command line to be run when the event is detected (can be a script as well).

+

+

You may need to reboot the router the make the change effective (mine would work with the simple shell script just fine but wouldn'​t budge when using the 00-button script --- //Frex 2011/03/25 22:29//). If this works, you can change the handler to something more useful, and add more button handlers.

You'll have to create the file ''/​usr/​bin/​wifionoff''​ and paste this:

+

<code bash>

+

#!/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

+

</​code>​

+

+

Another option for wifionoff is this script (doesn'​t store the state in uci, so it remains what is set in the configuration)

+

You can also call this script eg. from cron, to switch off your wifi at night.

+

<code bash>

+

#!/bin/sh

+

STATEFILE="/​tmp/​wifionoff.state"​

+

+

if [ $# -eq 1 ]; then

+

case $1 in

+

"​up"​|"​on"​)

+

STATE=off

+

;;

+

"​down"​|"​off"​)

+

STATE=on

+

;;

+

esac

+

else

+

if [ ! -e ${STATEFILE} ]; then

+

STATE=on

+

else

+

. ${STATEFILE}

+

fi

+

fi

+

if [ -z ${STATE} ]; then

+

STATE=on

+

fi

+

+

if [ ${STATE} == "​on"​ ]; then

+

/sbin/wifi down

+

STATE=off

+

else

+

/sbin/wifi up

+

STATE=on

+

fi

+

​

+

echo "​STATE=${STATE}"​ > ${STATEFILE}

+

</​code>​

+

+

**Example 6:** //Set transmission-daemon alt-speed, enable or disable.Short press will activate alt-speed or longer press will deactivate alt-speed and also turns on qss led about speed status on tl-wr1043nd//​

* kernel modules: ​ **kmod-hid** and **kmod-hid-generic** both should be installed\\ The kmod-hid-generic kernel module must be installed for buttons on USB devices such as USB sound cards to work in OpenWrt trunk. Only then the /​dev/​input/​event0 node for the buttons was created on the DIR-505 router with attached USB sound card. <​code>​