斐讯k2 openwrt LED颜色

2020年09月28日 108点热度 0人点赞 0条评论

简介

使用命令行控制斐讯 k2(PSG1218A) 的 LED 颜色,这里使用的是 openwrt 19 固件。

使用方法

新建 /usr/bin/led

#!/bin/sh

RED=/sys/class/leds/psg1218a:red:status/brightness
BLUE=/sys/class/leds/psg1218a:blue:status/brightness
YELLOW=/sys/class/leds/psg1218a:yellow:status/brightness

if [ "$1" = "blue" ];then
    echo 0 > $RED
    echo 1 > $BLUE
    echo 0 > $YELLOW
    exit 1
fi

if [ "$1" = "dark" ];then
    echo 0 > $RED
    echo 0 > $BLUE
    echo 0 > $YELLOW
    exit 1
fi

if [ "$1" = "lightblue" ];then
    echo 0 > $RED
    echo 1 > $BLUE
    echo 1 > $YELLOW
    exit 1
fi

if [ "$1" = "orange" ];then
    echo 1 > $RED
    echo 0 > $BLUE
    echo 1 > $YELLOW
    exit 1
fi

if [ "$1" = "pink" ];then
    echo 1 > $RED
    echo 1 > $BLUE
    echo 1 > $YELLOW
    exit 1
fi

if [ "$1" = "purple" ];then
    echo 1 > $RED
    echo 1 > $BLUE
    echo 0 > $YELLOW
    exit 1
fi

if [ "$1" = "red" ];then
    echo 1 > $RED
    echo 0 > $BLUE
    echo 0 > $YELLOW
    exit 1
fi

if [ "$1" = "yellow" ];then
    echo 0 > $RED
    echo 0 > $BLUE
    echo 1 > $YELLOW
    exit 1
fi

echo "usage: led [blue|dark|lightblue|orange|pink|purple|red|yellow]"

添加执行权限

chmod +x /usr/bin/led

切换颜色

led [blue|dark|lightblue|orange|pink|purple|red|yellow]

监控网络连接

原版 openwrt 貌似灯一直都是蓝色,不能随网络状态变化。后台的 LED 设置完全看不明白,这里就用个笨方法监控网络状态修改 LED 颜色。

创建 /usr/bin/netcheck

#!/bin/sh

while true
do
    if ping -I eth0.2 -c 1 -W 5 114.114.114.114 1>/dev/null 2>&1 
    then
        echo "connected wan"
        /usr/bin/led blue
    else
        echo "not connected"
        /usr/bin/led yellow
    fi
    sleep 10
done

添加执行权限

chmod +x /usr/bin/netcheck

使用 netcheck 命令测试

然后可以把他加到自启动服务

创建 /etc/init.d/netcheckd

#!/bin/sh /etc/rc.common

START=40
NETCHECK_BIN=/usr/bin/netcheck

start() {
	"$NETCHECK_BIN"
}

stop() {
	killall "$NETCHECK_BIN"
}

KAMINO

暂无