Fixed filling logic
This commit is contained in:
@@ -40,7 +40,9 @@ function openOutValve(controller_id) {
|
||||
closeOutValve(controller_id);
|
||||
}
|
||||
});
|
||||
console.log("Finished adding cron ", controller_id);
|
||||
console.log(Meteor.sharedFunctions);
|
||||
|
||||
Meteor.sharedFunctions.reactToSensorData(last_sensor_reading(controller_id));
|
||||
}
|
||||
|
||||
function closeOutValve(controller_id) {
|
||||
@@ -51,6 +53,10 @@ function closeOutValve(controller_id) {
|
||||
SyncedCron.remove(jobName);
|
||||
setOutValveTo(controller_id, 'closing');
|
||||
console.log("Finished clearing cron ", controller_id);
|
||||
|
||||
console.log(Meteor.sharedFunctions);
|
||||
|
||||
Meteor.sharedFunctions.reactToSensorData(last_sensor_reading(controller_id));
|
||||
}
|
||||
|
||||
function clearLog() {
|
||||
@@ -88,6 +94,28 @@ function saveControllerConfig(controller_id, time, days) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function last_sensor_reading(controller_id) {
|
||||
var result = null;
|
||||
|
||||
if (controller_id) {
|
||||
result = SensorData.find({
|
||||
controllerId: controller_id
|
||||
}, {
|
||||
sort: {
|
||||
created_at: -1
|
||||
},
|
||||
limit: 1
|
||||
});
|
||||
}
|
||||
if (result && result.count() > 0) {
|
||||
return result.fetch()[0];
|
||||
} else {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Meteor.methods({
|
||||
openOutValve: openOutValve,
|
||||
closeOutValve: closeOutValve,
|
||||
|
||||
Reference in New Issue
Block a user