會員 | 【腳本】WifiToggle for DD-WRT - 以Reset 按鈕當作無線開關, 無線閒置則自動關閉訊號 相信不少網友聽過Tomato & DD-WRT, 也知道兩者功能強大, 兩者都可以將SES/AOSS 按鈕設定為無線開關, 而DD-WRT 更支援無線定時開關, 事實上DD-WRT 可完成的還不只如此, 例如待機一小時就自動關閉無線, 再以SES/AOSS 按鈕當成無線開關等等, 以上需要懂一點硬體 (GPIO 腳位) 和Shell Script SES Button - DD-WRT Wiki LED Scripts - DD-WRT Wiki 引用:
Hardware Button - OpenWrt Wiki Startup Scripts - DD-WRT Wiki Script Execution - DD-WRT Wiki 此篇文章於 2011-06-18 04:44 AM 被 FYI 編輯。. | |
回覆 |
會員 | Use Reset Button as WiFi Toggle v1.3 04/01/10 以下DD-WRT 無線開關腳本wifitoggle.startup 適用於採用Atheros 無線晶片的分享器, 例如La Fonera & La Fonera+, 乃參考 "# 2.8 GPIO Button Wifi Toggle D-Link DIR-300" 改寫而成, 主要修改GPIO 腳位定義, 使用方法為按壓Reset 按鈕一秒以上, 直到WLAN LED 點亮或熄滅, 無線傳輸功率 (Tx Power) 建議介於1-18dBm 之間, 不可為0 (=Off), La Fonera 之韌體設計最大功率為18dBm (63mW), 若設定大於18dBm, 則內部會自動調整為18dBm 請儲存於/jffs/etc/config, 並執行 "chmod +x /jffs/etc/config/wifitoggle.startup" 語法: #!/bin/sh ############################################### # Use Reset Button as WiFi Toggle v1.3 04/01/10 # Hold Reset Button for more than one second # and release it to toggle WiFi on/off # # GPIO Info for La Fonera 2100/2200/2201 # 1 WLAN Orange LED (FON2201) # 2 WLAN Green LED # 6 Reset Button # Copyleft: [email protected] ############################################### # Define GPIO info #WLED1=1 WLED=2 RESET=6 ################################################ # Define 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 ############################################### # ath0_txpwrdbm for La Fonera = 0-18 (63mW) PWR="`nvram get ath0_txpwrdbm`" if [ $PWR -lt 0 ]; then PWR=0 elif [ -z $PWR ] || [ $PWR -gt 18 ]; then PWR=18 fi #nvram set ath0_txpwrdbm=$PWR ############################################### # Check if WiFi disabled if [ `nvram get ath0_net_mode` = disabled ]; then if [ -n "`nvram get ath0_ssid`" ] \ && [ -n "`nvram get ath0_wpa_psk`" ] \ && [ `nvram get ath0_security_mode` != disabled ]; then echo -e "\033[1m\033[41mEnable WiFi and reboot...\033[0m" nvram set ath0_net_mode=mixed nvram commit reboot fi exit fi ############################################### # Leave enough time for /sbin/resetbutton # in case we need to do factory reset while [ -n "`uptime | grep 'up 0 min'`" ]; do sleep 5; done if [ -n "`ps | grep resetbutton`" ]; then killall resetbutton fi ############################################### # Copy cron jobs if exist if [ -e /jffs/etc/crontab ]; then stopservice cron cp /jffs/etc/crontab /tmp startservice cron fi ############################################### T=/proc/gpio/${RESET}_in gpio disable $RESET while sleep 1 do if [ `cat $T` = 1 ]; then WL_STATUS="`ifconfig ath0`" if [ -z $WL_STATUS ]; then gpio disable $RESET continue fi if [ -z "`echo $WL_STATUS | grep UP`" ]; then UP=0 eval $WLED_ON else UP=1 eval $WLED_OFF fi while [ `cat $T` = 1 ]; do gpio disable $RESET sleep 1 done if [ $UP = 0 ]; then iwconfig ath0 txpower $PWR # nvram set ath0_net_mode=$NET ifconfig ath0 up if [ -n "`ifconfig ath0 | grep UP`" ]; then eval $WLED_ON else eval $WLED_OFF fi else # sleep 3 # nvram set ath0_net_mode=disabled ifconfig ath0 down iwconfig ath0 txpower off eval $WLED_OFF fi fi done & 此外, 如果不關閉無線 (nvram set ath0_net_mode=disabled), 改為調整Tx Power (iwconfig ath0 tx off), 似乎也可行, 故下一步將會設法結合無人上線就關閉無線, 如此一來除非需要24hrs 啟動無線, 否則就不需要用到DD-WRT 的定時開關無線功能, 而是有需要就按下無線開關, 閒置一段時間就自動關閉無線 補充: 原始程式有一個重大的缺點, 也就是使用修改NVRAM 變數 "ath0_net_mode" 和關閉無線介面 (ifconfig ath0 down) 的方法關閉無線, 除了這是導致和/sbin/resetbutton 衝突的原因之外, 萬一無線關閉, 而網友又對DD-WRT 進行修改和儲存設定, 則會間接執行 "nvram commit", 以至於重新啟動之後才發現並未啟用無線, 由於小弟的程式碼之中並未對無線介面初始化, 介面初始化是一件很複雜的事, 又牽涉到其後的Bridge Control, VLAN等, 而小弟對於這部份指令 (wlanconfig? iwconfig? brctl? ifconfig?) 尚未瞭解透徹, 所以暫時解決之道就是一旦啟動時發現無線是關閉的, 則設定 "ath0_net_mode=mixed", 並重新啟動 下一個版本會結合閒置就自動關閉無線的功能, 不需要啟用Cron Jobs, 而且採用類似 "wl radio on/off" 或降低Tx Power 的方式停止發射無線訊號, 而非 "wl radio up/down", 不過小弟尚未找到對應於Atheros 的指令, 所以暫時只能以 "ifconfig ath0 up/down" 替代, 對此有興趣的網友不妨參考以下文件 Madwifi/Atheros Wireless Linux Driver Users Guide (2005-12-16) users-guide.pdf (June 2, 2006) UserDocs/WPA_PSK_on_Both_Ends - madwifi-project.org - Trac /src/router/madwifi-fonera/README - DD-WRT - Trac /src/router/rc/resetbutton.c - DD-WRT - Trac /src/router/rc/init.c - DD-WRT - Trac 此篇文章於 2010-04-15 02:23 AM 被 FYI 編輯。. |
回覆 |
會員 | 無線閒置檢查腳本 for Cron 以下腳本 (僅一行) 適用於採用Atheros 無線晶片的分享器, 例如La Fonera, La Fonera+ & D-Link DIR-300-A1, 乃參考 "DD-WRT Forum :: View topic - Scripting help" 修改而成, 請儲存於DD-WRT Administration -> Cron 或/jffs/etc/crontab 或/tmp/crontab, 必須啟用Administration -> Cron, 執行 "stopservice cron && startservice cron" 可令修改後的Cron jobs 立即生效, 作用為每整點和半小時 (*/30) 檢查是否有任何電腦使用無線網路, 若連續兩次檢查都沒有任何電腦使用無線網路, 則自動關閉無線和WLAN LED, 想要省電的網友則不妨改成每隔10 (*/10) 或20 (*/20) 分鐘就檢查一次, 反正開啟無線也只需按一下Reset (請參考#2) 或SES / AOSS 按鈕 引用:
引用:
雖然以上腳本僅適用於採用Atheros 無線晶片, 但和Broadcom 晶片的指令差異不算太大, 小弟列出需要修改的部份, 網友不妨自行修改 [table]Atheros|Broadcom wl_atheros assoclist (wlanconfig ath0 list sta)|wl assoclist ifconfig ath0 up|wl radio up (wl radio on) ifconfig ath0 down|wl radio down (wl radio off) iwconfig ath0 txpower n|wl txpwr1 -d n[/table] 引用:
2.15 WLAN Disable Radio If No Clients Connected CRON - DD-WRT Wiki cron - Wikipedia, the free encyclopedia 此篇文章於 2010-04-10 09:52 PM 被 FYI 編輯。. | |||
回覆 |
會員 | Use Reset Button as WiFi Toggle v1.4 04/04/10 小弟把#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) 本腳本已盡量針對不同機器特性而設計, 但目前僅以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 & 此篇文章於 2010-04-15 02:24 AM 被 FYI 編輯。. |
回覆 |
|
類似的主題 | ||||
主題 | 主題作者 | 討論版 | 回覆 | 最後發表 |
【腳本】WifiToggle - 以 Reset/WPS/QSS 按鈕當作無線開關 | FYI | -- 無 線 網 路 版 | 1 | 2011-04-27 01:29 PM |
請教Fon+(DD-WRT)雙路由如何設定 | rain | -- 網 路 技 術 版 | 2 | 2010-09-14 11:23 PM |
DD-WRT 的WDS連線? | WSC | -- 無 線 網 路 版 | 9 | 2010-03-03 10:28 PM |
DD-WRT 的無線橋接模式整理 | FYI | -- 網 路 硬 體 版 | 7 | 2008-12-30 03:48 PM |
Buffalo WHR-G125 刷 DD-WRT | andesapple | -- 網 路 硬 體 版 | 2 | 2008-09-13 10:31 PM |
XML | RSS 2.0 | RSS |
本論壇所有文章僅代表留言者個人意見,並不代表本站之立場,討論區以「即時留言」方式運作,故無法完全監察所有即時留言,若您發現文章可能有異議,請 email :[email protected] 處理。