picture api ready
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
SensorData = new Mongo.Collection("sensorData");
|
||||
ControllerState = new Mongo.Collection("controller_states");
|
||||
Picture = new Mongo.Collection("pictures");
|
||||
|
||||
BIN
app/public/images/noImage.png
Normal file
BIN
app/public/images/noImage.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
@@ -10,7 +10,7 @@ Api.addRoute('sensorData', {
|
||||
}, {
|
||||
post: function() {
|
||||
reactToSensorData(this.bodyParams);
|
||||
SensorData.insert({
|
||||
var sensorObject = {
|
||||
temperatureValue: parseFloat(this.bodyParams.temperatureValue),
|
||||
humidityValue: parseFloat(this.bodyParams.humidityValue),
|
||||
tankLevel0: this.bodyParams.tankLevel0,
|
||||
@@ -24,7 +24,8 @@ Api.addRoute('sensorData', {
|
||||
owner: this.bodyParams.owner,
|
||||
controllerId: this.bodyParams.controllerId,
|
||||
created_at: new Date()
|
||||
});
|
||||
};
|
||||
SensorData.insert(sensorObject);
|
||||
return [];
|
||||
}
|
||||
});
|
||||
@@ -47,11 +48,11 @@ reactToSensorData = function(nextSensorReading) {
|
||||
|
||||
var shouldStartAutomaticPumping = (!state.in_valve || state.in_valve === 'closed') && ((parseInt(nextSensorReading.tankFull) === 0) && startPumpingLevelReached && (state.out_valve === 'closed' || state.out_valve === 'closing'));
|
||||
|
||||
console.log("State: ", state);
|
||||
console.log("State: ", state);
|
||||
|
||||
var shouldStartPumping = shouldStartAutomaticPumping && config && !config.manualInflow;
|
||||
|
||||
console.log("shouldStartAutomaticPumping: ", shouldStartAutomaticPumping);
|
||||
console.log("shouldStartAutomaticPumping: ", shouldStartAutomaticPumping);
|
||||
|
||||
console.log("shouldStartPumping: ", shouldStartPumping);
|
||||
|
||||
@@ -75,11 +76,11 @@ reactToSensorData = function(nextSensorReading) {
|
||||
else if (nextSensorReading.stopPumpingAt == 'TANKLEVEL4') stopPumpingLevelReached = (parseInt(nextSensorReading.tankLevel4) === 1)
|
||||
else stopPumpingLevelReached = false;
|
||||
|
||||
var shouldStopAutomaticPumping = (state.in_valve === 'open' || state.in_valve === 'opening') && (parseInt(nextSensorReading.tankFull) === 1 || stopPumpingLevelReached || state.out_valve === 'open' || state.out_valve === 'opening');
|
||||
var shouldStopAutomaticPumping = (state.in_valve === 'open' || state.in_valve === 'opening') && (parseInt(nextSensorReading.tankFull) === 1 || stopPumpingLevelReached || state.out_valve === 'open' || state.out_valve === 'opening');
|
||||
|
||||
var shouldStopPumping = shouldStopAutomaticPumping && config && !config.manualInflow;
|
||||
var shouldStopPumping = shouldStopAutomaticPumping && config && !config.manualInflow;
|
||||
|
||||
console.log("shouldStopPumping: ", shouldStopPumping);
|
||||
console.log("shouldStopPumping: ", shouldStopPumping);
|
||||
|
||||
|
||||
if (shouldStopPumping) {
|
||||
@@ -116,10 +117,50 @@ Api.addRoute('state/:id', {
|
||||
}
|
||||
});
|
||||
|
||||
Api.addRoute('picture/:id', {
|
||||
authRequired: false
|
||||
}, {
|
||||
post: function() {
|
||||
console.log("setting picture", this.bodyParams);
|
||||
return Picture.upsert({
|
||||
controller_id: this.urlParams.id
|
||||
}, {
|
||||
'$set': {
|
||||
'picture_base64': this.bodyParams.picture_base64,
|
||||
'time': new Date()
|
||||
}
|
||||
});
|
||||
},
|
||||
get: function() {
|
||||
var id = this.urlParams.id;
|
||||
var res = this.response;
|
||||
var picture_src = "/images/noImage.png";
|
||||
var pictureEntry = Picture.findOne({
|
||||
controller_id: id
|
||||
});
|
||||
if (pictureEntry) {
|
||||
var imageData = pictureEntry.picture_base64;
|
||||
picture_src = "data:image/jpeg;charset=utf-8;base64," + imageData;
|
||||
}
|
||||
return {
|
||||
picture: picture_src
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
function base64_to_buffer(base64string) {
|
||||
var buf;
|
||||
if (typeof Buffer.from === "function") {
|
||||
buf = Buffer.from(base64string, 'base64');
|
||||
} else {
|
||||
buf = new Buffer(base64string, 'base64');
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
function stateOrDefault(id) {
|
||||
var stateEntry = ControllerState.findOne({
|
||||
controller_id: id,
|
||||
controller_id: id
|
||||
});
|
||||
|
||||
if (stateEntry === undefined) {
|
||||
|
||||
Reference in New Issue
Block a user