Merge pull request #35 from senaduka/farm_alarm_voice

Farm alarm voice
This commit is contained in:
2017-01-05 15:25:38 +01:00
committed by GitHub
10 changed files with 50 additions and 29 deletions

View File

@@ -52,21 +52,21 @@
<td>2. <td>2.
</td> </td>
<td> <td>
<input required name="sms2" type="tel" id="sms2" placeholder="+3876xxxxxxxx" value={{ config 'sms2'}}/> <input required name="sms2" type="tel" id="sms2" placeholder="+3876xxxxxxxx" value={{ config 'sms2'}} />
</td> </td>
</tr> </tr>
<tr> <tr>
<td>3. <td>3.
</td> </td>
<td> <td>
<input required name="sms3" type="tel" id="sms3" placeholder="+3876xxxxxxxx" value={{ config 'sms3'}}/> <input required name="sms3" type="tel" id="sms3" placeholder="+3876xxxxxxxx" value={{ config 'sms3'}} />
</td> </td>
</tr> </tr>
<tr> <tr>
<td>4. <td>4.
</td> </td>
<td> <td>
<input required name="sms4" type="tel" id="sms4" placeholder="+3876xxxxxxxx" value={{ config 'sms4'}}/> <input required name="sms4" type="tel" id="sms4" placeholder="+3876xxxxxxxx" value={{ config 'sms4'}} />
</td> </td>
</tr> </tr>
</table> </table>

View File

@@ -45,9 +45,3 @@ Template.alarm_settings.events({
Meteor.call('saveAlarmSettings', controller_id, minTemperature, maxTemperature, timeoutBox, timeoutPhone, [sms1, sms2, sms3, sms4]); Meteor.call('saveAlarmSettings', controller_id, minTemperature, maxTemperature, timeoutBox, timeoutPhone, [sms1, sms2, sms3, sms4]);
} }
}); });
Template.sensorData.helpers({
created_at_formatted: function() {
return moment(this.created_at).format("DD.MM.YYYY, HH:mm")
}
});

View File

@@ -10,6 +10,10 @@
display: none; display: none;
} }
.no-bullets {
list-style-type: none;
}
.huge_text { .huge_text {
font-size: 2.5em; font-size: 2.5em;
} }
@@ -47,3 +51,10 @@
.clickable { .clickable {
cursor:pointer; cursor:pointer;
} }
.sensorData {
color: #101010;
font-family: 'PT Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
}

View File

@@ -1,9 +1,8 @@
<template name="log"> <template name="log">
<div class="hello"> <div class="hello">
<h1> Podaci sa senzora: </h1>
<button id="clear_log">Očisti</button> <ul class="no-bullets">
<ul>
{{#each sensorDataCollection}} {{#each sensorDataCollection}}
{{> sensorData}} {{> sensorData}}
{{/each}} {{/each}}

View File

@@ -22,13 +22,13 @@ Template.log.events({
Template.sensorData.helpers({ Template.sensorData.helpers({
created_at_formatted: function() { created_at_formatted: function() {
return moment(this.created_at).format("DD.MM.YYYY, HH:mm") return moment(this.created_at).format(/*"DD.MM.YYYY, */ " (HH:mm)")
}, },
all_temperatures: function(temperatures) { all_temperatures: function(temperatures) {
var result = ''; var result = '';
if (temperatures.length > 0) { if (temperatures.length > 0) {
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;

View File

@@ -1,3 +1,4 @@
<template name="sensorData"> <template name="sensorData">
<li>{{owner}} / <strong>{{temperatureValue}}°C {{all_temperatures temperatures}}</strong> / <strong>{{humidityValue}}%</strong> / Bačva puna: <strong>{{tankFull}}</strong> (L0:{{tankLevel0}}-L1:{{tankLevel1}}-L2:{{tankLevel2}}-L3:{{tankLevel3}}-L4:{{tankLevel4}}-full:{{tankFull}}) / {{created_at_formatted}}</li> <!--<li>{{owner}} / <strong>{{temperatureValue}}°C {{all_temperatures temperatures}}</strong> / <strong>{{humidityValue}}%</strong> / Bačva puna: <strong>{{tankFull}}</strong> (L0:{{tankLevel0}}-L1:{{tankLevel1}}-L2:{{tankLevel2}}-L3:{{tankLevel3}}-L4:{{tankLevel4}}-full:{{tankFull}}) / {{created_at_formatted}}</li> -->
<li class="sensorData"><strong>{{all_temperatures temperatures}}</strong> {{created_at_formatted}}</li>
</template> </template>

View File

@@ -35,9 +35,3 @@ Template.settings.events({
Meteor.call('saveControllerConfig', controller_id, selectedTime, selectedDays, manualInflow); Meteor.call('saveControllerConfig', controller_id, selectedTime, selectedDays, manualInflow);
} }
}); });
Template.sensorData.helpers({
created_at_formatted: function() {
return moment(this.created_at).format("DD.MM.YYYY, HH:mm")
}
});

View File

@@ -10,7 +10,7 @@
{{/if}} {{/if}}
{{#if accessible 'log'}} {{#if accessible 'log'}}
<li role="presentation" class="{{ class_for 'log' }}"><a class="clickable">Novosti</a></li> <li role="presentation" class="{{ class_for 'log' }}"><a class="clickable">Danas</a></li>
{{/if}} {{/if}}
{{#if accessible 'surveillance'}} {{#if accessible 'surveillance'}}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="woman" language="english">Zoblak Farm ALARM! ALARM! ALARM!</Say>
</Response>

View File

@@ -218,7 +218,7 @@ reactToAlarmData = function(controller_id) {
var boxSilent = config.timeoutBox && minutesSinceLastBoxContact > config.timeoutBox; var boxSilent = config.timeoutBox && minutesSinceLastBoxContact > config.timeoutBox;
var minutesSinceLastPhoneContact = state.lastPhoneContact ? moment(new Date()).diff(moment(state.lastPhoneContact), 'minutes') : -1; var minutesSinceLastPhoneContact = state.lastPhoneContact ? moment(new Date()).diff(moment(state.lastPhoneContact), 'minutes') : -1;
var phoneSilent = config.timeoutPhone && minutesSinceLastPhoneContact > config.timeoutPhone; var phoneSilent = false; //config.timeoutPhone && minutesSinceLastPhoneContact > config.timeoutPhone;
console.log("too ", tooCold, tooHot, boxSilent, phoneSilent); console.log("too ", tooCold, tooHot, boxSilent, phoneSilent);
console.log("lpc", state.lastPhoneContact); console.log("lpc", state.lastPhoneContact);
@@ -252,9 +252,11 @@ function soundTheAlarm(controller_id, tooCold, tooHot, boxSilent, phoneSilent) {
}; };
var smsSent = !!state.state.alarmSmsSent; var smsSent = !!state.state.alarmSmsSent;
var needsToSendSms = !smsSent && phoneSilent; var needsToSendSms = !smsSent // && phoneSilent;
var sendSmsPart = needsToSendSms ? { 'state.alarmSmsSent': true } : {}; var sendSmsPart = needsToSendSms ? {
'state.alarmSmsSent': true
} : {};
ControllerState.update(state._id, { ControllerState.update(state._id, {
'$set': Object.assign({ '$set': Object.assign({
@@ -265,18 +267,19 @@ function soundTheAlarm(controller_id, tooCold, tooHot, boxSilent, phoneSilent) {
}); });
if (needsToSendSms) { if (needsToSendSms) {
sendAlarmingSms(reason, state.config.smsNumbers) sendAlarmingSms(controller_id, reason, state.config.smsNumbers);
callTheUser(controller_id, reason, state.config.smsNumbers);
} }
} }
function sendAlarmingSms(reason, numbers) { function sendAlarmingSms(controller_id, reason, numbers) {
for (var i in numbers) { for (var i in numbers) {
var number = numbers[i]; var number = numbers[i];
twilio = Twilio('AC10d7ed0bf54c1be4b1cd7133130e63f4', 'e133d3f02a69b79e93ad9ca1d73517d1'); twilio = Twilio('AC10d7ed0bf54c1be4b1cd7133130e63f4', 'e133d3f02a69b79e93ad9ca1d73517d1');
twilio.sendSms({ twilio.sendSms({
to: number, // Any number Twilio can deliver to to: number, // Any number Twilio can deliver to
from: '+447481345235', // A number you bought from Twilio and can use for outbound communication from: '+19282124174', // A number you bought from Twilio and can use for outbound communication
body: 'Zoblak alarm! Pokrenite aplikaciju! HITNO! http://agrar.zoblak.com' // body of the SMS message body: 'Zoblak alarm! Pokrenite aplikaciju! HITNO! http://agrar.zoblak.com/alarm?controller_id=' + controller_id // body of the SMS message
}, function(err, responseData) { //this function is executed when a response is received from Twilio }, function(err, responseData) { //this function is executed when a response is received from Twilio
if (!err) { // "err" is an error received during the request, if any if (!err) { // "err" is an error received during the request, if any
// "responseData" is a JavaScript object containing data received from Twilio. // "responseData" is a JavaScript object containing data received from Twilio.
@@ -289,6 +292,21 @@ function sendAlarmingSms(reason, numbers) {
} }
} }
function callTheUser(controller_id, reason, numbers) {
for (var i in numbers) {
var number = numbers[i];
twilio = Twilio('AC10d7ed0bf54c1be4b1cd7133130e63f4', 'e133d3f02a69b79e93ad9ca1d73517d1');
twilio.makeCall({
to: number, // Any number Twilio can call
from: '+441143031932', // A number you bought from Twilio and can use for outbound communication
url: 'https://handler.twilio.com/twiml/EH9491c24474db07ec52b598baa5724f1e' // A URL that produces an XML document (TwiML) which contains instructions for the call
}, function(err, responseData) {
//executed when the call has been initiated.
console.log(err); // outputs "+14506667788"
});
}
}
function stopTheAlarm(controller_id, everythingIsBackToNormal = false) { function stopTheAlarm(controller_id, everythingIsBackToNormal = false) {
// time of alarm stopped is reset so that scheduled job can raise the alarm // time of alarm stopped is reset so that scheduled job can raise the alarm
// again // again