reading onewire sensors
This commit is contained in:
@@ -4,6 +4,7 @@ import requests
|
||||
import Adafruit_DHT
|
||||
import config
|
||||
import RPi.GPIO as GPIO
|
||||
import onewire
|
||||
|
||||
# Try to read the state of GPIO_PIN_TANKLEVELx and GPIO_PIN_TANKFULL
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
@@ -42,6 +43,12 @@ stopPumpingAt = config.STOP_PUMPING_AT
|
||||
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
|
||||
humidity, temperature = Adafruit_DHT.read_retry(SENSOR_TYPE, config.GPIO_PIN_DHT)
|
||||
|
||||
temperatures = []
|
||||
|
||||
try:
|
||||
temperatures = onewire.read_many_thermo(config.ONE_WIRE_TERMO_SENSORS)
|
||||
except:
|
||||
print("onewire thermo error:", sys.exc_info()[0])
|
||||
|
||||
# Un-comment the line below to convert the temperature to Fahrenheit.
|
||||
# temperature = temperature * 9/5.0 + 32
|
||||
@@ -58,7 +65,8 @@ if tankFull is not None:
|
||||
# "tankLevel3": "1" if tankLevel3 else "0",
|
||||
"tankLevel4": "1" if tankLevel4 else "0",
|
||||
"tankFull": "1" if tankFull else "0",
|
||||
"startPumpingAt": startPumpingAt,"stopPumpingAt": stopPumpingAt,"controllerId": controller_id
|
||||
"startPumpingAt": startPumpingAt,"stopPumpingAt": stopPumpingAt,"controllerId": controller_id,
|
||||
"temperatures": temperatures
|
||||
})
|
||||
print 'Temp={0:0.1f}*C'.format(temperature)
|
||||
print 'Humidity={0:0.1f}%'.format(humidity)
|
||||
|
||||
Reference in New Issue
Block a user