当前位置:网站首页>[RPI]树莓派监控温度及报警关机保护「建议收藏」
[RPI]树莓派监控温度及报警关机保护「建议收藏」
2022-07-31 12:49:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
最近把树莓派用作了Aria2下载机+无线路由,24小时不间断工作,生怕机子有时会过热烧坏,所以写了个脚本做温度记录,以及在温度过高时能自动关机保护。下面直接上Shell脚本(/data/temperature.sh):
#!/bin/sh
# 高温阈值
hot_temp=80.0
# 低温阈值
cold_temp=-70.0
# 过热预警连续出现次数
hot_cnt=0
# 过冷预警连续出现次数
cold_cnt=0
while (true) do
temp=`/opt/vc/bin/vcgencmd measure_temp|awk -F= '{print $2}'|awk -F\' '{print $1}'`
echo $temp
# 网上有实验表明,树莓派温度达到 -78°C 的低温下会停止工作
# http://shumeipai.nxez.com/2019/04/02/what-is-the-ideal-raspberry-pi-cpu-temperature-range.html
if [ `expr "$temp < $cold_temp"` ]; then
if [ $cold_cnt > 3 ]; then
echo "太冷了,我不会是在太空中吧!" >&2
halt -p
break
else
let cold_cnt+=1
fi
elif [ `expr "$temp > $hot_temp"` ]; then
if [ $hot_cnt > 3 ]; then
echo "太热了,需要关机休息一下!" >&2
halt -p
break
else
let hot_cnt+=1
fi
else
# 需要连续出现温度预警才会关机
hot_cnt=0
cold_cnt=0
if [ `expr "$temp < 0.0"` ]; then # 有点冷
echo "警告:当前温度有点冷,小心受凉!" >&2
elif [ `expr "$temp < 40.0"` ]; then # 待机温度
sleep 0.1
elif [ `expr "$temp < 70.0"` ]; then # 正常工作温度
sleep 0.1
elif [ `expr "$temp < $hot_temp"` ]; then # 挖矿温度?
echo "警告:我有点热,注意控制温度!" >&2
fi
fi
sleep 10
done另外,还可以写个服务配置文件(/etc/systemd/system/temperature.service):
[Unit]
Description=Temperature Monitor
After=network.target
[Service]
ExecStart=/data/temperature.sh > /data/temperature.log &
Restart=on-abort
[Install]
WantedBy=multi-user.target最后执行一下systemctl enable temperature,这样每次开机时就会自动启动温度监控脚本。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/128631.html原文链接:https://javaforall.cn
边栏推荐
- PyQt5快速开发与实战 10.1 获取城市天气预报
- Adding data nodes and decommissioning data nodes in the cluster
- PyQt5 rapid development and actual combat 10.2 compound interest calculation && 10.3 refresh blog clicks
- 函数的参数
- SAP 电商云 Spartacus UI 和 Accelerator UI 里的 ASM 模块
- 荣耀手机参数写错,客服认为没错
- Chrome开发自定义右键菜单实现快速跳转到指定页面
- 行业案例 | 全面防护 赛宁助力能源工控安全建设
- Comparison of ipv4 and ipv6 (IPV4)
- Ali on three sides: MQ message loss, repetition, backlog problem, how to solve?
猜你喜欢

CWE4.8 -- 2022年危害最大的25种软件安全问题

ECCV2022:在Transformer上进行递归,不增参数,计算量还少!

365-day challenge LeetCode1000 questions - Day 044 Maximum element in the layer and level traversal

AMBA APB学习记录(AMBA 3/4)

TOGAF10标准读书会第2场活动精彩继续,高光时刻回顾!
![LRU缓存[线性表 -> 链表 -> hash定位 -> 双向链表]](/img/ad/dd80541514d6fedde8c730218fdf5a.png)
LRU缓存[线性表 -> 链表 -> hash定位 -> 双向链表]

alert(1) (haozi.me)靶场练习

深圳某游戏研发公司每个工位都装监控,网友:堪比“坐牢”!

Use docker to build mysql master-slave

How does the SAP ABAP OData service support the $filter (filter) operation trial version
随机推荐
ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
Full GC (Ergonomics)排查分析
CentOS7 —— yum安装mysql
alert(1) (haozi.me)靶场练习
Two methods of NameNode failure handling
Wearing detection and action recognition of protective gear based on pose estimation
The function of SQL GROUP BY dependence
行业案例 | 全面防护 赛宁助力能源工控安全建设
三相PWM整流器预测直接功率控制
基本语法(二)
手撕Verilog PWM呼吸灯
jmeter性能测试步骤入门(性能测试工具jmeter)
Qt鼠标穿透
全动力学约束的机器人高效时间最优轨迹规划
NameNode故障处理的两种方法
Double non-one into bytes!!Pure dry goods sharing
分布式监视 Zabbix 和 Prometheus 到底怎么选?千万别用错了!
SAP message TK 248 solved
[core]-ARMV7-A, ARMV8-A, ARMV9-A Architecture Introduction "Recommended Collection"
NPM 使用介绍