Pre production fixes #14
@@ -26,3 +26,4 @@ percolate:synced-cron
|
|||||||
rzymek:moment-locale-bs
|
rzymek:moment-locale-bs
|
||||||
peppelg:bootstrap-3-modal
|
peppelg:bootstrap-3-modal
|
||||||
fortawesome:fontawesome
|
fortawesome:fontawesome
|
||||||
|
mfpierre:chartist-js
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ email@1.0.8
|
|||||||
es5-shim@4.1.14
|
es5-shim@4.1.14
|
||||||
fastclick@1.0.7
|
fastclick@1.0.7
|
||||||
fortawesome:fontawesome@4.5.0
|
fortawesome:fontawesome@4.5.0
|
||||||
|
fourseven:scss@3.4.1
|
||||||
geojson-utils@1.0.4
|
geojson-utils@1.0.4
|
||||||
handlebars@1.0.4
|
handlebars@1.0.4
|
||||||
hot-code-push@1.0.0
|
hot-code-push@1.0.0
|
||||||
@@ -47,6 +48,7 @@ localstorage@1.0.5
|
|||||||
logging@1.0.8
|
logging@1.0.8
|
||||||
meteor@1.1.10
|
meteor@1.1.10
|
||||||
meteor-base@1.0.1
|
meteor-base@1.0.1
|
||||||
|
mfpierre:chartist-js@1.6.1
|
||||||
minifiers@1.1.7
|
minifiers@1.1.7
|
||||||
minimongo@1.0.10
|
minimongo@1.0.10
|
||||||
mobile-experience@1.0.1
|
mobile-experience@1.0.1
|
||||||
|
|||||||
@@ -46,15 +46,15 @@ Template.state.helpers({
|
|||||||
var sensor = last_sensor_reading();
|
var sensor = last_sensor_reading();
|
||||||
var stateObject = controller_state();
|
var stateObject = controller_state();
|
||||||
if (sensor) {
|
if (sensor) {
|
||||||
if (sensor.tankFull === 0 && stateObject.state.in_valve === 'open' && stateObject.state.out_valve === 'closed') return "/images/barrellFillingUp.png";
|
if (parseInt(sensor.tankFull) === 0 && stateObject.state.in_valve === 'open' && stateObject.state.out_valve === 'closed') return "/images/barrellFillingUp.png";
|
||||||
else if (sensor.tankFull === 1 && (stateObject.state.out_valve === 'closed')) return "/images/barrellFull.png";
|
else if (parseInt(sensor.tankFull) === 1 && (stateObject.state.out_valve === 'closed')) return "/images/barrellFull.png";
|
||||||
else if (sensor.tankFull === 1 && (stateObject.state.out_valve === 'opening')) return "/images/barrellStartWateringFull.png";
|
else if (parseInt(sensor.tankFull) === 1 && (stateObject.state.out_valve === 'opening')) return "/images/barrellStartWateringFull.png";
|
||||||
else if (sensor.tankFull === 1 && (stateObject.state.out_valve === 'open')) return "/images/barrellWateringFull.png";
|
else if (parseInt(sensor.tankFull) === 1 && (stateObject.state.out_valve === 'open')) return "/images/barrellWateringFull.png";
|
||||||
else if (sensor.tankFull === 1 && (stateObject.state.out_valve === 'closing')) return "/images/barrellStopWateringFull.png";
|
else if (parseInt(sensor.tankFull) === 1 && (stateObject.state.out_valve === 'closing')) return "/images/barrellStopWateringFull.png";
|
||||||
else if (sensor.tankFull === 0 && (stateObject.state.out_valve === 'closed')) return "/images/barrellNotFull.png";
|
else if (parseInt(sensor.tankFull) === 0 && (stateObject.state.out_valve === 'closed')) return "/images/barrellNotFull.png";
|
||||||
else if (sensor.tankFull === 0 && (stateObject.state.out_valve === 'opening')) return "/images/barrellStartWateringNotFull.png";
|
else if (parseInt(sensor.tankFull) === 0 && (stateObject.state.out_valve === 'opening')) return "/images/barrellStartWateringNotFull.png";
|
||||||
else if (sensor.tankFull === 0 && (stateObject.state.out_valve === 'open')) return "/images/barrellWateringNotFull.png"
|
else if (parseInt(sensor.tankFull) === 0 && (stateObject.state.out_valve === 'open')) return "/images/barrellWateringNotFull.png"
|
||||||
else if (sensor.tankFull === 0 && (stateObject.state.out_valve === 'closing')) return "/images/barrellStopWateringNotFull.png"
|
else if (parseInt(sensor.tankFull) === 0 && (stateObject.state.out_valve === 'closing')) return "/images/barrellStopWateringNotFull.png"
|
||||||
else return "/images/statusAmber.png";
|
else return "/images/statusAmber.png";
|
||||||
} else return "/images/statusRed.png";
|
} else return "/images/statusRed.png";
|
||||||
},
|
},
|
||||||
@@ -80,10 +80,11 @@ Template.state.helpers({
|
|||||||
|
|
||||||
pretty_days: function(daysInNumbers) {
|
pretty_days: function(daysInNumbers) {
|
||||||
var days = ["Nedjelja", "Ponedjeljak", "Utorak", "Srijeda", "Četvrtak", "Petak", "Subota"];
|
var days = ["Nedjelja", "Ponedjeljak", "Utorak", "Srijeda", "Četvrtak", "Petak", "Subota"];
|
||||||
if (daysInNumbers.length == 7) {
|
if (!daysInNumbers || daysInNumbers.length == 0) {
|
||||||
return "Svaki dan"
|
|
||||||
} else if (!daysInNumbers || daysInNumbers.length == 0) {
|
|
||||||
return "Nikad"
|
return "Nikad"
|
||||||
|
}
|
||||||
|
else if (daysInNumbers.length == 7) {
|
||||||
|
return "Svaki dan"
|
||||||
} else {
|
} else {
|
||||||
return daysInNumbers.map(function(number) {
|
return daysInNumbers.map(function(number) {
|
||||||
return days[number -1 ];
|
return days[number -1 ];
|
||||||
|
|||||||
@@ -8,9 +8,29 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 chart">
|
||||||
<div><strong>Otpusni ventil:</strong> {{pretty_valve state.out_valve }}</div>
|
<div><strong>Otpusni ventil:</strong> {{pretty_valve state.out_valve }}</div>
|
||||||
<div><strong>Ulazni ventil/pumpa:</strong> {{pretty_valve state.in_valve }}</div>
|
<div><strong>Ulazni ventil/pumpa:</strong> {{pretty_valve state.in_valve }}</div>
|
||||||
<div><strong>Zadnja komunikacija: {{ last_communication_time }}</strong></div>
|
<div><strong>Zadnja komunikacija: {{ last_communication_time }}</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 chart">
|
||||||
|
<h3>Temperatura:</h3>
|
||||||
|
<div id="temperature_graph">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 chart">
|
||||||
|
<h3>Vlažnost:</h3>
|
||||||
|
<div id="humidity_graph">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|||||||
@@ -10,5 +10,99 @@ Template.state_details.helpers({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Template.state_details.events({
|
Template.state_details.events({});
|
||||||
|
|
||||||
|
Template.state_details.rendered = function() {
|
||||||
|
this.node = this.find('#temperature_graph'); // our d3 code goes here
|
||||||
|
var yScale = d3.scale.linear()
|
||||||
|
.domain([0, 4])
|
||||||
|
.range([10, 60]);
|
||||||
|
var xScale = d3.scale.linear()
|
||||||
|
.domain([0, self.duration])
|
||||||
|
.range([0, $(self.timelineWrapper).width()])
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function sensor_data_collection() {
|
||||||
|
var controllerId = Session.get('controller_id');
|
||||||
|
return SensorData.find({
|
||||||
|
controllerId: controllerId
|
||||||
|
}, {
|
||||||
|
sort: {
|
||||||
|
created_at: -1
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Template.state_details.rendered = function() {
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
/*
|
||||||
|
* add point when new temperature is added
|
||||||
|
*/
|
||||||
|
setTimeout(function() {
|
||||||
|
self.autorun(function() {
|
||||||
|
sensor_data_collection().observe({
|
||||||
|
added: function(reading) {
|
||||||
|
buildTemperatureGraph();
|
||||||
|
buildHumidityGraph()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function to draw the graph
|
||||||
|
*/
|
||||||
|
function buildTemperatureGraph() {
|
||||||
|
|
||||||
|
var sensorReadings = sensor_data_collection();
|
||||||
|
|
||||||
|
console.log("Added: ", sensorReadings.count());
|
||||||
|
var times = sensorReadings.map(function(reading) {
|
||||||
|
return moment(reading.created_at).format("HH:mm:ss");
|
||||||
|
});
|
||||||
|
var values = sensorReadings.map(function(reading) {
|
||||||
|
return reading.temperatureValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
return new Chartist.Line('#temperature_graph', {
|
||||||
|
labels: times,
|
||||||
|
series: [values]
|
||||||
|
}, {
|
||||||
|
fullWidth: true,
|
||||||
|
chartPadding: {
|
||||||
|
right: 40
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function to draw the graph
|
||||||
|
*/
|
||||||
|
function buildHumidityGraph() {
|
||||||
|
|
||||||
|
var sensorReadings = sensor_data_collection();
|
||||||
|
|
||||||
|
console.log("Added: ", sensorReadings.count());
|
||||||
|
var times = sensorReadings.map(function(reading) {
|
||||||
|
return moment(reading.created_at).format("HH:mm:ss");
|
||||||
|
});
|
||||||
|
var values = sensorReadings.map(function(reading) {
|
||||||
|
return reading.humidityValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
return new Chartist.Line('#humidity_graph', {
|
||||||
|
labels: times,
|
||||||
|
series: [values]
|
||||||
|
}, {
|
||||||
|
fullWidth: true,
|
||||||
|
chartPadding: {
|
||||||
|
right: 40
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,10 +24,12 @@ Api.addRoute('sensorData', {
|
|||||||
|
|
||||||
|
|
||||||
function reactToSensorData(nextSensorReading) {
|
function reactToSensorData(nextSensorReading) {
|
||||||
console.log("reacting to sensor");
|
|
||||||
var controllerId = nextSensorReading.controllerId;
|
var controllerId = nextSensorReading.controllerId;
|
||||||
var state = stateOrDefault(controllerId).state;
|
var state = stateOrDefault(controllerId).state;
|
||||||
var shouldStartPumping = (!state.in_valve || state.in_valve === 'closed') && ((parseInt(nextSensorReading.tankFull) === 0) && (state.out_valve === 'closed' || state.out_valve === 'closing'));
|
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');
|
||||||
|
|
||||||
if (shouldStartPumping) {
|
if (shouldStartPumping) {
|
||||||
ControllerState.update({
|
ControllerState.update({
|
||||||
@@ -39,10 +41,7 @@ function reactToSensorData(nextSensorReading) {
|
|||||||
'set_by': 'server'
|
'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({
|
ControllerState.update({
|
||||||
controller_id: controllerId
|
controller_id: controllerId
|
||||||
}, {
|
}, {
|
||||||
@@ -102,3 +101,6 @@ function stateOrDefault(id) {
|
|||||||
});
|
});
|
||||||
return stateEntry;
|
return stateEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Meteor.sharedFunctions = Meteor.sharedFunctions || {};
|
||||||
|
Meteor.sharedFunctions.reactToSensorData = reactToSensorData;
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ function openOutValve(controller_id) {
|
|||||||
closeOutValve(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) {
|
function closeOutValve(controller_id) {
|
||||||
@@ -51,6 +53,10 @@ function closeOutValve(controller_id) {
|
|||||||
SyncedCron.remove(jobName);
|
SyncedCron.remove(jobName);
|
||||||
setOutValveTo(controller_id, 'closing');
|
setOutValveTo(controller_id, 'closing');
|
||||||
console.log("Finished clearing cron ", controller_id);
|
console.log("Finished clearing cron ", controller_id);
|
||||||
|
|
||||||
|
console.log(Meteor.sharedFunctions);
|
||||||
|
|
||||||
|
Meteor.sharedFunctions.reactToSensorData(last_sensor_reading(controller_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearLog() {
|
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({
|
Meteor.methods({
|
||||||
openOutValve: openOutValve,
|
openOutValve: openOutValve,
|
||||||
closeOutValve: closeOutValve,
|
closeOutValve: closeOutValve,
|
||||||
|
|||||||
@@ -5,26 +5,28 @@ if (Meteor.isServer) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Global API configuration
|
// Global API configuration
|
||||||
var Api = new Restivus({
|
var Api = new Restivus({
|
||||||
useDefaultAuth: true,
|
useDefaultAuth: true,
|
||||||
prettyJson: true
|
prettyJson: true
|
||||||
});
|
});
|
||||||
|
|
||||||
Api.addRoute('sensorData', {
|
// Api.addRoute('sensorData', {
|
||||||
authRequired: false
|
// authRequired: false
|
||||||
}, {
|
// }, {
|
||||||
post: function() {
|
// post: function() {
|
||||||
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,
|
||||||
created_at: new Date()
|
// created_at: new Date()
|
||||||
});
|
// });
|
||||||
return [];
|
// return [];
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user