Multiple level sensors added

This commit is contained in:
2016-06-02 23:13:42 +02:00
parent db843163f2
commit 1ae13f6fb1
5 changed files with 58 additions and 13 deletions

View File

@@ -13,6 +13,11 @@ Api.addRoute('sensorData', {
SensorData.insert({
temperatureValue: parseFloat(this.bodyParams.temperatureValue),
humidityValue: parseFloat(this.bodyParams.humidityValue),
tankLevel0: this.bodyParams.tankLevel0,
tankLevel1: this.bodyParams.tankLevel1,
tankLevel2: this.bodyParams.tankLevel2,
tankLevel3: this.bodyParams.tankLevel3,
tankLevel4: this.bodyParams.tankLevel4,
tankFull: this.bodyParams.tankFull,
owner: this.bodyParams.owner,
controllerId: this.bodyParams.controllerId,
@@ -24,12 +29,10 @@ Api.addRoute('sensorData', {
function reactToSensorData(nextSensorReading) {
console.log("reacting to sensor");
var controllerId = nextSensorReading.controllerId;
var state = stateOrDefault(controllerId).state;
console.log(nextSensorReading , state);
var shouldStartPumping = (!state.in_valve || state.in_valve === 'closed' || state.in_valve === 'closing') && ((parseInt(nextSensorReading.tankFull) === 0) && (state.out_valve === 'closed' || state.out_valve === 'closing'));
var shouldStopPumping = (state.in_valve === 'open' || state.in_valve === 'opening') && (parseInt(nextSensorReading.tankFull) === 1 || state.out_valve === 'open' || state.out_valve === 'opening');
var shouldStartPumping = (!state.in_valve || state.in_valve === 'closed') && ((parseInt(nextSensorReading.tankFull) === 0) && (state.out_valve === 'closed' || state.out_valve === 'closing'));
if (shouldStartPumping) {
ControllerState.update({
@@ -37,12 +40,14 @@ function reactToSensorData(nextSensorReading) {
}, {
'$set': {
'state.in_valve': 'opening',
'significantEvents.lastInValveOpen': new Date(),
'time': new Date(),
'set_by': 'server'
}
});
} else if (shouldStopPumping) {
}
var shouldStopPumping = (state.in_valve === 'open' || state.in_valve === 'opening') && (parseInt(nextSensorReading.tankFull) === 1 || state.out_valve === 'open' || state.out_valve === 'opening');
if (shouldStopPumping) {
ControllerState.update({
controller_id: controllerId
}, {
@@ -91,7 +96,7 @@ function stateOrDefault(id) {
},
time: new Date(),
config: {
draining_period_amount: 60,
draining_period_amount: 40,
draining_period_unit: 'minutes'
},
set_by: 'server'
@@ -102,6 +107,3 @@ function stateOrDefault(id) {
});
return stateEntry;
}
Meteor.sharedFunctions = Meteor.sharedFunctions || {};
Meteor.sharedFunctions.reactToSensorData = reactToSensorData;