当前位置:网站首页>Raspberry pie get temperature and send pictures to email
Raspberry pie get temperature and send pictures to email
2022-06-12 14:30:00 【zz891422822】
Raspberry pie successfully debugged the camera 、 Temperature sensor rear
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import re
import smtplib
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
import subprocess
msg_from = ['[email protected]', '[email protected]', '[email protected]', '[email protected]']
def mail(to):
print(" Send to "+to)
print("start")
# Get sensor information
p = subprocess.Popen('cat /sys/bus/w1/devices/28-3c01a8167760/w1_slave',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True
)
p.wait()
out = p.stdout.read()
out = str(out)
out1 = " The value obtained :"+ out + " Why print failed "
print(out1)
# Get the temperature
out_b = re.findall("\d\d\d\d\d", out1)
out_c = float(out_b[0])
out_c = out_c/1000
out_c = str(out_c)
print(" Current temperature :"+out_c)
#b = float(a[0])
#print(" The temperature is :"+str(b))
# print(out.decode(encoding='UTF-8',errors='strict'))
subprocess.run(["raspistill", "-o", "new.jpg", "-t", "200"])
msg_from = "[email protected]" # The sender
pwd = "oxopodyppnrabebd" # Authorization code
# to = "[email protected]" # Email address of the other party
msgRoot = MIMEMultipart('related')
msgRoot['From'] = Header(msg_from, 'utf-8')
msgRoot['To'] = Header(to, 'utf-8')
subject = ' Current ambient temperature ' + out_c
msgRoot['Subject'] = Header(subject, 'utf-8')
msgAlternative = MIMEMultipart('alternative')
msgRoot.attach(msgAlternative)
mail_msg = """ <p> condition </p> <p> picture :</p> <p><img src="cid:image1" width="800" height="600"></p> """
msgAlternative.attach(MIMEText(mail_msg, 'html', 'utf-8'))
# Specify the picture as the current directory
fp = open('new.jpg', 'rb')
msgImage = MIMEImage(fp.read())
fp.close()
# Define pictures ID, stay HTML References in text
msgImage.add_header('Content-ID', '<image1>')
msgRoot.attach(msgImage)
try:
ss = smtplib.SMTP_SSL("smtp.qq.com", 465)
ss.login(msg_from, pwd)
ss.sendmail(msg_from, to, msgRoot.as_string())
print(" Mail sent successfully ")
except smtplib.SMTPException:
print( "Error: Unable to send mail ")
for i in msg_from:
mail(i)
边栏推荐
- Design of PLC intelligent slave station based on PROFIBUS DP protocol
- Shell notes
- C magic skill Chapter 4 (detailed explanation of memory function)
- Player practice 19 xaudio turn on audio
- Getting started alicloud haas510 open board DTU (version 2.0) --510-as
- How to package QT program learning records with inno setup
- Player practice 18 xresample
- Huawei equipment is configured with H virtual private network
- Player actual combat 25 unpacking module add close
- 【OCR】AspriseOCR C# 英文、數字識別(中文不行)
猜你喜欢

En langage C, la fonction principale appelle une autre fonction et assemble le Code pour comprendre

C語言中主函數調用另外一個函數,匯編代碼理解

Analysis of two-dimensional array passing as function parameter (C language)

QT multi thread drawing and real-time refreshing method

WinDbg preview debug analysis createtoolhelp32snapshot
![JS (I) error [err\u module\u not\u found]: cannot find package 'UUID' imported](/img/a4/ef2d73576e027a2179ec9251167fa4.jpg)
JS (I) error [err\u module\u not\u found]: cannot find package 'UUID' imported

QT realize picture dragging
![[ROC] aspriseocr C # English, Digital identification (not Chinese)](/img/80/198145df663d2eeec6b8b1d7bc47b6.png)
[ROC] aspriseocr C # English, Digital identification (not Chinese)

Player practice 11 audio resampling

What is automatic bidding? What are its advantages?
随机推荐
To SystemC Beginners: the first program
Player actual combat 25 unpacking module add close
PostgreSQL14安装使用教程
Sizeof calculation space size summary
Axi4 increase burst / wrap burst/ fix burst and narrow transfer
使用make方法创建slice切片的坑
对某热水软件的加密参数逆向
Player actual combat 14 display YUV
Unit test (I) unit test with JUnit
Array one
Visual studio common shortcuts
Is Shell Scripting really a big technology?
Software package for optimization scientific research field
Player practice 15 xdemux and avcodecparameters
Crack WinRAR to ad pop-up window
完美收官|详解 Go 分布式链路追踪实现原理
C secret arts script Chapter 2 (detailed explanation of pointers) (Section 3)
chrome://tracing Performance analysis artifact
Design of PLC intelligent slave station based on PROFIBUS DP protocol
If you want to build brand awareness, what bidding strategy can you choose?