树莓派OpenWrt下的散热风扇控制脚本
OpenWrt下的shell脚本解释器与Raspbian下略有区别,这里分享一下树莓派openwrt下的风扇控制脚本:
#!/bin/bash
echo 14 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio14/direction
echo 1 > /sys/class/gpio/gpio14/value
sleep 2
while true
do
cputemp=`cat /sys/class/thermal/thermal_zone0/temp`
valve=70000
temp=`expr $cputemp`
echo $temp
if (( $temp >= $valve ))
then
echo 1 > /sys/class/gpio/gpio14/value &
else
echo 0 > /sys/class/gpio/gpio14/value &
fi
sleep 60
done
注:
树莓派4官方风扇,通过GPIO14控制通断
valve为阈值,单位为摄氏度的1000倍,valve为70000代表cpu超过70℃时开启风扇