小弟把#2, #3 結合成一支腳本就可以完成以Reset 按鈕當作無線開關, 並且閒置一段時間即可自動關閉無線, 首先, 當無線開啟中按下Reset 按鈕一秒鐘, 直到Power LED 熄滅才放開, 則可以關閉無線, 此時WLAN LED 熄滅, 當無線關閉中按下Reset 按鈕一秒鐘, 直到WLAN LED 點亮才放開, 則可以啟用無線, 若任何時間長按Reset 按鈕直到Power LED 開始明滅交替, 且於Power LED 點亮時放開Reset 按鈕, 則可以關閉無線閒置檢查, 此時無線頻道並不會改變, 若於Power LED 熄滅時放開Reset 按鈕, 則可以重新啟用無線閒置檢查, 若無線閒置檢查作用中, 則Power LED 會每隔5 秒鐘閃爍一次, 若無線關閉或停止無線閒置檢查, 則Power LED 恆亮
本腳本主要適用於只有一個按鈕 (Reset) 的無線分享器, 新一點的機器多半都有SES / AOSS / WPS 等按鈕或硬體無線開關, 所以只要配合使用#3 無線閒置檢查腳本即可
有一點需注意的是, 原本Reset 按鈕的功能 (/sbin/resetbutton) 只有在開機第一分鐘才有作用, 這是為了萬一需要恢復DD-WRT 預設值而設計, 過了第一分鐘之後, 則Reset 按鈕只能當作無線開關, v1.3 (#2) 腳本也有相同設計
在一個眾多AP 訊號的環境中, 建議於DD-WRT Wireless 頻道設定中選擇 "自動", 以便讓DD-WRT v24 自動選擇一個干擾較少的頻道, 但網友仍可以透過關閉再開啟無線的方式, 讓DD-WRT v24 重新選擇別的頻道, 不過重複幾次以後可能會發現DD-WRT 只會在兩三個頻道之中切換, 這可能是因為頻道都被佔用, 所以DD-WRT 只能盡量選擇干擾較少的頻道
對於不支援JFFS/MMC 的分享器來說, 由於程式碼並不小, 因此可能無法儲存於NVRAM (rc_startup), 變通的辦法則是儲存於網路上, 再以wget 下載至/tmp, 然後執行 "chmod +x /tmp/wifitoggle.startup && /tmp/wifitoggle.startup", 請把以上指令儲存於DD-WRT Administration Commands Firewall 腳本 (rc_firewall) (http://192.168.1.1/Diagnostics.asp)
本腳本已盡量針對不同機器特性而設計, 但目前僅以La Fonera+ 測試無誤, 原則上只需修改GPIO 腳位定義, 就可以用於採用Atheros 無線晶片的分享器, 請將腳本儲存為/jffs/etc/config/wifitoggle.startup, 並執行 "chmod +x /jffs/etc/config/wifitoggle.startup"
#!/bin/sh
################################################
# Use Reset Button as WiFi Toggle v1.4 04/04/10
# Hold Reset Button till Power LED goes off or
# WLAN LED goes on to toggle WiFi off/on.
# Continuing holding Reset Button till Power LED
# starts blinking can toggle WiFi idle check.
# Release Reset Button while Power LED On will
# disable WiFi idle check (WiFi always on).
# Release Reset Button while Power LED Off will
# enable WiFi idle check. The Power LED will
# blink every 5 seconds to notify idle check.
# WiFi idle for a pre-defined period and auto
# shutdown. The Power LED stops blinking.
#
# GPIO Info for La Fonera 2100/2200/2201
# 1 WLAN Orange LED (FON2201)
# 2 WLAN Green LED
# 4 Power Green LED (FON2201)
# 6 Reset Button
# 7 Power Orange LED (FON2200/2201)
# Copyleft:
[email protected]
################################################
# Define GPIO info
WLED=2
PLED=7
RESET=6
# Comment out unused GPIO pins or set them to
# $WLED and $PLED to create short blink effect.
#WLED1=1
#PLED1=4
# Define maximum WiFi idle period of minutes
MAX_IDLE=30
# Define maximun TxPower in dBm. 18 for Fonera
MAXTXPWR=18
################################################
# Define Power and WLAN LEDs on/off
for UP in $WLED1 $WLED
do
T=$WLED_OFF"gpio enable $UP;"
WLED_OFF="gpio disable $UP;"$WLED_ON
WLED_ON=$T
done
for UP in $PLED $PLED1
do
T=$PLED_OFF"gpio enable $UP;"
PLED_OFF="gpio disable $UP;"$PLED_ON
PLED_ON=$T
done
################################################
# Get WiFi interface name from "wl0_ifname"
IFNAME="`nvram get wl0_ifname`"
# If WiFi disabled then exit
if [ -z $IFNAME ] || [ -z "`ifconfig $IFNAME`" ] \
|| [ "`nvram get ${IFNAME}_net_mode`" = disabled ]; then
exit
fi
################################################
case $IFNAME in
ath?) PWR="`nvram get ${IFNAME}_txpwrdbm`" ;;
eth?) PWR="`nvram get wl0_txpwr`" ;;
*) exit ;;
esac
if [ $PWR -lt 0 ]; then
PWR=0
elif [ -z $PWR ] || [ $PWR -gt $MAXTXPWR ]; then
PWR=$MAXTXPWR
fi
case $IFNAME in
ath?)
WL_CMD=wl_atheros
SET_PWR="iwconfig $IFNAME txpower $PWR"
SET_PWR_OFF="iwconfig $IFNAME txpower off"
RADIO_ON="$SET_PWR; ifconfig $IFNAME up"
RADIO_OFF="ifconfig $IFNAME down; $SET_PWR_OFF" ;;
eth?)
WL_CMD=wl
SET_PWR="wl txpwr1 -d $PWR"
SET_PWR_OFF="wl txpwr1 -d 0"
RADIO_ON="$SET_PWR; wl radio on"
RADIO_OFF="wl radio off; $SET_PWR_OFF" ;;
esac
################################################
# Leave enough time for /sbin/resetbutton
# in case we need to do factory reset
while [ -n "`uptime | grep 'up 0 min'`" ]; do sleep 10; done
if [ -n "`ps | grep resetbutton`" ]; then
killall resetbutton
fi
################################################
T=/proc/gpio/${RESET}_in
gpio disable $RESET
IDLE_CHK=1
SEC=0
MIN=0
while sleep 1
do
if [ `cat $T` = 1 ]; then
WL_STATUS="`ifconfig $IFNAME`"
if [ -z $WL_STATUS ]; then
gpio disable $RESET
continue
fi
if [ -z "`echo $WL_STATUS | grep UP`" ]; then
UP=0
eval $WLED_ON
IDLE_CHK=1
else
UP=1
eval $PLED_OFF
fi
SEC=1
MIN=0
while [ `cat $T` = 1 ]; do
gpio disable $RESET
if [ $SEC = 0 ]; then
SEC=1
if [ $MIN -ge 2 ]; then
# UP=0
eval $PLED_OFF
IDLE_CHK=1
fi
else
SEC=0
let MIN+=1
if [ $MIN -ge 2 ]; then
UP=0
eval $PLED_ON
IDLE_CHK=0
fi
fi
sleep 2
done
if [ $UP = 0 ]; then
eval $RADIO_ON
if [ -n "`ifconfig $IFNAME | grep UP`" ]; then
eval $WLED_ON
else
eval $WLED_OFF
IDLE_CHK=0
fi
else
eval $RADIO_OFF
eval $WLED_OFF
IDLE_CHK=0
fi
eval $PLED_ON
SEC=0
MIN=0
fi
if [ $IDLE_CHK = 0 ]; then continue; fi
let SEC+=1
if [ $(( $SEC % 5 )) -eq 0 ]; then eval $PLED_OFF; else eval $PLED_ON; fi
if [ $SEC -ge 60 ]; then
SEC=0
WL_STATUS="`ifconfig $IFNAME`"
if [ -z $WL_STATUS ]; then
eval $PLED_ON
IDLE_CHK=0
continue
fi
if [ -n "`echo $WL_STATUS | grep UP`" ]; then
if [ -z "`$WL_CMD assoclist`" ]; then
let MIN+=1
else
MIN=0
fi
else
eval $PLED_ON
IDLE_CHK=0
fi
fi
if [ $MIN -ge $MAX_IDLE ]; then
eval $RADIO_OFF
eval $WLED_OFF
eval $PLED_ON
IDLE_CHK=0
fi
done &
下一個版本可能會設法增加一點彈性, 例如將閒置時間變數儲存於NVRAM, 如此一來修改比較方便, 此外為了顧及可能不方便操作Reset 按鈕, 也許可以透過某台網線連接的電腦下達指令, 以便恢復無線, 當然最理想的結果是可以自動偵測是否要求建立連線, 不過小弟目前還不知道該如何進行