-
Notifications
You must be signed in to change notification settings - Fork 0
/
filler_test.py
90 lines (69 loc) · 2.34 KB
/
filler_test.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
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
from datetime import datetime
import smtplib
from collections import Counter
def most_common(lst):
data = Counter(lst)
return max(lst, key=data.get)
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def filler():
try:
bucket = []
t = 0
forth = GPIO.input(18)
if forth == False:
bucket.append(0)
if len(bucket) == 9:
del bucket[-1]
elif forth == True:
bucket.append(1)
if len(bucket) == 9:
del bucket[-1]
if most_common(bucket) == 0:
if t == 0:
print ("Pool level A-OK")
time.sleep(5)
elif t == 1:
t = 0
print('Resetting GPIO')
GPIO.cleanup()
time.sleep(2)
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
"""
# Send email
server = smtplib.SMTP('smtp.gmail.com', 587)
email = '[email protected]'
server.starttls()
server.login(email, "Stuff180!")
msg = 'Pool is full'
server.sendmail(email, "[email protected]", msg) # [email protected]
server.quit()
"""
elif most_common(bucket) == 1:
if t == 0:
t = 1
print('Flip\'n relay')
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, 0)
time.sleep(5)
"""
# Send email
server = smtplib.SMTP('smtp.gmail.com', 587)
email = '[email protected]'
server.starttls()
server.login(email, "Stuff180!")
msg = 'Filling pool'
server.sendmail(email, "[email protected]", msg) # [email protected]
server.quit()
"""
elif t == 1:
print('Still fill\'n')
time.sleep(5)
print(bucket)
except KeyboardInterrupt:
GPIO.cleanup()
filler()