2015-12-27 06:26:48 +01:00
|
|
|
if (Meteor.isServer) {
|
|
|
|
|
Meteor.startup(function() {
|
|
|
|
|
// code to run on server at startup
|
2016-02-14 10:34:54 +01:00
|
|
|
SyncedCron.start();
|
2017-01-05 15:39:34 +01:00
|
|
|
|
|
|
|
|
Meteor.zoblak.server.on_all_controllers(function(controller_id) {
|
2017-05-21 17:51:45 +02:00
|
|
|
if(!controller_id) { return; }; // protects from null controller_id
|
2017-01-05 15:39:34 +01:00
|
|
|
var jobName = "automatic_alarm_" + controller_id;
|
|
|
|
|
|
|
|
|
|
SyncedCron.remove(jobName);
|
|
|
|
|
SyncedCron.add({
|
|
|
|
|
name: jobName,
|
|
|
|
|
schedule: function(parser) {
|
|
|
|
|
return parser.text('every 10 seconds');
|
|
|
|
|
},
|
|
|
|
|
job: function() {
|
|
|
|
|
reactToAlarmData(controller_id);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-12-27 06:26:48 +01:00
|
|
|
});
|
|
|
|
|
|
2016-06-02 23:13:42 +02:00
|
|
|
|
2015-12-27 06:26:48 +01:00
|
|
|
// Global API configuration
|
|
|
|
|
var Api = new Restivus({
|
|
|
|
|
useDefaultAuth: true,
|
|
|
|
|
prettyJson: true
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-02 23:13:42 +02:00
|
|
|
Api.addRoute('sensorData', {
|
|
|
|
|
authRequired: false
|
|
|
|
|
}, {
|
|
|
|
|
post: function() {
|
|
|
|
|
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,
|
2017-01-05 15:39:34 +01:00
|
|
|
tankFull: this.bodyParams.tankFull,
|
2016-06-09 20:07:38 +02:00
|
|
|
startPumpingAt: this.bodyParams.startPumpingAt,
|
|
|
|
|
stopPumpingAt: this.bodyParams.stopPumpingAt,
|
2016-06-02 23:13:42 +02:00
|
|
|
owner: this.bodyParams.owner,
|
|
|
|
|
created_at: new Date()
|
|
|
|
|
});
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2015-12-27 06:26:48 +01:00
|
|
|
}
|