Netgear WNDR3800 WPS按钮切换LED灯

Netgear WNDR3800前面板的灯看起来还是挺上档次的,不过放在客厅一直闪,总觉得晃眼,故而准备使用前面板的WPS按钮来控制LED灯的亮灭。

Shell脚本

创建/root/led.sh脚本,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
# const
ENABLE="enable"
DISABLE="disable"
TOGGLE="toggle"
# read parameter
ope=
while getopts "edt" arg
do
case $arg in
e)
ope=$ENABLE
;;
d)
ope=$DISABLE
;;
t)
ope=$TOGGLE
;;
?)
echo "unknown argument"
exit 1
;;
esac
done
# check operator
if [[ -z $ope ]]; then
echo "Miss operator!"
exit 1
fi
if [ "$ope" == "$TOGGLE" ]; then
# read current led status
cur_state=`swconfig dev rtl8366s port 1 get led`
if [ "$cur_state" == "0" ]; then
ope=$ENABLE
else
ope=$DISABLE
fi
fi
# check command
if [ "$ope" == "$DISABLE" ]; then
# turn on power green led
echo 0 > /sys/class/leds/netgear\:green\:power/brightness
echo 0 > /sys/class/leds/netgear\:orange\:power/brightness
# turn off all group 1 (i.e., green) and group 2 (i.e., orange) leds
swconfig dev rtl8366s port 1 set led 0
swconfig dev rtl8366s port 2 set led 0
# USB
echo 0 > /sys/class/leds/netgear\:green\:usb/brightness
# 2.4GHz
echo 0 > /sys/class/leds/ath9k-phy0/brightness
# 5GHz
echo 0 > /sys/class/leds/ath9k-phy1/brightness
fi
if [ "$ope" == "$ENABLE" ]; then
# turn on power green led
echo 128 > /sys/class/leds/netgear\:green\:power/brightness
echo 0 > /sys/class/leds/netgear\:orange\:power/brightness
# turn off all group 1 (i.e., green) and group 2 (i.e., orange) leds
# turn on all group 1 (i.e., green) and group 2 (i.e., orange) leds
swconfig dev rtl8366s port 1 set led 6
swconfig dev rtl8366s port 2 set led 9
# USB
echo 128 > /sys/class/leds/netgear\:green\:usb/brightness
# 2.4GHz
echo 128 > /sys/class/leds/ath9k-phy0/brightness
# 5GHz
echo 128 > /sys/class/leds/ath9k-phy1/brightness
fi

目前这一脚本中控制全部LED灯:电源、2.4GHz、5GHz、USB、WAN、LAN

测试脚本是否正常工作

  • 点亮LED灯 /root/led.sh -e
  • 熄灭LED灯 /root/led.sh -d
  • 切换LED灯 /root/led.sh -t

接入按钮事件

在/etc/hotplug.d位置创建一个目录,名为button,然后在/etc/hotplug.d/button下创建名为01-radio-toggle的文件

1
2
3
4
#!/bin/sh
if [ "$BUTTON" = "wps" ] && [ "$ACTION" = "pressed" ]; then
( sleep 1; /root/led.sh -t ) &
fi

测试:按下WPS按钮就可以切换前面板中的部分LED灯了

开机设置默认值

如果开机就希望LED灯熄灭,可以使用crontab:#crontab -e

添加如下命令

1
2
# turn off led
@reboot /root/led.sh -d

参考