-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataRetriever.py
51 lines (45 loc) · 1.2 KB
/
dataRetriever.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
import time
import grovepi
from influxdb import InfluxDBClient
#from numbers import Number
temp_humidity=3
gas_sensor = 0
relay=4
grovepi.pinMode(temp_humidity,"INPUT")
grovepi.pinMode(gas_sensor,"INPUT")
grovepi.pinMode(relay,"OUTPUT")
# Generates the necessary payload to post
# temperature data into the InfluxDB
capture_interval = 5.0 # Every 5 seconds
client = InfluxDBClient('localhost','8086','root','root','testdb')
while True:
try:
# Get temperature and humidity sensor value
[temp,humidity] = grovepi.dht(temp_humidity,1)
print("Temp.: {0}".format(temp))
print("Humidity: {0}".format(humidity))
json_body = [
{
"measurement": "WeatherData",
"tags": {
"Project": "Green-house"
},
"fields": {
"Temperature": temp,
"Humidity": humidity,
}
}
]
if (temp>0 and temp<100) and (humidity>0 and humidity<100):
print("Temp.: {0}".format(temp))
client.write_points(json_body)
if humidity > 65 or temp > 14:
grovepi.digitalWrite(relay,0)
else:
grovepi.digitalWrite(relay,1)
time.sleep(capture_interval)
except KeyboardInterrupt:
grovepi.digitalWrite(relay,1)
break
except IOError:
print ("Error")