-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_dht.py
36 lines (31 loc) · 1.12 KB
/
plugin_dht.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
#!/usr/bin/python
import utils
import logger
import config
log = logger.get_logger(__name__)
conf = config.get_config()
# import the module if running on a supported platform
platform = utils.get_platform()
supported_platform = True if platform != "unknown" else False
if supported_platform: import Adafruit_DHT
# poll the sensor
def poll(sensor):
# set the device type
if sensor["plugin"]["type"] == "dht11":
dht_sensor = Adafruit_DHT.DHT11
elif sensor["plugin"]["type"] == "dht22":
dht_sensor = Adafruit_DHT.DHT22
# read the measures
humidity, temperature = Adafruit_DHT.read_retry(dht_sensor,sensor["plugin"]["pin"])
if humidity is not None and temperature is not None and humidity <= 100:
# if this is a valid measure, return both the measures
return str(temperature)+"|"+str(humidity)
# parse the data
def parse(sensor,data):
if "|" not in data: return
split = data.split("|")
if sensor["plugin"]["measure"] == "temperature": return split[0]
if sensor["plugin"]["measure"] == "humidity": return split[1]
# return the cache schema
def cache_schema(sensor):
return sensor["plugin"]["type"]+"_"+str(sensor["plugin"]["pin"])