Merge pull request #6 from senaduka/controller_id_on_sensor_data
Controller id on sensor data
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
Template.log.helpers({
|
Template.log.helpers({
|
||||||
sensorDataCollection: function() {
|
sensorDataCollection: function() {
|
||||||
return SensorData.find({}, {
|
var controllerId = Session.get('controller_id');
|
||||||
|
return SensorData.find({ controllerId: controllerId }, {
|
||||||
sort: {
|
sort: {
|
||||||
created_at: -1
|
created_at: -1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// Global API configuration
|
// Global API configuration
|
||||||
var Api = new Restivus({
|
var Api = new Restivus({
|
||||||
|
version: 'v1.0',
|
||||||
useDefaultAuth: true,
|
useDefaultAuth: true,
|
||||||
prettyJson: true
|
prettyJson: true
|
||||||
});
|
});
|
||||||
@@ -8,11 +9,13 @@ Api.addRoute('sensorData', {
|
|||||||
authRequired: false
|
authRequired: false
|
||||||
}, {
|
}, {
|
||||||
post: function() {
|
post: function() {
|
||||||
|
console.log("Body params", this.bodyParams);
|
||||||
SensorData.insert({
|
SensorData.insert({
|
||||||
temperatureValue: parseFloat(this.bodyParams.temperatureValue),
|
temperatureValue: parseFloat(this.bodyParams.temperatureValue),
|
||||||
humidityValue: parseFloat(this.bodyParams.humidityValue),
|
humidityValue: parseFloat(this.bodyParams.humidityValue),
|
||||||
tankFull: this.bodyParams.tankFull,
|
tankFull: this.bodyParams.tankFull,
|
||||||
owner: this.bodyParams.owner,
|
owner: this.bodyParams.owner,
|
||||||
|
controllerId: this.bodyParams.controllerId,
|
||||||
created_at: new Date()
|
created_at: new Date()
|
||||||
});
|
});
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
GPIO_PIN_DHT = 4 # BCM
|
GPIO_PIN_DHT = 4 # BCM
|
||||||
SENSORDATA_URL = 'http://tfm.meteor.com/api/sensorData'
|
SENSORDATA_URL = 'http://tfm.meteor.com/api/v1.0/sensorData'
|
||||||
GPIO_PIN_TANKFULL = 20 # BCM
|
GPIO_PIN_TANKFULL = 20 # BCM
|
||||||
GPIO_PIN_VALVE = 21 # BCM
|
GPIO_PIN_VALVE = 21 # BCM
|
||||||
API_BASE_URL = 'http://tfm.meteor.com/api'
|
API_BASE_URL = 'http://tfm.meteor.com/api/v1.0'
|
||||||
CONTROLLER_ID = '120' # every controller must have a different one
|
CONTROLLER_ID = '120' # every controller must have a different one
|
||||||
STATE_FILE = '/var/run/controller_state'
|
STATE_FILE = '/var/run/controller_state'
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import sys
|
|||||||
import requests
|
import requests
|
||||||
import Adafruit_DHT
|
import Adafruit_DHT
|
||||||
import config
|
import config
|
||||||
import config
|
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
|
|
||||||
# Try to read the state of GPIO_PIN_TANKFULL
|
# Try to read the state of GPIO_PIN_TANKFULL
|
||||||
@@ -15,14 +14,8 @@ print 'Bacva puna: {}'.format(tankFull)
|
|||||||
|
|
||||||
# Go on to DHT
|
# Go on to DHT
|
||||||
SENSOR_TYPE = Adafruit_DHT.DHT11
|
SENSOR_TYPE = Adafruit_DHT.DHT11
|
||||||
|
controller_id = config.CONTROLLER_ID
|
||||||
if len(sys.argv) == 3:
|
owner = "Controller: %s" % controller_id
|
||||||
owner = sys.argv[1]
|
|
||||||
controller_id = sys.argv[2]
|
|
||||||
else:
|
|
||||||
print 'usage: sudo ./controller.py [OWNER] [CONTROLLER_ID]#'
|
|
||||||
print 'example: sudo ./controller.py Senad 225 - Send temperature as Senad for controller 225'
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Try to grab a sensor reading. Use the read_retry method which will retry up
|
# Try to grab a sensor reading. Use the read_retry method which will retry up
|
||||||
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
|
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
|
||||||
@@ -36,7 +29,9 @@ humidity, temperature = Adafruit_DHT.read_retry(SENSOR_TYPE, config.GPIO_PIN_DHT
|
|||||||
# guarantee the timing of calls to read the sensor).
|
# guarantee the timing of calls to read the sensor).
|
||||||
# If this happens try again!
|
# If this happens try again!
|
||||||
if temperature is not None and humidity is not None:
|
if temperature is not None and humidity is not None:
|
||||||
response = requests.post(config.SENSORDATA_URL, json={"owner": owner, "temperatureValue": temperature, "humidityValue":humidity, "tankFull":tankFull})
|
response = requests.post(config.SENSORDATA_URL, json={"owner": owner, "temperatureValue": temperature, "humidityValue":humidity, "tankFull":tankFull,
|
||||||
|
"controllerId": controller_id
|
||||||
|
})
|
||||||
print 'Temp={0:0.1f}*C'.format(temperature)
|
print 'Temp={0:0.1f}*C'.format(temperature)
|
||||||
print 'Humidity={0:0.1f}%'.format(humidity)
|
print 'Humidity={0:0.1f}%'.format(humidity)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
|
|||||||
Reference in New Issue
Block a user