Wi-Fi on/off buttons

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.

  • This package lacks a graphical interface so for the setup we will need to connect to the OpenWrt device using SSH (remote terminal).
  • Install wifitoggle package with opkg update && opkg install wifitoggle
  • see the new uci configuration for it uci show wifitoggle, you will see something like this
# uci show wifitoggle
  • Do any customizations to the configuration and then save the changes with uci commit

The 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:

  • wps = Wi-Fi protected service, most likely to be free in OpenWrt and also default in wifitoggle
  • wlan = used for buttons that toggle Wi-Fi on/off in stock firmware
  • rfkill = also used for buttons that toggle Wi-Fi on/off in stock firmware
  • wifi = also used for buttons that toggle Wi-Fi on/off in stock firmware, yes there is a bit of creativity going on.
  • power = used to power up some devices, may be bound already to system shutdown function
  • help = unknown, but I see it in the source code of some devices
  • phone = unknown, but I see it in the source code of some devices
  • BTN_0 = unknown, but I see it in the source code of some devices
  • BTN_1 = unknown, but I see it in the source code of some devices
  • ses = cisco services button
  • reset = the reset button, usually already bound to system restart function

:!: 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.


This is how it looks after I deleted and created it again (and is actually working)


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

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

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2023/04/05 16:57
  • by vgaetera