Added humidity sensor data handling

This commit is contained in:
2015-12-29 23:25:11 +01:00
parent 89877bbe65
commit f30100e795
6 changed files with 15 additions and 16 deletions

View File

@@ -5,13 +5,13 @@ import Adafruit_DHT
GPIO_PIN = 4
TEMPERATURE_URL = 'http://tfm.meteor.com/api/temperatures'
SENSORDATA_URL = 'http://tfm.meteor.com/api/sensorData'
SENSOR_TYPE = Adafruit_DHT.DHT11
if len(sys.argv) == 2:
owner = sys.argv[1]
else:
print 'usage: sudo ./conntroler.py [OWNER]#'
print 'usage: sudo ./controler.py [OWNER]#'
print 'example: sudo ./controller.py Senad - Send temperature as Senad'
sys.exit(1)
@@ -26,9 +26,10 @@ humidity, temperature = Adafruit_DHT.read_retry(SENSOR_TYPE, GPIO_PIN)
# the results will be null (because Linux can't
# guarantee the timing of calls to read the sensor).
# If this happens try again!
if temperature is not None:
response = requests.post(TEMPERATURE_URL, json={"owner": owner, "value": temperature})
if temperature is not None and humidity is not None:
response = requests.post(SENSORDATA_URL, json={"owner": owner, "temperatureValue": temperature, "humidityValue":humidity})
print 'Temp={0:0.1f}*C'.format(temperature)
print 'Humidity={0:0.1f}%'.format(humidity)
if response.status_code != 200:
print 'Failed to send temperature!'
sys.exit(2)