This shows you the differences between two versions of the page.
Next revision | Previous revision Next revision Both sides next revision | ||
sdk:alarm-via-voice [2016/09/16 15:12] juraschek created |
sdk:alarm-via-voice [2017/06/30 07:44] juraschek [Requirements] |
||
---|---|---|---|
Line 3: | Line 3: | ||
The Script will try to reach a phonenumber for a certain time, also retries after a specific time and give up after a defined timeout. | The Script will try to reach a phonenumber for a certain time, also retries after a specific time and give up after a defined timeout. | ||
+ | |||
+ | We will see the alarm as received if the Call was picked up. To be sure that a person picked up we only accept calls that last less then 10 seconds. This way we avoid false positives if a answering machine, a voice mail or a pbx will pickup the phone call. | ||
For this example we will work with die DIGITAL INPUT as an alarm. But you can trigger this script on many events. | For this example we will work with die DIGITAL INPUT as an alarm. But you can trigger this script on many events. | ||
Line 10: | Line 12: | ||
* Voice-License installed | * Voice-License installed | ||
* A SIM card with phonecalls enabled (some data-SIMs will not work) | * A SIM card with phonecalls enabled (some data-SIMs will not work) | ||
- | * NBSW [[ftp://share.netmodule.com/router/public/system-software/4.0/4.0.0.102/|4.0.0.102]] or higher | + | * NBSW [[ftp://share.netmodule.com/router/public/system-software/4.0/4.0.0.106/|4.0.0.106]] or higher |
Line 98: | Line 100: | ||
// How many times should we try to calll; | // How many times should we try to calll; | ||
retries=5;// | retries=5;// | ||
+ | |||
+ | //maximum time in seconds a call can be connected before we assume it's picked up by a machine | ||
+ | maxConnectTime=10; | ||
+ | |||
//Enable Debug Messages; | //Enable Debug Messages; | ||
- | DEBUG=false; | + | DEBUG=true; |
void debug(string msg) { | void debug(string msg) { | ||
if(DEBUG) { | if(DEBUG) { | ||
Line 142: | Line 148: | ||
- | | + | connectStart=0; |
callOngoing=true; | callOngoing=true; | ||
while(callOngoing) { | while(callOngoing) { | ||
Line 168: | Line 174: | ||
break; | break; | ||
case "connected": | case "connected": | ||
- | debug("handle connected: hangup"); | + | debug("handle connected:"); |
- | nb_syslog("Call with %s was answered. Alarm was succesfull",phoneNo); | + | nb_syslog("Call with %s was answered. Let's check if we have voicemail answering (max 10sec call)",phoneNo); |
- | sleep(2); | + | if (connectStart==0) connectStart=jiffy(); |
- | nb_syslog("We will terminated the call"); | + | |
- | nb_voice_call_hangup(event.call.id); | + | if (connectStart>0 && jiffy()-maxConnectTime>connectStart) { |
- | exit(0); | + | nb_syslog("We will terminated the call, call was anserwered by a machine, call was connected longer then 10 sec."); |
+ | nb_syslog("We will retry the call"); | ||
+ | nb_voice_call_hangup(event.call.id); | ||
+ | connecStart=0; | ||
+ | } | ||
break; | break; | ||
case "hungup": | case "hungup": | ||
+ | if (connectStart!=0) { | ||
+ | if (jiffy()-maxConnectTime<connectStart) { | ||
+ | nb_syslog("Call was ended before timeout we assume someone answered the call manually"); | ||
+ | nb_voice_call_hangup(event.call.id); | ||
+ | connectStart=0; | ||
+ | exit(0); | ||
+ | } | ||
+ | } | ||
break; | break; | ||
default: | default: | ||
Line 200: | Line 218: | ||
nb_syslog("Alarm was not successfull after %i seconds",jiffy()-startTime); | nb_syslog("Alarm was not successfull after %i seconds",jiffy()-startTime); | ||
exit(0); | exit(0); | ||
- | |||
</code> | </code> |