forked from tmalch/GreenTechJam2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
executable file
·47 lines (35 loc) · 1.18 KB
/
controller.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
#!/usr/bin/python
import requests
import json
import time
while True:
r_co2 = requests.get('http://localhost:8000/CO2')
r_hum = requests.get('http://localhost:8000/humidity')
r_tem = requests.get('http://localhost:8000/temperature')
r_window = requests.get('http://localhost:8000/window')
r_heating = requests.get('http://localhost:8000/heating')
dic_co2 = r_co2.json()
time_co2 = dic_co2.get('time')
value_co2 = dic_co2.get('value')
dic_hum = r_hum.json()
time_hum = dic_hum.get('time')
value_hum = dic_hum.get('value')
dic_tem = r_tem.json()
time_tem = dic_tem.get('time')
value_tem = dic_tem.get('value')
window_set = r_window.json().get('open')
heating_set = r_heating.json().get('on')
if (value_co2 > 800 and value_tem > 30 and value_hum > 70):
window_set = True
heating_set = False
print("case 1")
elif (value_co2 < 500 and value_tem < 18 and value_hum < 50):
window_set = False
print("case 2")
elif (value_tem < 10):
window_set = False
heating_set = True
print("case 3")
requests.post('http://localhost:8000/window', data = {'open':window_set})
requests.post('http://localhost:8000/heating', data = {'on':heating_set})
time.sleep(5)