-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPIRCamera.py
More file actions
64 lines (49 loc) · 1.45 KB
/
PIRCamera.py
File metadata and controls
64 lines (49 loc) · 1.45 KB
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
60
61
62
63
# Author: Matthew Baker
# GitHub: https://github.com/mbaker92
# Libraries
from gpiozero import MotionSensor
from picamera import PiCamera
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
import datetime
import smtplib
import time
# Email Addresses
fromAddr = 'Address Sending Email'
toAddr = 'Address Receiving Email'
#Motion Sensor and Camera Initialized
PIRSensor = MotionSensor(4)
camera = PiCamera()
# Variable to Exit while loop
Tripped = True
#wait five seconds
time.sleep(5)
while Tripped:
if PIRSensor.motion_detected:
print("Motion Detected")
#Sent Tripped to False and capture picture
Tripped = False
timeCaptured = '/home/pi/Desktop' + datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S') + '.png'
camera.rotation = 180
camera.capture(timeCaptured)
print("Image Captured")
#Create the Message
msg = MIMEMultipart()
msg[ 'Subject'] = 'Intruder'
msg['From'] = fromAddr
msg['To'] = toAddr
#Attach the file
File = open(timeCaptured, 'rb')
img = MIMEImage(File.read())
File.close()
msg.attach(img)
# Credentials for fromAddr
username = 'Email Address'
password = 'Password'
# The actual mail send from a microsoft account
server = smtplib.SMTP('smtp-mail.outlook.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromAddr, toAddr, msg.as_string())
server.quit()
print("Email Sent")