Mercurial > code > home > repos > homeauto
changeset 345:d36863e09095
switch to pigpio for reading DHT sensor
Ignore-this: 32b960f125848261c3896802ed7bcfb4
author | drewp@bigasterisk.com |
---|---|
date | Sun, 15 Apr 2018 04:14:33 -0700 |
parents | a143658ebeff |
children | 9636e950373e |
files | service/piNode/devices.py |
diffstat | 1 files changed, 19 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/service/piNode/devices.py Sat Apr 14 23:47:34 2018 -0700 +++ b/service/piNode/devices.py Sun Apr 15 04:14:33 2018 -0700 @@ -267,30 +267,30 @@ def __init__(self, *a, **kw): DeviceType.__init__(self, *a, **kw) - import Adafruit_DHT - self.mod = Adafruit_DHT + import DHT22 + self.sens = DHT22.sensor(self.pi, self.pinNumber) def poll(self): - for tries in range(1): - # fails a lot, but I don't want to add too much delay in - # here- the next poll is coming soon - humid, tempC = self.mod.read(self.mod.DHT22, self.pinNumber) - if humid and tempC: - break + stmts = set() - stmts = set() - if humid is not None: - stmts.add((self.uri, ROOM['humidity'], Literal(round(humid, 2)))) + if self.sens.staleness() < self.pollPeriod * 2: + humid, tempC = self.sens.humidity(), self.sens.temperature() + if humid > -999: + stmts.add((self.uri, ROOM['humidity'], Literal(round(humid, 2)))) + else: + stmts.add((self.uri, RDFS['comment'], Literal('No recent humidity measurement'))) + if tempC > -999: + stmts.add((self.uri, ROOM['temperatureF'], + # see round() note in arduinoNode/devices.py + Literal(round(tempC * 9 / 5 + 32, 2)))) + else: + stmts.add((self.uri, RDFS['comment'], Literal('No recent temperature measurement'))) else: stmts.add((self.uri, RDFS['comment'], - Literal('DHT read returned None'))) - if tempC is not None: - stmts.add((self.uri, ROOM['temperatureF'], - # see round() note in arduinoNode/devices.py - Literal(round(tempC * 9 / 5 + 32, 2)))) - else: - stmts.add((self.uri, RDFS['comment'], - Literal('DHT read returned None'))) + Literal('No recent DHT response (%.02f sec old)' % self.sens.staleness()))) + + self.sens.trigger() + return stmts def watchPrefixes(self):