-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccelerometerwithemail.py
114 lines (67 loc) · 2.08 KB
/
accelerometerwithemail.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import smbus
import time
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
TRIG = 18
ECHO = 24
print "Distance measurement in progress"
GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
fromaddr= "golurai15011998@gmail.com"
toaddr= "gauravrai15011998@gmail.com"
msg=MIMEMultipart()
msg['From']=fromaddr
msg['to']=toaddr
msg['subject']='garbage level'
bus = smbus.SMBus(1)
bus.write_byte_data(0x53, 0x2C, 0x0A)
bus.write_byte_data(0x53, 0x2D, 0x08)
bus.write_byte_data(0x53, 0x31, 0x08)
time.sleep(0.5)
data0 = bus.read_byte_data(0x53, 0x32)
data1 = bus.read_byte_data(0x53, 0x33)
xAccl = ((data1 & 0x03) * 256) + data0
if xAccl > 511 :
xAccl -= 1024
data0 = bus.read_byte_data(0x53, 0x34)
data1 = bus.read_byte_data(0x53, 0x35)
yAccl = ((data1 & 0x03) * 256) + data0
if yAccl > 511 :
yAccl -= 1024
data0 = bus.read_byte_data(0x53, 0x36)
data1 = bus.read_byte_data(0x53, 0x37)
zAccl = ((data1 & 0x03) * 256) + data0
if zAccl > 511 :
zAccl -= 1024
while True:
GPIO.output(TRIG, False)
print "Waitng For Sensor To Settle"
time.sleep(2)
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
while GPIO.input(ECHO)==0:
pulse_start = time.time()
while GPIO.input(ECHO)==1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distance = int(pulse_duration * 17150)
message = "l=%d" %(distance)
print distance
msg.attach(MIMEText(message,'plain'))
server=smtplib.SMTP('smtp.gmail.com', 25)
server.starttls()
server.login(fromaddr, 'password123@')
text="garbage level exceed"
text1="bin is not placed properly"
if distance < 200:
server.sendmail(fromaddr,toaddr,text)
if (xAccl<0 and zAccl>0 and yAccl>0):
server.sendmail(fromaddr,toaddr,text1)
if (yAccl<0 and zAccl>0 and xAccl>0):
server.sendmail(fromaddr,toaddr,text1)
server.quit