Monthly Archives: May 2018

Groundwire push notifications with private SIP server

Acrobits’ Groundwire is a SIP soft-phone app for iOS. To receive incoming calls while the app is inactive, it either runs in the background (which drains the battery pretty quickly) or uses push notifications. The latter requires you to entrust Acrobits’ servers with your login credentials and only works for SIP servers reachable from the internet, so it is is not an option for private/internal SIP servers.

However, Acrobits offers a push notification HTTP API. This article tells you how to use it for this purpose.

First, you need the app to report its push token to your server. A PHP script like this one can accept this information and store it into your Asterisk server’s database:

$key = $_POST['username'];
$key = filter_var($key, FILTER_SANITIZE_NUMBER_INT);
$value = $_POST['token'];
if ($value == '')
 header('HTTP/1.0 422 Unprocessable Entity', TRUE, 422);
 die('No token provided');
shell_exec("sudo asterisk -rx 'database put GroundwireToken " . escapeshellarg($key) . " " . escapeshellarg($value) . "'");

$value = $_POST['selector'];
shell_exec("sudo asterisk -rx 'database put GroundwireSelector " . escapeshellarg($key) . " " . escapeshellarg($value) . "'");

$value = $_POST['appid'];
shell_exec("sudo asterisk -rx 'database put GroundwireApp " . escapeshellarg($key) . " " . escapeshellarg($value) . "'");

In Groundwire, go to Settings, Accounts, edit your account, Advanced Settings, Web Services, Push Token Reporter. For URL, enter the full URL of the above script. For POST, enter

Second, you need to modify your dialplan to send a push notification that wakes up the app. I created a subroutine for that purpose:

exten => _XX,1,GotoIf(${DB_EXISTS(GroundwireToken/${EXTEN})}]?groundwire)
same => n,Return()
same => n(groundwire),Set(push_data=verb=NotifyTextMessage&Selector=${URIENCODE(${DB(GroundwireSelector/${EXTEN})})}&DeviceToken=${URIENCODE(${DB(GroundwireToken/${EXTEN})})}&AppId=${URIENCODE(${DB(GroundwireApp/${EXTEN})})})
same => n,Noop(Groundwire: ${CURL("",${push_data})})
same => n,Ringing()
same => n,Wait(3) ; give app some time to activate
same => n(done),Return()
exten => i,1,Return()
exten => s,1,Return()

Then, in your dialplan, call that subroutine, like so:

exten => _XX,Noop(Incoming call for ${EXTEN})
same => n,Gosub(sub-push,${EXTEN},1)
same => n,Dial(SIP/${EXTEN})

Because there is no (documented) way to tell the app to dial a number (e.g. one that does PickupChan(SIP/${CALLERID(num)})) when it receives the push notification, we are simply waiting for three seconds for the app to launch and register and then proceed signalling the call.