FEATURE REQ: WiFi on/off with side switch?

So this seems basic but it would be incredibly useful to me. The current 2 options are VPN on/off or switch between bridge/router modes. Which are also quite useful. But in my use case here, I would love to be able to disable (and enable) the WiFi radio on AR300M with the side slider switch rather than having to ping the web interface to make the adjustment. Any chance?

1 Like

The switch can be programmed to do whatever you like. Just do a forum search on it and you will see!

Find the script of the switch button under /etc/rc.button/

You can also find /etc/init.d/init_switch

OK but how does one go about changing the function? I’m not a Linux expert and not real familiar with LuCi and working at the command prompt level. I just want to change to allow WiFi on/off with the side button toggle as opposed to VPN or router/bridge mode as default options.

1 Like

Agreed this would be a great feature to be included… im not sure how to do this either. Any ideas?

Here is how you can do it, manually.

Find /etc/init.d/initswitch

Turn on wifi when switch on left side

Line 57:

"noop")
;;
*)
uci set wirless.@wifi-iface[0].disabled=0
uci commit wireless
wifi on
;;

Turn off wifi when switch on left side
Line 70 (before editing):

"noop")
;;
*)
uci set wirless.@wifi-iface[0].disabled=1
uci commit wireless
wifi off
;;
2 Likes

Wow already had it down. Thank you so much alzaho, you are so very helpful!

Hello, I’m a fresh new and happy GL.iNet user (owner of a GL-MT300N-V2). I apologize in advance for the length of this post because I’ve dig around and I’ve discovered many things but not all I need. As other users in this topic I wanted to use the hardware switch to enable/disable wifi. I think things has changed because I don’t have any /etc/init.d/initswitch script in my device. I managed to get the result but I don’t like the solution because I had to force some variables value in /usr/bin/switchaction and this could break some functionalities.
Firmware version: 3.012
What I’ve discovered:

  • commands wifionoff on/off work fine to enable/disable wifi
  • the switch fires /etc/rc.button/BTN_0 (I think but I’m not sure) which print something to /dev/console and fires /usr/bin/switchaction
  • /usr/bin/switchaction reads get glconfig.switch_button.enable and glconfig.switch_button.function variables to decide if and what it has to do
  • glconfig.switch_button.function by factory contains “”, not “noop” or something like this (bug?)
  • when we interact with the web interface (MORE SETTINGS>Button Settings) the actions to set the variables start from /usr/share/glweb1/web/src/temple/settings/index.js

What I miss:

  • which script actually set the variables read in /usr/bin/switchaction after /usr/share/glweb1/web/src/temple/settings/index.js has been called

In v3.x firmware, the shell script to operate the slide switch is /usr/bin/switchaction. Actually, you can remove this shell script, and rewrite one.

mv /usr/bin/switchaction /usr/bin/switchaction.bak
touch /usr/bin/switchaction && chmod +x /usr/bin/switchaction
vi /usr/bin/switchaction

Add those line into /usr/bin/switchaction, it will looks like:

#!/bin/sh

switch_action() {
        local switch_left=$(grep -o "BTN_0.*hi" /sys/kernel/debug/gpio)

        if [ -n "$switch_left" ]; then
                # Switch to left
                # TODO
        else
                # Switch to right
                # TODO
        fi
}

switch_action
1 Like

Thank you for your reply. Yes, I’ve already done that, but it’s not exactly what I’m trying to do. It breaks the web interface selector for the switch behaviour. I’d like instead to preserve the possibility of selecting it from the web interface, and I’d like to add an entry to select “WiFi on/off” to it.

Then you can edit /usr/bin/switchaction and web UI source code to achieve this.

This needs a little skills but you don’t have to wait.

Here is a working switchaction that should work on most models:

#!/bin/sh

set_function(){
        model=$(awk -F': ' '/machine/ {print tolower($NF)}' /proc/cpuinfo| cut -d- -f2-)
        switch_left=
        case "$model" in
                "ar150")
                        switch_left=$(grep -o "BTN_8.*hi" /sys/kernel/debug/gpio)
                        ;;
                "ar300m")
                        switch_left=$(grep -o "left.*hi" /sys/kernel/debug/gpio)
                        ;;
                "mt300a")
                        switch_left=$(grep -o "BTN_1.*hi" /sys/kernel/debug/gpio)
                        ;;
                "mt300n")
                        switch_left=$(grep -o "BTN_0.*hi" /sys/kernel/debug/gpio)
                        ;;
                "mt300n-v2")
                        switch_left=$(grep -o "BTN_0.*hi" /sys/kernel/debug/gpio)
                        ;;
                "ar750s")
                        switch_left=$(grep -o "right.*lo" /sys/kernel/debug/gpio)
                        ;;
                "ar750")
                        switch_left=$(grep -o "sw1.*lo" /sys/kernel/debug/gpio)
                        ;;
                "*")
                        switch_disabled="1"
                        ;;
        esac

        #if switch is on left
        if [ -n "$switch_left" ]; then
                wifi down
        else
                wifi up
        fi
}
set_function

this is just what I have been looking for. if all we need to do is modify the last if and else section I would love to be able to set the following addtional features. what commands like “wifi down” and “wifi up” are equivelent to the following without requiring a reboot and restarts network fully for them to take effect.

enable/disable guestwireless = ?

enable/disable ssproxy client = ?
enable/disable ssproxy server = ?
enable/disable wireguard server = ?
enable/disable openvpn server = ?

of course setting button any vpnserver or vpnclient will require shutting down all other vpn client services and vpn servers before the action.

adding features to gl-web button interface would be awesome and might show value add for non programmers. for middle of the road users like myself just listing the commands here would be great. I could just installl luci-app-command and create each button setting as a separate file and use a shell script with a cp command for each selection.

Yes, it can be programmed.