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

准备:

opkg install msmtp

安装vchiq模块,详见:https://blog.csdn.net/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 [email protected] #谁发的?
auth login
user [email protected] #你寄几的qq邮箱
password ehzsapggamejbdbg #去qq邮箱设置界面生成授权码

# Construct envelope-from addresses of the form "[email protected]".
#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:[email protected]\r\nsubject:Raspberry Pi temperature report\r\n\r\n`vcgencmd measure_tem
p`" | msmtp -t

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

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

0 0 * * * echo -e "to:[email protected]\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:[email protected]\r\nsubject:Raspberry Pi temperature report\r\n\r\n$content" | msmtp -t

猜你喜欢

转载自blog.csdn.net/wang805447391/article/details/81180396