Hello dear,
for the next firmware version (MT3000 or other products) it’s possible add for the side switch/toggle the WiFi ON/OFF feature?
For now I see only VPN on/off for this switch.
THANK YOU!
Hello dear,
for the next firmware version (MT3000 or other products) it’s possible add for the side switch/toggle the WiFi ON/OFF feature?
For now I see only VPN on/off for this switch.
THANK YOU!
Here is a similar topic:
Here’s a ‘modernized’ version to account for dual radio devices.
root@GL-AXT1800:~# cat /etc/gl-switch.d/Wi-Fi.sh
#!/bin/sh
# 2023-07-25
# /etc/gl-switch.d/
# uci show wireless
# source: https://forum.gl-inet.com/t/feature-req-wifi-on-off-with-side-switch/2896/41
action=$1
if [ "$action" = "on" ]; then
uci set wireless.default_radio0.disabled='0'
uci set wireless.default_radio1.disabled='0'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "radios enabled"
fi
if [ "$action" = "off" ]; then
uci set wireless.default_radio0.disabled='1'
uci set wireless.default_radio1.disabled='1'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "radios disabled"
fi
exit 0
See the following for a primer on how to install scripts onto your device (if needed):
I have made adjustments to the script to consider the current status of both 2.4GHz (2g) and 5GHz (5g) WiFi connections.
For example, if I use only the 5g connection, the script ensures that toggling the WiFi on will enable only the 5GHz connection, not both.
Tested with the GL-MT3000 / Beryl AX.
You can customize the default settings to specify a different file or set the default status for both 2g and 5g WiFi connections.
#!/bin/sh
# Default Settings
# File to save the wifi default status
wifi_default_status_file="/etc/wifi_default_status"
# If the wifi default status file is not (yet) available then use these defaults
# 0 = enabled, 1 = disabled
wifi2g_default_disabled=0
wifi5g_default_disabled=0
action=$1
if [ "$action" = "off" ]; then
# Get the default status before disabling
wifi2g_default_disabled=$(uci get wireless.wifi2g.disabled)
wifi5g_default_disabled=$(uci get wireless.wifi5g.disabled)
# Save the default status to the wifi_default_status_file
echo "$wifi2g_default_disabled $wifi5g_default_disabled" > "$wifi_default_status_file"
# if wifi2g is enabled then disable it
if [ "$wifi2g_default_disabled" -eq 0 ]; then
uci set wireless.wifi2g.disabled='1'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi2g disabled"
fi
# if wifi5g is enabled then disable it
if [ "$wifi5g_default_disabled" -eq 0 ]; then
uci set wireless.wifi5g.disabled='1'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi5g disabled"
fi
fi
if [ "$action" = "on" ]; then
# Check if the wifi_default_status_file is available
if [ -f "$wifi_default_status_file" ]; then
# If the file is available read the default status from the file
read -r wifi2g_default_disabled wifi5g_default_disabled < "$wifi_default_status_file"
fi
# if wifi2g is enabled by default then enable it
if [ "$wifi2g_default_disabled" -eq 0 ]; then
uci set wireless.wifi2g.disabled='0'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi2g enabled"
fi
# if wifi5g is enabled by default then enable it
if [ "$wifi5g_default_disabled" -eq 0 ]; then
uci set wireless.wifi5g.disabled='0'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi5g enabled"
fi
fi
sleep 5
Nice. I don’t see a reason for sleep 5
though. exit 0
should close out the script unless you’re eventually going to put in some error handling.
Hi.
Trying your script on a gl-ar750 but don't seem to get any action from it when flipping the switch.
Installed openssh-sftp-server
and used Notepad++ (NppFTP
plugin) to create the file /etc/gl-switch.d/Wi-Fi.sh
with the contents from your post. I can see and select the new option (Wifi On/OFF) in the menu but nothing seem to happen when flipping the switch.
I'm running version 4.3.11
Am i missing any other files or plugins to get it to run?
PS... This would definetely be a great addition to the official firmware.
Is file execute permission (X) on?
That was it I guess, but also...
Before:
File Permissions:
-rw-r--r-- 1 root root 686 Jun 22 12:42 Wi-Fi.sh
-rwxr-xr-x 1 root root 1368 Apr 9 2023 openvpn.sh
-rwxr-xr-x 1 root root 985 Apr 9 2023 wireguard.sh
System log:
Sat Jun 22 12:55:42 2024 user.notice gl-switch: switch pressed
Sat Jun 22 12:55:42 2024 user.notice gl-switch: /etc/gl-switch.d/Wi-Fi.sh can't be exec
Sat Jun 22 12:55:55 2024 user.notice gl-switch: switch released
Sat Jun 22 12:55:55 2024 user.notice gl-switch: /etc/gl-switch.d/Wi-Fi.sh can't be exec
Ran
chmod 755 /etc/gl-switch.d/Wi-Fi.sh
After that:
-rwxr-xr-x 1 root root 686 Jun 22 12:42 Wi-Fi.sh
Sat Jun 22 12:56:44 2024 user.notice gl-switch: switch pressed
Sat Jun 22 12:56:45 2024 user.notice gl-switch: switch released
After fixing the permissions, I didn't get the "can't be exec" error but I still did't see any changes.
I ran the blocks from the code thru ssh
and that makes the correct changes, so the commands were correct still
Ie: will turn the radios off (and even respects the repeater settings, didn't disconect me from the AP I'm connected to)
uci set wireless.default_radio0.disabled='1'
uci set wireless.default_radio1.disabled='1'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "radios disabled"
Then ran the script thru ssh
sh /etc/gl-switch.d/Wi-Fi.sh on
: not foundtch.d/Wi-Fi.sh: line 2:
: not foundtch.d/Wi-Fi.sh: line 6:
: not foundtch.d/Wi-Fi.sh: line 11:
: not foundtch.d/Wi-Fi.sh: line 13:
/etc/gl-switch.d/Wi-Fi.sh: line 65: syntax error: unexpected end of file (expecting "then")
Turns out that, in addition to the file permission, my file was not correctly formatted. I changed the EOL settings from "Windows CR LF" to "Unix LF" and then the file was executing correctly, from both ssh and the switch
This is for @bring.fringe18 's script
I'm adding @pforna 's script too as Wi-Fi2.sh
but that one seems to have a different issue
Best practice by writing / copying scripts is to write them on the device directly instead of uploading them. Using nano
or vi
you can write text files directly via SSH.
For @pforna 's script.
At least on my device, looks like the comands are a little different.
I replaced instances of wireless.wifi2g
and wireless.wifi5g
for wireless.default_radio0
and wireless.default_radio1
and it worked.
Ie:
From:
# Get the default status before disabling
wifi2g_default_disabled=$(uci get wireless.wifi2g.disabled)
wifi5g_default_disabled=$(uci get wireless.wifi5g.disabled)
To:
# Get the default status before disabling
wifi2g_default_disabled=$(uci get wireless.default_radio1.disabled)
wifi5g_default_disabled=$(uci get wireless.default_radio0.disabled)
For reference, my device
Model GL.iNet GL-AR750
Architecture Qualcomm Atheros QCA9533 ver 2 rev 0
OpenWrt Version OpenWrt 22.03.4 r20123-38ccc47687
Kernel Version 5.10.176
Firmware 4.3.11
I am trying also the pforna script modified for my device
A question, why don't you replace wifi2g_default_disabled by wireless.default_radio0.disabled
and wireless.wifi2g.disabled by wireless.radio0.disabled ?
I'm not sure if I'm understanding your question correctly.
I think you are asking if I replaced all the instances of the interfaces in the script, right?
Here's the full working script for the GL-AR750
You need to replace the interface names to what corresponds to your device. ALL the instances.
#!/bin/sh
# Default Settings
# File to save the wifi default status
wifi_default_status_file="/etc/wifi_default_status"
# If the wifi default status file is not (yet) available then use these defaults
# 0 = enabled, 1 = disabled
wifi2g_default_disabled=0
wifi5g_default_disabled=0
action=$1
if [ "$action" = "off" ]; then
# Get the default status before disabling
wifi2g_default_disabled=$(uci get wireless.default_radio1.disabled)
wifi5g_default_disabled=$(uci get wireless.default_radio0.disabled)
# Save the default status to the wifi_default_status_file
echo "$wifi2g_default_disabled $wifi5g_default_disabled" > "$wifi_default_status_file"
# if wifi2g is enabled then disable it
if [ "$wifi2g_default_disabled" -eq 0 ]; then
uci set wireless.default_radio1.disabled='1'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi2g disabled"
fi
# if wifi5g is enabled then disable it
if [ "$wifi5g_default_disabled" -eq 0 ]; then
uci set wireless.default_radio0.disabled='1'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi5g disabled"
fi
fi
if [ "$action" = "on" ]; then
# Check if the wifi_default_status_file is available
if [ -f "$wifi_default_status_file" ]; then
# If the file is available read the default status from the file
read -r wifi2g_default_disabled wifi5g_default_disabled < "$wifi_default_status_file"
fi
# if wifi2g is enabled by default then enable it
if [ "$wifi2g_default_disabled" -eq 0 ]; then
uci set wireless.default_radio1.disabled='0'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi2g enabled"
fi
# if wifi5g is enabled by default then enable it
if [ "$wifi5g_default_disabled" -eq 0 ]; then
uci set wireless.default_radio0.disabled='0'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi5g enabled"
fi
fi
sleep 5
-------------------------------------------------
My device is the GL-AR750
, @pforna 's is the (much newer) GL-MT3000
GL-AR750
is running firmware 4.3.17
(I had 4.3.11
when I wrote the previous post)
GL-MT3000
firmware 4.5.16
I don't have a GT-MT3000
but I have a GL-MT6000
, which is running 4.5.8
Looking at the interfaces in /etc/config/wireless
cat /etc/config/wireless | grep wifi-iface | awk '{print $3}'
For the GL-AR750
I find the following:
'default_radio0'
'default_radio1'
'guest5g'
'guest2g'
'sta'
For the GL-MT6000
I find the following:
'wifi2g'
'wifi5g'
'guest2g'
'guest5g'
I'm going to assume that the interfaces have different names in 4.3
and 4.5
and the uci
command won't work if you are calling the wrong interface name.
If you look at this link, here's a table of the hardware and their firmwares. The ones running 4.5
are "SDK MTK" and "OpenWRT 21.02", while the ones running 4.3
are "Native OpenWrt 22.03.4". I will take a guess that's the difference.
Also, I guess, in theory you could make it so the script turns the guest
interfaces (instead or in addition too) by addding the corresponding commands.
Here are a few changes to include the guest networks.
Notice I reorganized the radios to be in the same order in the file and operations as they are displayed in the widget in the Admin Panel main screen
#!/bin/sh
# Default Settings
# File to save the wifi default status
wifi_default_status_file="/etc/wifi_default_status"
# If the wifi default status file is not (yet) available then use these defaults
# 0 = enabled, 1 = disabled
wifi5g_default_disabled=0
wifi2g_default_disabled=0
wifi5g_guest_disabled=0
wifi2g_guest_disabled=0
action=$1
if [ "$action" = "off" ]; then
# Get the default status before disabling
wifi5g_default_disabled=$(uci get wireless.default_radio0.disabled)
wifi2g_default_disabled=$(uci get wireless.default_radio1.disabled)
wifi5g_guest_disabled=$(uci get wireless.guest5g.disabled)
wifi2g_guest_disabled=$(uci get wireless.guest2g.disabled)
# Save the default status to the wifi_default_status_file
echo "$wifi5g_default_disabled $wifi2g_default_disabled $wifi5g_guest_disabled $wifi2g_guest_disabled" > "$wifi_default_status_file"
# if wifi5g is enabled then disable it
if [ "$wifi5g_default_disabled" -eq 0 ]; then
uci set wireless.default_radio0.disabled='1'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi5g disabled"
fi
# if wifi2g is enabled then disable it
if [ "$wifi2g_default_disabled" -eq 0 ]; then
uci set wireless.default_radio1.disabled='1'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi2g disabled"
fi
# if wifi5g guest is enabled then disable it
if [ "$wifi5g_guest_disabled" -eq 0 ]; then
uci set wireless.guest5g.disabled='1'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi5g guest disabled"
fi
# if wifi2g guest is enabled then disable it
if [ "$wifi2g_guest_disabled" -eq 0 ]; then
uci set wireless.guest2g.disabled='1'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi2g guest disabled"
fi
fi
if [ "$action" = "on" ]; then
# Check if the wifi_default_status_file is available
if [ -f "$wifi_default_status_file" ]; then
# If the file is available read the default status from the file
read -r wifi5g_default_disabled wifi2g_default_disabled wifi5g_guest_disabled wifi2g_guest_disabled < "$wifi_default_status_file"
fi
# if wifi5g is enabled by default then enable it
if [ "$wifi5g_default_disabled" -eq 0 ]; then
uci set wireless.default_radio0.disabled='0'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi5g enabled"
fi
# if wifi2g is enabled by default then enable it
if [ "$wifi2g_default_disabled" -eq 0 ]; then
uci set wireless.default_radio1.disabled='0'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi2g enabled"
fi
# if wifi5g guest is enabled by default then enable it
if [ "$wifi5g_guest_disabled" -eq 0 ]; then
uci set wireless.guest5g.disabled='0'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi5g guest enabled"
fi
# if wifi2g guest is enabled by default then enable it
if [ "$wifi2g_guest_disabled" -eq 0 ]; then
uci set wireless.guest2g.disabled='0'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi2g guest enabled"
fi
fi
sleep 5
What I see in my "wireless" file, is :
wireless.radio0.disabled
wireless.default_radio0.disabled
I don't take in count guest or radio1 to be more simple
So for me logically, for the sense the words have :
wireless.radio0.disabled must replace wireless.wifi2g.disabled
and
wireless.default_radio0.disabled must replace wifi2g_default_disabled
I guess it is the same for you
And I get wireless.default_radio0=wifi-iface
is this not the same than you ?
What's your device?
Does it have two bands or just one?
Ie:
gl-ar300m
(Shadow) doesn't have 5g, only 2g
I edited my previous post
It is an Opal, it has both 5g et 2g
What I can say is that this script doesn't work on Opals ...
#!/bin/sh
wifi_default_status_file="/etc/wifi_default_status"
wireless.default_radio0.disabled=0
wireless.default_radio1.disabled=0
action=$1
if [ "$action" = "off" ]; then
wireless.radio0.disabled=$(uci get wireless.default_radio0.disabled)
wireless.radio1.disabled=$(uci get wireless.default_radio1.disabled)
echo "$wireless.default_radio0.disabled $wireless.default_radio1.disabled" > "$wifi_default_status_file"
if [ "$wireless.default_radio0.disabled" -eq 0 ]; then
uci set wireless.radio0.disabled='1'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi2g disabled"
fi
if [ "$wireless.default_radio1.disabled" -eq 0 ]; then
uci set wireless.radio1.disabled='1'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi5g disabled"
fi
fi
if [ "$action" = "on" ]; then
if [ -f "$wifi_default_status_file" ]; then
read -r wireless.default_radio0.disabled wireless.default_radio1.disabled < "$wifi_default_status_file"
fi
if [ "$wireless.default_radio0.disabled" -eq 0 ]; then
uci set wireless.radio0.disabled='0'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi2g enabled"
fi
if [ "$wireless.default_radio1.disabled" -eq 0 ]; then
uci set wireless.radio1.disabled='0'
uci commit wireless
wifi reload
logger -p notice -t wifi-toggle "wifi5g enabled"
fi
fi
sleep 5
And that with this script, the content of /etc/wifi_default_status is :
.default_radio0.disabled .default_radio1.disabled
it is something that I don't understand, have you got this when it works ?
I'm going to assume you can SSH into your router.
Could you run this please? (exactly as what I typed)
cat /etc/config/wireless | grep wifi-iface | awk '{print $3}
What do you get?
@admon :
I've added the scripts that worked for me and my device to my github.
Would it be okay to offer the files, and instructions of how to download them (using wget
), to @Menard or would that be against the forum guidelines?
Thanks!
It's totally fine, thanks for the support!