-
Notifications
You must be signed in to change notification settings - Fork 2
/
grovepi-zero-air-initialstate.py
47 lines (39 loc) · 1.38 KB
/
grovepi-zero-air-initialstate.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
from grovepi import grovepi
import time
from ISStreamer.Streamer import Streamer
# --------- User Settings ---------
# Connect the Grove Air Quality Sensor to one of the analog pins (i.e. 0, 1, 2)
AIR_SENSOR_PIN = 0
# Initial State settings
BUCKET_NAME = ":partly_sunny: Indoor Environment"
BUCKET_KEY = "GPZa"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
# Set the time between sensor reads
MINUTES_BETWEEN_READS = 1
# ---------------------------------
def isFloat(string):
try:
float(string)
return True
except ValueError:
return False
streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
while True:
try:
airSensorVal = grovepi.analogRead(AIR_SENSOR_PIN)
if isFloat(airSensorVal):
if airSensorVal > 700:
# print "High pollution"
streamer.log("Air Quality", ":fog: :bangbang:")
elif airSensorVal > 300:
# print "Low pollution"
streamer.log("Air Quality", ":foggy: :exclamation:")
else:
# print "Air fresh"
streamer.log("Air Quality", ":rainbow:")
# print "Air Quality =", airSensorVal
streamer.log("Air Quality Sensor", airSensorVal)
streamer.flush()
except IOError:
print "Error"
time.sleep(60*MINUTES_BETWEEN_READS)