»
(008) CubeIDE Implementation of USB Peripherals*
(012) Temperature Control of Arm
(018) C99 pointer*
(019) C99 With only value assignment*
(022) POSIX pthread multi-threads mutex*
(023) POSIX pthread multi-threads programming*
(027) C99 time and wait*
(028) High-precision calculation with GMP*
(029) Web Service Lib*
(030) International Components for Unicode (ICU)*
(031) Performance of C is higher than C++, because...*
1. 从网上总结得到的Arm系统温度检测监测程序(linux-temperature.sh):
#!/bin/sh
# 系统最高温度,80.0度
max_temp=80000
# 系统最低温度,-70.0度
min_temp=-70000
# 过热连续出现次数
too_high_count=0
# 过冷连续出现次数
too_low_count=0
while (true) do
# temp=`/opt/vc/bin/vcgencmd measure_temp|awk -F= '{print $2}'|awk -F\' '{print $1}'`
temp=`cat /sys/class/thermal/thermal_zone0/temp`
echo $temp
# 网上有实验表明,树莓派温度达到 -78°C 的低温下会停止工作
# http://shumeipai.nxez.com/2019/04/02/what-is-the-ideal-raspberry-pi-cpu-temperature-range.html
if [ `expr "$temp < $min_temp"` ]; then
if [ $too_low_count > 3 ]; then
echo `date` "系统已过冷" $too_low_count >> ./wait-halt.log
#halt -p
reboot
break
else
let too_low_count+=1
fi
elif [ `expr "$temp > $max_temp"` ]; then
if [ $too_high_count > 3 ]; then
echo `date` "系统已过热" $too_high_count >> ./wait-halt.log
#halt -p
reboot
break
else
let too_high_count+=1
fi
else
# 连续出现过热或过冷次数超过3次才关机,必须是连续出现
too_low_count=0
too_high_count=0
fi
sleep 1
done
2、做成服务(linux-temperature.service)
[Unit]
Description=Temperature Monitor
After=network.target
[Service]
ExecStart=/root/linux-temperature.sh 2>&1 > /dev/null &
Restart=on-abort
[Install]
WantedBy=multi-user.target
3、使能服务
systemctl enable linux-temperature
附上:
Linux环境,转换windows环境的\r\n为\n的最简单方法(也就是Linux环境转换windows换行的最简单方法):
sed -i 's/\r//' linux-temperature.sh
sed -i 's/\r//' linux-temperature.service