TUTORIAL Wazo: Use button on phones to control lighting or other event

Joined
Nov 14, 2008
Messages
1,396
Reaction score
320
Below is an example of a programmatic interface between a SIP phone, Wazo and a ELK alarm panel configured for lighting control.

The example could easily be changed to send whatever you like, wherever you like and is just meant to illustrate how this type of thing is put in place on an existing Wazo install.

In the example the string to send is constructed and then sent to the ELK device over the lan. The ELK has an Ethernet to RS232 interface.

Without the appropriate entries in the Wazo locations directory the ngix webserver would not accept the URL.

An ELK command specification manual is attached.


Code:
create the file /etc/nginx/locations/https-available/elk-commands
with the following contents:

location ~ /elk/ {
 root /var/www/html;
 index index.php;
 try_files $uri $uri/ =404;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_index index.php;
 include fastcgi_params;
 fastcgi_pass unix:/var/run/php5-fpm.sock;
}


then create this link to it
ln -s /etc/nginx/locations/http-enabled/elk-commands /etc/nginx/locations/http-available/elk-commands

create the file:
/var/www/html/elk/elkm1y.php

add this content:

<?php

#Elk M1 php command sender
#Syntax Example: Source ip -> Destination IP  Port   Command
#http://XXX.XXX.XXX.XXX/elk/elkm1y.php?elkip=XXX.XXX.XXX.XXX&elkport=2101&&elkcmd=pnI11
#Brian Kelly 2017


#Initialize some variables
$command = 0;
$val = 0;
$i = 0;
$EOF = "\r\n";

#Get input values from XML URL sent by phone
$elkcmd=$_GET['elkcmd'];
$elkip=$_GET['elkip'];
$elkport=$_GET['elkport'];

# Add the two future use characters to the string.
$elkcmd .= '00';

# Assemble it, prepend length value + 2.
$command = sprintf('%02X',strlen($elkcmd) + 2  ).$elkcmd;
        
#Loop through string and calc checksum
        for ($i=0;$i<strlen($command);$i++) {
               $val += ord(substr($command,$i,1));
    }
#Attach value to end of string command
$command .= sprintf('%02X',((~$val + 1) & 0xFF));

#Open addr and port, send command plus EOF
$fp = fsockopen($elkip, $elkport);
fwrite($fp, $command.$EOF);
fclose($fp);

exit;


?>

Commands can then be sent by crafting a URL (see example above) and either executing it from a browser (for testing) or assigning it to
a URL button on a phone.
 

Attachments

Members online

Forum statistics

Threads
26,687
Messages
174,411
Members
20,257
Latest member
Dempan
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Back
Top