Added suport for in valve
This commit is contained in:
@@ -9,7 +9,7 @@ Api.addRoute('sensorData', {
|
||||
authRequired: false
|
||||
}, {
|
||||
post: function() {
|
||||
console.log("Body params", this.bodyParams);
|
||||
reactToSensorData(this.bodyParams);
|
||||
SensorData.insert({
|
||||
temperatureValue: parseFloat(this.bodyParams.temperatureValue),
|
||||
humidityValue: parseFloat(this.bodyParams.humidityValue),
|
||||
@@ -23,16 +23,34 @@ Api.addRoute('sensorData', {
|
||||
});
|
||||
|
||||
|
||||
function reactToSensorData(nextSensorReading) {
|
||||
var controllerId = nextSensorReading.controllerId;
|
||||
var state = stateOrDefault(controllerId).state;
|
||||
var shouldStartPumping = (parseInt(nextSensorReading.tankFull) === 0 && ( !state.in_valve || state.in_valve === 'closed' ) );
|
||||
|
||||
if(shouldStartPumping) {
|
||||
ControllerState.update({
|
||||
controller_id: controllerId
|
||||
}, {
|
||||
'$set': {
|
||||
'state.in_valve': 'opening',
|
||||
'time': new Date(),
|
||||
'set_by': 'server'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Api.addRoute('state/:id', {
|
||||
authRequired: false
|
||||
}, {
|
||||
post: function() {
|
||||
console.log("Body params", this.bodyParams);
|
||||
return ControllerState.update({
|
||||
controller_id: this.urlParams.id
|
||||
}, {
|
||||
'$set': {
|
||||
'state.out_valve': this.bodyParams.out_valve,
|
||||
'state.in_valve': this.bodyParams.in_valve,
|
||||
'time': new Date(),
|
||||
'set_by': 'client'
|
||||
}
|
||||
@@ -43,6 +61,7 @@ Api.addRoute('state/:id', {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function stateOrDefault(id) {
|
||||
var stateEntry = ControllerState.findOne({
|
||||
controller_id: id,
|
||||
@@ -52,13 +71,13 @@ function stateOrDefault(id) {
|
||||
stateEntry = ControllerState.insert({
|
||||
controller_id: id,
|
||||
state: {
|
||||
out_valve: 'closed'
|
||||
out_valve: 'closed',
|
||||
in_valve: 'closed'
|
||||
},
|
||||
time: new Date(),
|
||||
config: {
|
||||
draining_period_amount: 5,
|
||||
draining_period_unit: 'minutes'
|
||||
|
||||
},
|
||||
set_by: 'server'
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user