-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver_finally5.py
More file actions
101 lines (81 loc) · 2.35 KB
/
server_finally5.py
File metadata and controls
101 lines (81 loc) · 2.35 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
import RPi.GPIO as GPIO
from subprocess import call
import picamera
import os
import sys
import time
import datetime
def record():
camera = picamera.PiCamera()
camera.resolution = (1280, 720)
camera.framerate = 60
now = datetime.datetime.now()
filename = now.strftime('%Y-%m-%d %H:%M:%S')
camera.start_recording(output = filename + '.h264')
camera.wait_recording(30)
camera.stop_recording()
camera.close()
email_user = 'son33620812@gmail.com'
email_password = 'hlove3308'
email_send = 'son33620812@gmail.com'
subject = 'project finish??'
msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = email_send
msg['Subject'] = subject
body = 'project finish~~'
msg.attach(MIMEText(body,'plain'))
attachment =open(filename+".h264",'rb')
part = MIMEBase('application','octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',"attachment; filename= "+filename)
msg.attach(part)
text = msg.as_string()
server = smtplib.SMTP('smtp.gmail.com',587)
server.starttls()
server.login(email_user,email_password)
server.sendmail(email_user,email_send,text)
server.quit()
GPIOIN = 17
GPIOOUT = 27
GPIO.setmode(GPIO.BCM)
print("HC-SR501 motion detection start")
GPIO.setup(GPIOIN, GPIO.IN)
GPIO.setup(GPIOOUT, GPIO.OUT)
try:
while True:
state = GPIO.input(GPIOIN)
if (state == True):
print("motion detected")
breakAll = 0
while (breakAll == 0):
state = GPIO.input(GPIOIN)
while (state == False):
print("motion not detected")
startTime = time.time()
while (breakAll == 0):
print("motion not detected")
nowTime = time.time()
if (nowTime - startTime >= 108000):
record()
breakAll = 1
time.sleep(0.5)
state = GPIO.input(GPIOIN)
time.sleep(0.5)
if (state == True):
print("motion detected")
time.sleep(0.5)
if (breakAll == 1):
break
else:
print("motion not detected")
GPIO.output(GPIOOUT, state)
time.sleep(0.5)
except KeyboardInterrupt:
GPIO.cleanup()