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?

2 Likes

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
;;
3 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.

@Nikolas

I know this topic is pretty old at this point, but you seem to be getting very close to what I’m trying to do, only with a different action programmed.

I’m wondering if I can use the switch on the AR750S to swap between router and WAP modes. I can see from your script here that, I think, all I’d need to change from what you’ve written in

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

is making “wifi down” and “wifi up” be instead whatever command I would need to change the functioning mode of the router.

Do you know if this is possible? If so, do you know what I would put there at the end instead of the wifi commands?

Thank you very much for this post, either way. You’ve gotten me at least 10 steps closer to what I’m trying to do!

can you explain this in more detail because what I think what your trying to achieve may already be there.

For sure!

In router mode, the 750 will assign any devices that end up on its WLAN/SSIDs their own IP addresses from its DHCP pool (i.e. 192.168.8.0/24, maybe .200~.250?). In WAP mode, it will just act as a wireless access point, deferring DHCP assignment to the default DHCP server on the network to which it is attached, or requiring the entry of a statically-assigned IP, as the case may be. This is all pretty self-explanatory, of course.

I know I can log in to the admin portal for the device and set it to WAP mode, thereby allowing me to take it on-site to a client’s, plug it into an active network port, and set up my own little WLAN for use working on whatever it is I’m working on. But, AFAIK, in order to get it back in to router mode, for use when I’m out traveling or whatever, I would need to factory reset the device. Or hold the button down for 3 seconds, which I’m not sure what all that does. I guess maybe it’s not a factory reset? Still, would be a pain to have to log in to the thing every time I want to switch it back to WAP mode.

Instead, what I’d like to do is utilize the mode switch next to the reset button to swap between router and WAP modes, if at all possible.

I’ve come across a different-but-related post and added a comment (much like I did here), and received a response from @ThH stating

If you press the reset button 3 sec (power led flashing the fourth time) you can get back to router mode. Somewhere in the /usr/bin/button_released is the script doing this.

If you find that part, you could copy it to a new file in /usr/bin/(example:router_off) and execute that file by adding router_off to the /usr/bin/switchaction.

Haven’t found the scripts that enable other modes (like extender or bridge) but if you find them you could do the same as mentioned above.

So, in combination with the information from @Nikolas above, if I’m able to track down what variables are changed by that button press, I may be able to track down what I need to put in as the action to be performed by the switch moving from position 1 to position 0 or whatever. I plan on looking into this later on, when I’m at home. Currently at work, so I haven’t had any real chance to go digging through those configs in vi.

However, if one of you lovely folks already knows that information, that would be killer!

If no one does, and I figure it out myself, I’ll make sure to make a post about it, just in case someone else needs this information. Though, given my search results so far, I’m apparently the only person who’s ever wanted this particular functionality!

okay so if you leave it in router mode you have a firewall to protect you and all your other devices on your own subnet (192.168.8.0/24). do you have one device or multiple devices accessing the network through the router. is the connectivity requiring a local ip address from the visited network environment

note it does say you have to be careful that you nolonger have access to the router.

If in router mode, it would likely only be my laptop and phone, maybe those of anyone I’m traveling with. Not an issue, and part of why I bought the Slate was to be able to have a travel router, since that’s the main thing it does.

However, it does also have the ability to function as a wireless access point (WAP), which is what I was replacing when I bought it. In that case, I’m only trying to gain access to an extant local network, hence needing a local IP to be assigned to whatever device (work laptop) I’m connecting to my Slate. Being an extant network I’m only trying to gain access to, they already have a firewall, DHCP server, etc. So no need for the router functionality, and beyond that, the Slate acting as a router actually totally defeats the purpose of what I need.

Think of it this way; most home users (though maybe not as many people on these forums) have what they call a “router” at home. And that’s not a total misnomer, as it does function as a router. But it’s also a wireless access point. And, often, a modem, but we’ll ignore that as it’s not germane to this conversation. When in its “router” form, the Slate does the same thing; it routes traffic between networks, and provides WiFi access to said network. However, when it’s in its WAP form, it performs no router functionality, it just provides WiFi access to an already in-place network, which has the necessary means to protect devices connected to it, and to assign IP addresses, and already has its own router for gaining access to the Internet and beyond.

I need the ability to use this as a WAP, but also - occasionally - as a router. Having a nice, built-in little switch that I can just flip as needed would be killer. If I can’t make it happen, oh well, too bad so sad. However, this is Linux. It’s likely not impossible, just need to tell it to do the right things at the right times!

Hope that’s a little clearer for you, and I hope I didn’t misinterpret your question.