Openwrt 自訂script - 按鍵即開wifi 45 mins

首先建立homewifi.sh

root@openwrt:~# vi /etc/homewifi.sh

#!/bin/bash


if [[ -z "$1" ]]; then
echo "usage: sh $0 [on|off|button]"

exit
fi

if [[ "$1" == "on" ]]; then
echo turn wifi on
uci set wireless.@wifi-iface[0].disabled=0 && uci commit wireless && wifi
exit
fi

if [[ "$1" == "off" ]]; then
echo turn wifi off
uci set wireless.@wifi-iface[0].disabled=1 && uci commit wireless && wifi
exit
fi

if [[ "$1" == "button" ]]; then
uci set wireless.@wifi-iface[0].disabled=0 && uci commit wireless && wifi && sleep 30m && uci set wireless.@wifi-iface[0].disabled=1 && uci commit wireless && wifi
fi

exit


跟著建立自訂鍵功能。

root@openwrt:~# uci add system button
root@openwrt:~# uci set system.@button[-1].button=BTN_3
root@openwrt:~# uci set system.@button[-1].action=pressed
root@openwrt:~# uci set system.@button[-1].handler='sh /etc/homewifi.sh button'
root@openwrt:~# uci add system button
root@openwrt:~# uci set system.@button[-1].button=BTN_3
root@openwrt:~# uci set system.@button[-1].action=released
root@openwrt:~# uci set system.@button[-1].handler='sh /etc/homewifi.sh button'

Reference:
http://jeffkwan.blogspot.hk/2014/12/openwrt.html
http://jeffkwan.blogspot.hk/2015/02/openwrt-buffalo-wzr-hp-g300nh2_15.html

Comments

Popular Posts