controller id is now sent with sensor data
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
Template.log.helpers({
|
||||
sensorDataCollection: function() {
|
||||
return SensorData.find({}, {
|
||||
var controllerId = Session.get('controller_id');
|
||||
return SensorData.find({ controllerId: controllerId }, {
|
||||
sort: {
|
||||
created_at: -1
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ Api.addRoute('sensorData', {
|
||||
humidityValue: parseFloat(this.bodyParams.humidityValue),
|
||||
tankFull: this.bodyParams.tankFull,
|
||||
owner: this.bodyParams.owner,
|
||||
controllerId: this.bodyParams.controllerId,
|
||||
created_at: new Date()
|
||||
});
|
||||
return [];
|
||||
|
||||
@@ -3,7 +3,6 @@ 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
|
||||
@@ -15,13 +14,11 @@ print 'Bacva puna: {}'.format(tankFull)
|
||||
|
||||
# Go on to DHT
|
||||
SENSOR_TYPE = Adafruit_DHT.DHT11
|
||||
|
||||
if len(sys.argv) == 3:
|
||||
owner = sys.argv[1]
|
||||
controller_id = sys.argv[2]
|
||||
controller_id = config.CONTROLLER_ID
|
||||
owner = "Controller: %s" % controller_id
|
||||
else:
|
||||
print 'usage: sudo ./controller.py [OWNER] [CONTROLLER_ID]#'
|
||||
print 'example: sudo ./controller.py Senad 225 - Send temperature as Senad for controller 225'
|
||||
print 'usage: sudo ./sensors.py '
|
||||
print 'example: sudo ./sensors.py Send temperature for controller in config'
|
||||
sys.exit(1)
|
||||
|
||||
# Try to grab a sensor reading. Use the read_retry method which will retry up
|
||||
@@ -36,7 +33,9 @@ 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, "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 'Humidity={0:0.1f}%'.format(humidity)
|
||||
if response.status_code != 200:
|
||||
|
||||
Reference in New Issue
Block a user