-
Notifications
You must be signed in to change notification settings - Fork 0
/
AM2302Reader.py
36 lines (32 loc) · 1.04 KB
/
AM2302Reader.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
import Adafruit_DHT
import time
import json
pin = 3
def getValue():
""" sensor measurement implementation"""
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302 , pin)
timestamp = int(time.time())
ht = {"humidity": humidity, "temperature":temperature, "timestamp":timestamp}
hts = json.dumps(ht)
print hts
if humidity is not None and temperature is not None:
return ((humidity, "f"), (temperature, "f"), (timestamp, "i"))
else:
raise ValueError
def getSensorMetadata():
""" temporarily hardcode the metadata """
metadata = {
"sensor_name":"AM2302"
}
return metadata
def getValueMap():
""" sensor measurement implementation"""
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302 , pin)
timestamp = int(time.time())
ht = {"humidity": humidity, "temperature":temperature, "timestamp":timestamp}
hts = json.dumps(ht)
print hts
if humidity is not None and temperature is not None:
return ht
else:
raise ValueError