alarm triggering / silencing works
This commit is contained in:
@@ -3,6 +3,12 @@
|
|||||||
<div class="hello">
|
<div class="hello">
|
||||||
<h1> Temperatura </h1>
|
<h1> Temperatura </h1>
|
||||||
<div class="jumbotron text-center center-block" >
|
<div class="jumbotron text-center center-block" >
|
||||||
|
{{#with state}}
|
||||||
|
{{#if alarmTriggered}}
|
||||||
|
<img src="/images/alarm.gif" class="img-responsive center-block" id="alarm_image" />
|
||||||
|
<button id="stop_alarm" class="btn btn-danger"> <i class="fa fa-ban"></i> Prekini </button>
|
||||||
|
{{/if}}
|
||||||
|
{{/with}}
|
||||||
{{#with last_reading}}
|
{{#with last_reading}}
|
||||||
<div class="huge_text"> {{ all_temperatures }}</div>
|
<div class="huge_text"> {{ all_temperatures }}</div>
|
||||||
<div>{{pretty_time created_at}}</div>
|
<div>{{pretty_time created_at}}</div>
|
||||||
|
|||||||
@@ -25,14 +25,17 @@ function last_sensor_reading() {
|
|||||||
|
|
||||||
Template.alarm.helpers({
|
Template.alarm.helpers({
|
||||||
last_reading: last_sensor_reading,
|
last_reading: last_sensor_reading,
|
||||||
|
state: function() {
|
||||||
|
return Meteor.zoblak.client.controller_state().state;
|
||||||
|
},
|
||||||
pretty_time: function(time) {
|
pretty_time: function(time) {
|
||||||
return moment(time).format("DD.MM.YYYY, HH:mm")
|
return moment(time).format("DD.MM.YYYY, HH:mm")
|
||||||
},
|
},
|
||||||
all_temperatures: function() {
|
all_temperatures: function() {
|
||||||
var result="";
|
var result = "";
|
||||||
var temperatures = last_sensor_reading().temperatures;
|
var temperatures = last_sensor_reading().temperatures;
|
||||||
|
|
||||||
for(var i in temperatures) {
|
for (var i in temperatures) {
|
||||||
result += '' + parseFloat(temperatures[i]).toFixed(1) + ' °C ';
|
result += '' + parseFloat(temperatures[i]).toFixed(1) + ' °C ';
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -42,6 +45,10 @@ Template.alarm.helpers({
|
|||||||
Template.alarm.events({
|
Template.alarm.events({
|
||||||
'click #run_alarm_settings': function() {
|
'click #run_alarm_settings': function() {
|
||||||
Modal.show('alarm_settings');
|
Modal.show('alarm_settings');
|
||||||
|
},
|
||||||
|
'click #stop_alarm': function() {
|
||||||
|
let controller_id = Meteor.zoblak.client.controller_state().controller_id;
|
||||||
|
Meteor.call('stopTheAlarm', controller_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -23,3 +23,19 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@media all and (orientation: portrait) {
|
||||||
|
#alarm_image {
|
||||||
|
width: 90%;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media all and (orientation: landscape) {
|
||||||
|
#alarm_image {
|
||||||
|
width: 40%;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
BIN
app/public/images/alarm.gif
Normal file
BIN
app/public/images/alarm.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 590 KiB |
@@ -97,20 +97,6 @@ reactToSensorData = function(nextSensorReading) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Api.addRoute('alarm/:id/stop', {
|
|
||||||
authRequired: false
|
|
||||||
}, {
|
|
||||||
post: function() {
|
|
||||||
var state = Meteor.zoblak.server.controller_state(controller_id);
|
|
||||||
ControllerState.update(state._id, {
|
|
||||||
'$set': {
|
|
||||||
'state.alarmTriggered': false,
|
|
||||||
'state.alarmStopped': new Date()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Api.addRoute('state/:id', {
|
Api.addRoute('state/:id', {
|
||||||
authRequired: false
|
authRequired: false
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
function setOutValveTo(controller_id, nextState) {
|
function setOutValveTo(controller_id, nextState) {
|
||||||
var state = Meteor.zoblak.server.controller_state(controller_id);
|
var state = Meteor.zoblak.server.controller_state(controller_id);
|
||||||
ControllerState.update(state._id, {
|
ControllerState.update(state._id, {
|
||||||
@@ -173,6 +172,12 @@ function saveAlarmSettings(controller_id, minTemperature, maxTemperature, timeou
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// there are three states of alarm:
|
||||||
|
// 1. normal ( state.alarmTriggered: false, state.alarmStopped: null )
|
||||||
|
// 2. triggered ( state.alarmTriggered: true, state.alarmStopped: null )
|
||||||
|
// 3. silenced ( state.alarmTriggered: false, state.alarmStopped: (sometime) )
|
||||||
|
|
||||||
function reactToAlarmData(controller_id) {
|
function reactToAlarmData(controller_id) {
|
||||||
var reading = last_sensor_reading(controller_id);
|
var reading = last_sensor_reading(controller_id);
|
||||||
var state = Meteor.zoblak.server.controller_state(controller_id);
|
var state = Meteor.zoblak.server.controller_state(controller_id);
|
||||||
@@ -181,7 +186,7 @@ function reactToAlarmData(controller_id) {
|
|||||||
var minTemperature = function(temperatures) {
|
var minTemperature = function(temperatures) {
|
||||||
// if it gets a lot colder than absolute zero we will
|
// if it gets a lot colder than absolute zero we will
|
||||||
// we will have more problems than the bug in this code
|
// we will have more problems than the bug in this code
|
||||||
if(size(temperatures) <= 0) return -1000;
|
if (temperatures.length <= 0) return -1000;
|
||||||
var minimal = parseFloat(temperatures[0]);
|
var minimal = parseFloat(temperatures[0]);
|
||||||
for (var i in temperatures) {
|
for (var i in temperatures) {
|
||||||
if (parseFloat(temperatures[i]) < minimal) {
|
if (parseFloat(temperatures[i]) < minimal) {
|
||||||
@@ -193,7 +198,7 @@ function reactToAlarmData(controller_id) {
|
|||||||
|
|
||||||
var maxTemperature = function(temperatures) {
|
var maxTemperature = function(temperatures) {
|
||||||
// obviously - hell is not supported in this version
|
// obviously - hell is not supported in this version
|
||||||
if(size(temperatures) <= 0) return 1000;
|
if (temperatures.length <= 0) return 1000;
|
||||||
var maximal = parseFloat(temperatures[0]);
|
var maximal = parseFloat(temperatures[0]);
|
||||||
for (var i in temperatures) {
|
for (var i in temperatures) {
|
||||||
if (parseFloat(temperatures[i]) > maximal) {
|
if (parseFloat(temperatures[i]) > maximal) {
|
||||||
@@ -213,12 +218,17 @@ function reactToAlarmData(controller_id) {
|
|||||||
var minutesSinceLastPhoneContact = state.lastPhoneContact ? moment(state.lastPhoneContact).diff(moment(new Date()), 'minutes') : -1;
|
var minutesSinceLastPhoneContact = state.lastPhoneContact ? moment(state.lastPhoneContact).diff(moment(new Date()), 'minutes') : -1;
|
||||||
var phoneSilent = config.timeoutPhone && minutesSinceLastPhoneContact > config.timeoutPhone;
|
var phoneSilent = config.timeoutPhone && minutesSinceLastPhoneContact > config.timeoutPhone;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (tooCold || tooHot || boxSilent || phoneSilent) {
|
if (tooCold || tooHot || boxSilent || phoneSilent) {
|
||||||
soundTheAlarm(tooCold, tooHot, boxSilent, phoneSilent);
|
var alarmSilenced = !!state.state.alarmStopped;
|
||||||
|
if (!alarmSilenced) soundTheAlarm(controller_id, tooCold, tooHot, boxSilent, phoneSilent);
|
||||||
|
} else {
|
||||||
|
stopTheAlarm(controller_id, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function soundTheAlarm(tooCold, tooHot, boxSilent, phoneSilent) {
|
function soundTheAlarm(controller_id, tooCold, tooHot, boxSilent, phoneSilent) {
|
||||||
var state = Meteor.zoblak.server.controller_state(controller_id);
|
var state = Meteor.zoblak.server.controller_state(controller_id);
|
||||||
var reason = {
|
var reason = {
|
||||||
tooHot: tooHot,
|
tooHot: tooHot,
|
||||||
@@ -262,7 +272,18 @@ function sendAlarmingSms(reason, numbers) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stopTheAlarm(controller_id, everythingIsBackToNormal = false) {
|
||||||
|
// time of alarm stopped is reset so that scheduled job can raise the alarm
|
||||||
|
// again
|
||||||
|
var timeOfStopping = (everythingIsBackToNormal) ? null : new Date();
|
||||||
|
var state = Meteor.zoblak.server.controller_state(controller_id);
|
||||||
|
ControllerState.update(state._id, {
|
||||||
|
'$set': {
|
||||||
|
'state.alarmTriggered': false,
|
||||||
|
'state.alarmStopped': timeOfStopping
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function last_sensor_reading(controller_id) {
|
function last_sensor_reading(controller_id) {
|
||||||
var result = null;
|
var result = null;
|
||||||
@@ -293,5 +314,6 @@ Meteor.methods({
|
|||||||
clearLog: clearLog,
|
clearLog: clearLog,
|
||||||
saveControllerConfig: saveControllerConfig,
|
saveControllerConfig: saveControllerConfig,
|
||||||
requestNewPicture: requestNewPicture,
|
requestNewPicture: requestNewPicture,
|
||||||
saveAlarmSettings: saveAlarmSettings
|
saveAlarmSettings: saveAlarmSettings,
|
||||||
|
stopTheAlarm: stopTheAlarm
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user