Quite a bit of devices come with at least one button (apart from the omnipresent reset/recovery button, which isn't convenient to press), which in the stock firmware is used for WPS, toggling Wi-Fi, or whatever, and on OpenWrt is not usually connected to any function.
In this article we will install and configure a package called wifitoggle, which allows us to configure one of such buttons as a Wi-Fi on/off (toggle) button.
opkg update && opkg install wifitoggleuci show wifitoggle, you will see something like this# uci show wifitoggle
wifitoggle.@wifitoggle[0]=wifitoggle
wifitoggle.@wifitoggle[0].button='wps'
wifitoggle.@wifitoggle[0].timer='600'
wifitoggle.@wifitoggle[0].persistent='0'
wifitoggle.@wifitoggle[0].led_enable_trigger='timer'
wifitoggle.@wifitoggle[0].led_enable_delayon='500'
wifitoggle.@wifitoggle[0].led_enable_delayoff='500'
wifitoggle.@wifitoggle[0].led_disable_default='0'
uci commitThe wifitoggle section contains these settings:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
button |
String | yes | wps | internal name of the button to use. Usually the internal name is similar to what the button did in stock firmware. See notes below this table. |
persistent |
Boolean | yes | 0 | Commit changes to wireless config file, persistent after reset. Always 0 if Timer enabled |
timer |
Integer | yes | 600 | Seconds for Wi-Fi to be turned off, 0 for no timer |
led_sysfs |
String | no | none | Led to use, see Led configuration for possible values |
led_enable_trigger |
String | yes | timer | led trigger name, see Led configuration for other possible led trigger names |
led_enable_delayon |
Integer | yes | 500 | Milliseconds to turn led on after button pressed |
led_enable_delayoff |
Integer | yes | 500 | Milliseconds to turn led off after button pressed |
led_disable_default |
Boolean | yes | 0 | Led state for Wi-Fi disabled, 1 to turn it off if Wi-Fi is off |
:!: Common internal names for button (by searching through the source code) are:
:!: Here's a way to identify the internal name of your button if just trying the above list blindly does not work.
If the script isn't working on your Wi-Fi networks, or it works only on some but not all, try deleting and creating again the ones that don't work.
Default Wi-Fi networks look like this in the config, and it seems the script can't parse that.
wireless.default_radio0=wifi-iface
wireless.default_radio0.device='radio0'
wireless.default_radio0.network='lan'
wireless.default_radio0.mode='ap'
wireless.default_radio0.ssid='myWifi'
wireless.default_radio0.encryption='psk2+tkip+ccmp'
wireless.default_radio0.key='password'
wireless.default_radio0.disabled='1'
This is how it looks after I deleted and created it again (and is actually working)
wireless.@wifi-iface[0]=wifi-iface
wireless.@wifi-iface[0].device='radio0'
wireless.@wifi-iface[0].mode='ap'
wireless.@wifi-iface[0].ssid='myWifi'
wireless.@wifi-iface[0].encryption='psk2+tkip+ccmp'
wireless.@wifi-iface[0].key='password'
Anyone that can fix the script please send a PR from the link below.
If you like to have Wi-Fi disabled after power on, set it disabled by default and then set wifitoggle to NOT save Wi-Fi state changes to permanent memory (so that whatever the state was on reboot it would reset to disabled) with the following:
uci set wireless.@wifi-device[0].disabled=1
uci set wifitoggle.@wifitoggle[0].persistent=0
uci commit
Or add this to /etc/rc.local or in Startup (LuCI System - Startup):
uci set wireless.@wifi-device[0].disabled=1
wifi
This package drops a script called 50-wifitoggle into /etc/hotplug.d/button and this script relies on the OpenWrt Hotplug infrastructure to be called when you press the button.
The other component of its package is the uci configuration file to integrate it with the uci system. See the source here