Configuring WifiToggle with an actual toggle on GL.iNet Router

First post here and I could use some help! I want to customize the wifitoggle configuration so that the physical toggle on my router can turn the wifi on and off.

I bought this GL-SFT1200 'https://a.co/d/gepB0rU' because it has a physical toggle that slides left and right. The features made it sound like I could customize the button within the router interface. It's true, it can be customized, but only with various VPN configurations by default.

After searching these forums, I found this helpful article: 'https://openwrt.org/docs/guide-user/network/wifi/wifi_toggle'

So I installed my first SSH client, installed Luci on the router, logged in, installed wifitoggle, and was able to see the config like so:

config 'wifitoggle'
	option 'button' 'wps'

	option 'persistent' '0' 
	option 'timer' '600'

	option 'led_sysfs' 'wrt160nl:amber:wps'
	option 'led_enable_trigger' 'timer' 
	option 'led_enable_delayon' '500'
	option 'led_enable_delayoff' '500'
	option 'led_disable_default' '0'

I was then able to edit the config with this: vim /etc/config/wifitoggle and set it up with the following changes...

config 'wifitoggle'
	option 'button' 'wps'

	option 'persistent' '1' 
	option 'timer' '0'

	option 'led_sysfs' 'wrt160nl:blue:wps'
	option 'led_enable_trigger' 'persistent' 
	option 'led_enable_delayon' '500'
	option 'led_enable_delayoff' '500'
	option 'led_disable_default' '0'

I then followed some instructions to hit Esc, then :wq!

I believe it successfully saved the config file, but neither the toggle switch nor the only other button perform any changes.

I'm hoping to slide the toggle to one position where it turns off the wifi, changes the led from green to blue (it has both colors), but still leaves the LAN line active (thus why I cannot simply unplug the device).

I've learned a lot over the last few hours, but I feel I've wasted my whole evening with no results. I would greatly appreciate your expert help.

Powered by LuCI OpenWrt 18.06 r0-d5ed025

It's not a supported device - ToH.

You're using gl.inets derivative of openwrt, ask them.

thank you for your reply @frollic

So you're saying after all that learning curve, OpenWrt 18 simply doesn't support WifiToggle on my device? even though both the GL-iNet admin panel has the WifiToggle plugin that supported easy install, and the OpenWrt displays the config?

I copied my post above and sent it off to GL-iNet; we'll see if they can help or not???

If that's the case, do you know of any routers that have an easy WiFi toggle that keeps the LAN active? Preferably built in by default, but if not, at least customizable with this config?

Don't know, that fw is a black box for us ...

Fingers X:ed.

Gl.inets AR750 does, and I'm pretty sure their other small models do too.

What the switch does, and doesn't, is a configuration thing in openwrt.
I never used the feature myself, but at least you'd get support ... :wink:

The AR750 looks very similar to the SFT-200. All the GL-iNet travel routers have the same button and toggle switch, but upon closer investigation in the documentation, it's only for "switching" modes, like VPN on/off, or router/bridge. But none seem to have the function to toggle WiFi on/off with the slide of a toggle or push of a button.

Seems this would be configurable in OpenWRT, especially if there's a script already given for it.

misread your question, though you were asking about the existence of the button, not the feature ... sorry.

Most Gl devices (and many others) have a button and a switch.
The button defaults to "reset" with variations based on time pressed.
The switch usually has 2 or 3 positions eg mode 1, mode 2 and no mode or off.

Both the button and the switch are simply connected to gpio lines so both are fully programmable.

Gl have done this for specific functions in their firmware.

If you want something different, you need to write a simple daemon that loops and reads the gpio and does what ever you program it to do when something changes.

Whether the package you mention can do this or not, I cannot tell you as I am not familiar with it at all.

Thank you for your reply @bluewavenet. This statement makes me happy and gives me hope. I like the words "fully programmable" :wink:

Can you please show me how to do this? :pray:

Nope. Not in detail anyway, but it is simple enough if you are experienced in ash scripting.
It is hardware dependent.

Generically, your daemon will read the gpio and determine the switch position.
If in the position you want for wireless to be on, then enable wireless.
Sleep for say 5 seconds and loop back to the beginning.
When the gpio for "off" is seen, disable wireless. etc etc.
Loop forever in the background.

I believe no need for daemon.

@zsh7 you can place the proper button file (ask GL-Inet, most likely it's either BTN_0 or BTN_1) into /etc/button.d/ and from that file call the script which will read GPIO (again, ask GL-Inet) and perform actions. Based on your username it should be a walk in the park.

You'd also need to disable GL-Inet's functionality which triggers events based on the slider status, again, you need to ask GL-Inet. TLDR version -- you need to ask GL-Inet peeps unless you're running vanilla OpenWrt downloaded from openwrt.org.

My post was not to detail how to do what the OP was asking for, but to describe the principles involved. The detail is very much hardware dependent.

This would actually be /etc/rc.button, and if the OP is really lucky, the hardware will have an rfkill script associated with the switch, but I doubt it because this is not supported in the OEM firmware as far as I know, because the switch is used for other functions - I have no idea.

The point is - turning wireless on and off via a switch is entirely possible if you are prepared to dig a little and write a suitable script.

Here is what I found on a gl inet AR750. You may have similar setup on SFT1200.

This is running gl-inet firmware, but still of interest to OpenWRT users.
This is running 3.215 which is based on OpenWRT 19.07.

I did not see a /etc/button.d dir

I hacked some of the existing scripts as a proof of concept for what you can do.

Check the gpio mapping

root@GL-AR750:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/18040000.gpio, 18040000.gpio:
 gpio-0   (                    |sw1                 ) in  lo
 gpio-3   (                    |reset               ) in  hi
 gpio-12  (                    |gl-ar750:white:power) out lo
 gpio-13  (                    |gl-ar750:white:wlan5) out lo
 gpio-14  (                    |gl-ar750:white:wlan2) out hi
 gpio-16  (                    |sysfs               ) out hi

Check the rc.button dir

root@GL-AR750:~# cd /etc/rc.button
root@GL-AR750:/etc/rc.button# ls -al
drwxrwxr-x    2 root     root           132 Apr  7  2022 .
drwxrwxr-x    1 root     root             0 Jul 16 22:06 ..
-rwxrwxr-x    1 root     root           292 Apr  7  2022 BTN_0
-rwxrwxr-x    1 root     root           103 Apr  7  2022 BTN_1
-rwxrwxr-x    1 root     root           120 Apr  7  2022 BTN_7
-rwxrwxr-x    1 root     root           236 Apr  7  2022 BTN_8
-rwxrwxr-x    1 root     root            81 Jul 29  2021 power
-rwxrwxr-x    1 root     root           134 Jul 29  2021 reboot
-rwxrwxr-x    1 root     root           167 Apr  7  2022 reset
-rwxrwxr-x    1 root     root           526 Jul 29  2021 rfkill
-rwxr-xr-x    1 root     root          1739 Jul 29  2021 wps

For this device the slider is mapped to BTN_0
hack file to add logger lines to log message when 'pressed'.

root@GL-AR750:/etc/rc.button# cat BTN_0
#!/bin/sh
. /lib/functions/gl_util.sh

#[ $SEEN -gt 0 ] || exit 0

#This is the hidden button of AR300M
logger -t button "button pressed"
logger -t button $BUTTON ${ACTION}
echo "$BUTTON ${ACTION}" > /dev/console

model=$(get_model)
if [ "$model" = e750 ];then
        kill -9 $(pgrep -f "switch_queue")
        switch_queue &
else
        /usr/bin/switchaction &
fi

The switchaction script is where all the action is.
Using GUI, I mapped the slider to OpenVPN 'vpn' in the script.
You have to have an openvpn config to do this mapping in the GUI.

Then I hacked script in the 'vpn' section to turn wifi off or on.
A reboot would turn it back on even thought wifi was turned off.
You could do more elegant script to change config and commit using what they have for vpn as a template.

section from switchaction, see vpn sections with wifi command.

        #if switch is on left
        if [ -n "$switch_left" ]; then
                case "$switch_func" in
                        "wg")
                                check_other_vpn wg
                wgswitch=`uci get wireguard.@proxy[0].enable`
                if [ "$wgswitch" != "1" -o "$wgswitch" != 1 ];then
                        uci set wireguard.@proxy[0].enable='1'
                        uci commit wireguard
                fi
                wgstat=`pidof "wg-crypt-wg0"`
                if [ "$wgstat" = "" -o "$wgstat" = " "  ];then
                        /etc/init.d/wireguard restart
                fi
                        ;;
                        "vpn")
                                wifi down
                        ;;
                        "tor")
                                check_other_vpn tor
                                toggle_tor ON
                        ;;
                        "*")
                        ;;
                esac
        else
                case "$switch_func" in
                        "wg")
                                uci set wireguard.@proxy[0].enable='0'
                                uci commit wireguard
                                /etc/init.d/wireguard stop
                        ;;
                        "vpn")
                                wifi up
                        ;;
                        "tor")
                                toggle_tor OFF
                        ;;
                        "*")
                        ;;
                esac
        fi
1 Like