【LEDE】树莓派上玩LEDE终极指南-70-自动上报树莓派当前温度到qq邮箱

本文介绍了如何在树莓派上利用msmtp和crontab自动发送当前温度信息到QQ邮箱,包括安装配置过程和QQ邮箱的设置,以便定期接收树莓派的温度报告。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

准备:

opkg install msmtp

安装vchiq模块,详见:https://blog.youkuaiyun.com/wang805447391/article/details/80974500

开始:

编辑/etc/msmtprc如下:

# Example for a system wide configuration file

# A system wide configuration file is optional.
# If it exists, it usually defines a default account.
# This allows msmtp to be used like /usr/sbin/sendmail.
account default

# The SMTP smarthost.
host smtp.qq.com
from 805447391@qq.com #谁发的?
auth login
user 805447391@qq.com #你寄几的qq邮箱
password ehzsapggamejbdbg #去qq邮箱设置界面生成授权码

# Construct envelope-from addresses of the form "user@oursite.example".
#auto_from on
#maildomain oursite.example

# Use TLS.
#tls on
#tls_trust_file /etc/ssl/certs/ca-certificates.crt

# Syslog logging with facility LOG_MAIL instead of the default LOG_USER.
syslog LOG_MAIL

测试:

echo -e "to:805447391@qq.com\r\nsubject:Raspberry Pi temperature report\r\n\r\n`vcgencmd measure_tem
p`" | msmtp -t

正常情况下应该是能收到一封来自自己的qq邮件的,里面包含了当前树莓派的温度信息。

 

最后:添加一个crontab,定期上报即可

0 0 * * * echo -e "to:805447391@qq.com\r\nsubject:Raspberry Pi temperature report\r\n\r\n`vcgencmd measure_tem
p`" | msmtp -t

(每夜发送一封邮件告知温度)

 

QQ邮箱的相应设置:

这个步骤不是必须的,但是建议操作一下,因为老是周期性的接收到上报温度的消息难免会打乱自己的思绪,感觉烦烦的。解决方式要么就是降低上报频率,通过crontab实现,要么就是像我这样使用qq邮箱自带的邮件归档功能实现自动阅读右键并放入相应的文件夹中,具体的配置如下:

 

最终效果:

我所用的脚本(水平很低,勿喷)

#!/bin/sh

temp=`vcgencmd measure_temp | cut -d '=' -f 2 | cut -d "'" -f 1`
count=`echo "(10 * $temp - 400) / 2" | bc`
# echo -e "$count \c"

mark=""
while [ $count -gt 0 ]
do
        mark="$mark|"
        count=`expr $count - 1`
done
content=`echo -e "$temp $mark\c"`

echo -e "to:805447391@qq.com\r\nsubject:Raspberry Pi temperature report\r\n\r\n$content" | msmtp -t

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值