Alarming with a Phonecall

To contact a technican with a phone call and check if he picked up the phone we can use the following SDK Script and the Voice Gateway feature.

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.


  • NB1601, NB800 (Rev B.), NB1600, NB2700, NB3700 with a voice featured modem
  • Voice-License installed
  • A SIM card with phonecalls enabled (some data-SIMs will not work)

You can check the Voice-function in the web manager System→License.

If there is not availability or a positive licensing status please contact our support team. In the most cases this is a configuration issue.

Please also make sure your sim card is succefully registered in the mobile network


The Configuration is done in two steps:

  1. Enable and cofigure the voice gateway
  2. Paste and Configure the SDK Script

Voice Gateway

Enable the Administrative Status and set the Call Routing to SDK

Add two Endpoint Voice-over-Mobile and Nil-Device


Enable the SDK and configure script,trigger,job.

  • Script: Name: phone-alarm, Arguments: Destination Phonenumber, edit: Paste the script from below
  • Trigger: Name: din1-on, Type: event-based, Event: dio-in1-on
  • Job: combine the script phone-alarm and the trigger din1-on to a job.


Please test the script by using the “Trigger Job” Button on the right side of the Jobs overview.

You can also enable a input signal on the DI1 Input

A call should be initiated.

You will see the output of the script in System→Troubeshooting→System Debuging Systemlog.

SDK Skript

The SDK Script will contact the Phonenumber from the first argument.

By default he will wait 30 sec before hanging up, then wait 60 sec before making the next call and repeat this 5 times. This can be configured in the first lines of the script.

  • The Number called need to pick up the phone to stop this Alarm.
  • If he refuse the call the alarm will go on.
  • Please keep in mind, that in some cases a Mailbox/Voicebox can pick up the phone and the script will take this as an successfull phone call.
/* DESC: This script can be used to send an alert call via a voice phone call
 * Copyright (C) 2016 NetModule AG
// Who should we call
// How many seconds should we wait to answer the call
timeout=30; //seconds
// How manay seconds should we wait for the next try
// How many times should we try to calll;
//maximum time in seconds a call can be connected before we assume it's picked up by a machine
//Enable Debug Messages;
void debug(string msg) {
    if(DEBUG) {
        nb_syslog("DEBUG: %s",msg);
        printf("DEBUG: %s\n",msg);
//function to get the current uptime seconds
int jiffy()
        sys = sysinfo();
        u = struct_get(sys, "uptime");
        if (is_void(u) || u < 1) {
            return 0;
        } else {
            return u;
while(tryNo<retries+1) {
    dialcall = mkstruct(
        "calling", "nil://@Nil1",  // who is calling  (source). On NB1600 it's always the NULL Device (nil)
        "called", sprintf("vom://%s",phoneNo)  //who will be called (destination) Can be Voice over Mobile (Vom) or a SIP Endpoint
    nb_syslog("starting to call  %s from %s", dialcall.called, dialcall.calling);
    if(nb_voice_call_dial(dialcall) < 0) {
        nb_syslog("error: dial failed\n");
    nb_syslog("Call to %s sucessfully initiated",phoneNo);
    while(callOngoing) {
        event = nb_voice_event(1);
        if (is_struct( {
            debug(sprintf("event %s call %d (%s)\n- <%s>\n- <%s>"
                , event.type
            switch (event.type) {
                case "outgoing":
                    debug("handle outgoing: -");
                case "incoming":
                    debug("handle incoming: -");
                case "dialing":
                    debug("handle dialing: ");
                case "dispatched":
                    debug("handle dispatched: -");
                case "connected":
                    debug("handle connected:");
                    nb_syslog("Call with %s was answered. Let's check if we have voicemail answering (max 10sec call)",phoneNo);
                    if (connectStart==0) connectStart=jiffy();        
                     if (connectStart>0 && jiffy()-maxConnectTime>connectStart) {
                            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");
                case "hungup":
                    if (connectStart!=0) {
                        if (jiffy()-maxConnectTime<connectStart) {
                        nb_syslog("Call was ended before timeout we assume someone answered the call manually");
        } else {
            debug(sprintf("handle event timeout: %d", jiffy()-tryStart));
            if (jiffy()>tryStart+timeout) {
                call = nb_voice_call_get(dialcall);
                if (call) {
                    debug("handle timer: hangup");
                    nb_syslog("We let it ring for %i seconds, let's hangup",timeout);
                } else {
                    debug("handle timer: call not found");
nb_syslog("Alarm not successfull after %i call, let's wait %i sec and try again",tryNo,callbreak);
nb_syslog("Alarm was not successfull after %i seconds",jiffy()-startTime);