{{/if}}
{{#if accessible 'surveillance'}}
diff --git a/app/public/sayings/alarm.twiml.xml b/app/public/sayings/alarm.twiml.xml
new file mode 100644
index 0000000..ef68adf
--- /dev/null
+++ b/app/public/sayings/alarm.twiml.xml
@@ -0,0 +1,4 @@
+
+
+ Zoblak Farm ALARM! ALARM! ALARM!
+
diff --git a/app/server/methods.js b/app/server/methods.js
index d601952..11a169d 100644
--- a/app/server/methods.js
+++ b/app/server/methods.js
@@ -218,7 +218,7 @@ reactToAlarmData = function(controller_id) {
var boxSilent = config.timeoutBox && minutesSinceLastBoxContact > config.timeoutBox;
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("lpc", state.lastPhoneContact);
@@ -252,9 +252,11 @@ function soundTheAlarm(controller_id, tooCold, tooHot, boxSilent, phoneSilent) {
};
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, {
'$set': Object.assign({
@@ -265,18 +267,19 @@ function soundTheAlarm(controller_id, tooCold, tooHot, boxSilent, phoneSilent) {
});
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) {
var number = numbers[i];
twilio = Twilio('AC10d7ed0bf54c1be4b1cd7133130e63f4', 'e133d3f02a69b79e93ad9ca1d73517d1');
twilio.sendSms({
to: number, // Any number Twilio can deliver to
- from: '+447481345235', // 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
+ from: '+19282124174', // A number you bought from Twilio and can use for outbound communication
+ 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
if (!err) { // "err" is an error received during the request, if any
// "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) {
// time of alarm stopped is reset so that scheduled job can raise the alarm
// again