-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeleHealth-RemoteSend.py
59 lines (44 loc) · 1.48 KB
/
TeleHealth-RemoteSend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import RPi.GPIO as GPIO
import RPi.GPIO as GPIO
import datetime as dt
import picamera
import time
import tty, sys
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from email import encoders
fromaddr = "FROM EMAIL ADDRESS"
toaddr = "TO EMAIL ADDRESS"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "SUBJECT OF THE EMAIL"
body = "TEXT YOU WANT TO SEND"
msg.attach(MIMEText(body, 'plain'))
camera = picamera.PiCamera()
timestring=dt.datetime.now().strftime('%H:%M:%S:%d:%m:%Y')
ImageName = timestring + '.jpg'
camera.start_preview()
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
input_state = GPIO.input(18)
if input_state==False:
camera.capture(ImageName)
filename = timestring
attachment = open("/home/pi/" + ImageName, "rb")
part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(part)
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "PASSWORD")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
print('pressed')
time.sleep(1)