準備:
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