Merge pull request #4 from senaduka/tankFull

Version to support the reading if the tank is full (BCM GPIO 20 used)
This commit is contained in:
Senad Uka
2016-01-26 16:29:19 +01:00
5 changed files with 14 additions and 2 deletions

View File

@@ -1,3 +1,3 @@
<template name="sensorData">
<li>{{owner}} / <strong>{{temperatureValue}}°C</strong> / <strong>{{humidityValue}}%</strong> / {{created_at_formatted}}</li>
<li>{{owner}} / <strong>{{temperatureValue}}°C</strong> / <strong>{{humidityValue}}%</strong> / Bačva puna: <strong>{{tankFull}}</strong> / {{created_at_formatted}}</li>
</template>

View File

@@ -11,6 +11,7 @@ Api.addRoute('sensorData', {
SensorData.insert({
temperatureValue: parseFloat(this.bodyParams.temperatureValue),
humidityValue: parseFloat(this.bodyParams.humidityValue),
tankFull: this.bodyParams.tankFull,
owner: this.bodyParams.owner,
created_at: new Date()
});

View File

@@ -22,6 +22,7 @@ if (Meteor.isServer) {
SensorData.insert({
temperatureValue: parseFloat(this.bodyParams.temperatureValue),
humidityValue: parseFloat(this.bodyParams.humidityValue),
tankFull: this.bodyParams.tankFull,
owner: this.bodyParams.owner,
created_at: new Date()
});

View File

@@ -2,6 +2,7 @@
GPIO_PIN_DHT = 4 # BCM
SENSORDATA_URL = 'http://tfm.meteor.com/api/sensorData'
GPIO_PIN_TANKFULL = 20 # BCM
GPIO_PIN_VALVE = 21 # BCM
API_BASE_URL = 'http://tfm.meteor.com/api'
CONTROLLER_ID = '120' # every controller must have a different one

View File

@@ -3,8 +3,17 @@ import sys
import requests
import Adafruit_DHT
import config
import config
import RPi.GPIO as GPIO
# Try to read the state of GPIO_PIN_TANKFULL
GPIO.setmode(GPIO.BCM)
GPIO.setup(config.GPIO_PIN_TANKFULL, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
tankFull = GPIO.input(config.GPIO_PIN_TANKFULL)
GPIO.cleanup()
print 'Bacva puna: {}'.format(tankFull)
# Go on to DHT
SENSOR_TYPE = Adafruit_DHT.DHT11
if len(sys.argv) == 3:
@@ -27,7 +36,7 @@ humidity, temperature = Adafruit_DHT.read_retry(SENSOR_TYPE, config.GPIO_PIN_DHT
# guarantee the timing of calls to read the sensor).
# If this happens try again!
if temperature is not None and humidity is not None:
response = requests.post(config.SENSORDATA_URL, json={"owner": owner, "temperatureValue": temperature, "humidityValue":humidity})
response = requests.post(config.SENSORDATA_URL, json={"owner": owner, "temperatureValue": temperature, "humidityValue":humidity, "tankFull":tankFull})
print 'Temp={0:0.1f}*C'.format(temperature)
print 'Humidity={0:0.1f}%'.format(humidity)
if response.status_code != 200: