This translation is older than the original page and might be outdated. See what has changed.

Wifi Toggle

:!: 软件包'wifitoggle'可以实现和这些代码相同的功能,但更加高级。请参阅Wifi ON OFF buttons

利用下面的脚本,可以用SES按钮来开关WIFI。首先,增加一个热插拔事件的句柄,用以反映按钮按下事件。其次,增加一段开关脚本,根据当前状态来开启或是关闭WIFI。

注意: 如果你使用加密的无线网络,nas 和 radius 守护进程在开关时并不真正关闭,而是继续占用 cpu 和内存资源。但这并不消耗太多的资源,因为根本没有客户端接入。

:!: 这个新版本旨在解决以前在旧脚本中发现的问题。它还使用打开或关闭设备的正确命令 wifi up and wifi down

cat << "EOF" > /sbin/woggle
#!/bin/sh
 
device="wl0"
case $(uci get wireless.$device.disabled) in
    0)
        wifi down $device
        echo 0 > /proc/diag/led/ses_white
        echo 2 > /proc/diag/led/wlan
        echo 1 > /proc/diag/led/power
        uci set wireless.$device.disabled=1
 
        echo "Wifi disabled"
    ;;
    1)
        uci set wireless.$device.disabled=0
        wifi up $device
        echo 1 > /proc/diag/led/ses_white
 
        echo "Wifi enabled"
    ;;
esac
EOF
 
chmod +x /sbin/woggle

不要忘记根据您的情况更改设备的值。

cat << "EOF" > /sbin/woggle-old
#!/bin/sh
 
case "$(uci get wireless.@wifi-device[0].disabled)" in
    1)
        uci set wireless.@wifi-device[0].disabled=0
        wifi
        echo 1 > /proc/diag/led/ses_white
    ;;
    *)
        uci set wireless.@wifi-device[0].disabled=1
        wifi
        echo 0 > /proc/diag/led/ses_white
        echo 2 > /proc/diag/led/wlan
    ;;
esac
EOF
 
chmod +x /sbin/woggle-old

为了跟踪热插拔事件,需要运行以下代码:

mkdir -p /etc/hotplug.d/button
cat << "EOF" > /etc/hotplug.d/button/01-radio-toggle
if [ "$BUTTON" = "ses" -a "$ACTION" = "pressed" ] ; then
        ( sleep 1; /sbin/woggle ) &
fi
EOF

现在,每次你想开关WIFI时就可以通过按按路由器上的按钮来实现了!当然,你也可以通过在OpenWrt shell中调用一个名为woggle的命令来实现。

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: 2022/11/07 16:41
  • by tmomas