SOLVED: Door intercom system calls freePBX > automatic webcam image load on Cisco 7975 phones - how?

Hi,
I am using an analogue door intercom system
Auerswald TFS-dialog 300
connected to a
Fritzbox 7390 internet modem/phone system
which is connected to a freePBX (Asterisk 1.8) system through a sip-trunk.
The door intercom system dials the number of a freePBX ring group with Cisco 7975 phones. At the door there is a Trivision NC-326PW camera, which produces jpeg-snapshots. These snapshots can be displayed on the Cisco displays.
Everything works fine. Now I want to automatically display the webcam image on every Cisco 7975, when somebody presses the door bell button on the Auerswald intercom system.
Is there any way to start an agi script (by asterisk) without interrupting the call flow. What is the code I have to add to extensions_custom.conf? Asterisk should just start the script and not wait for any response and just go on…
My showcam.agi looks like this:

#!/bin/sh
cd /var/www/html/xmlservices/
php cam-start-11.php;
sleep 1
php cam-start-12.php;
php cam-start-13.php;
php cam-start-14.php;
php cam-start-15.php;
php cam-start-17.php;
sleep 25
php cam-stop-11.php;
php cam-stop-12.php;
php cam-stop-13.php;
php cam-stop-14.php;
php cam-stop-15.php;
php cam-stop-17.php;  

(cam-start-11 converts the camera image, stores it on the freepbx server and loads it, the other cam-start-scripts just load the image)
It works fine in the terminal and starts the other scripts. Is there any way to do it automatically?
The name of the incoming trunk is “fritzbox”.

Thanks
Reinhard

How to start a script is described in this post

[from-trunk-sip-MyTrunkName]
;Run Script
exten => .,1,System(/path/to/your/script)
;Continue on to default “trunk handling” from GUI
exten => .,n,Goto(from-trunk,${EXTEN},1)
; end of [from-trunk-sip-MyTrunkName]

however, I need asterisk to start the script without interfering with the normal call flow.
Any ideas?

Here’s a link to an image, which shows the results of my showcam script collection :wink:
http://www.ip-phone-forum.de/attachment.php?attachmentid=77992&d=1411914351

Is async-agi the solution to my problem?

Thanks
Reinhard

No the async AGI is way more than you need and is for talking back through AMI, just call the script and make sure that all output to stdout and stderr is sent to the bit bucket and then background your script, use TrySystem not System or a badly constructed script will close the channel.

TrySystem(/path/to/your/script > /dev/null 2>&1 &)

It should return to asterisk immediately

2 Likes

THANK YOU SOOOOOO MUCH!!! :smiley:

It perfectly works now! The webcam image loads and disappears automatically if someone presses the door bell button.

Wonderful!
Thanks
Reinhard

Here are my (working) settings:
extensions_custom.conf

[from-trunk-sip-fritzbox]
exten=>s,1,TrySystem(/var/lib/asterisk/agi-bin/showcam.agi > /dev/null 2>&1 &)
exten=>n,Hangup()

In case, somebody is interested in the scripts I am using. I found them on the www and adapted them.
You’ll find my adapted versions here
IP-Phone-Forum

I know this is already solved, but I noticed something in your configuration that you might wish to change.

Right now, if someone ripped out your doorphone and hooked up an analog phone or test set, they could call anywhere in the world on your dime. You might want to change your configuration as follows:

  1. In the Extensions setting for the door phone extension, change the context from “from-internal” to “from-trunk”
  2. Configure your doorphone to dial a fictional phone number instead if your ring group (i.e. 212-555-12121 - yes, I meant this to be one digit longer than a real phone number!).
  3. Configure an inbound route for the fictional phone number that routes to the ring group.

Now, if someone taps into your door phone, the only numbers that they can dial are DIDs you have configured on your system anyway, and all of those internal calls would be free…

1 Like

Thanks AdHominem for your detailed and helpful reply!
The door intercom system is connected to a Fritzbox (internet modem/phone system, extension 1). On the fritzbox I did not setup any external number or any external trunk.
I just added another extension (internal number
620) for a sip phone, which is connected to the freePBX system. So the door intercom system just dials **620 and the call goes to freePBX.
On the freePBX I have a separate trunk for the intercom/fritzbox calls and an incoming CID priority route for **1, which directly routes the call to the door ring group (601).
I think in this special case, there is no way, somebody could use the door intercom line to make an external call.
Am I wrong?

Here are my adapted scripts. The most important one, the cam.php I found here
Cisco webcam script

extensions_custom.conf (THANKS to dicko!!!)

[from-trunk-sip-fritzbox]
exten=>s,1,TrySystem(/var/lib/asterisk/agi-bin/showcam.agi > /dev/null 2>&1 &)
exten=>n,Hangup()

/var/lib/asterisk/agi-bin/showcam.agi

#!/bin/sh
cd /var/www/html/xmlservices/
php cam-start-11.php;
php cam-start-12.php;
php cam-start-13.php;
php cam-start-14.php;
php cam-start-15.php;
php cam-start-17.php;
sleep 40
php cam-stop-11.php;
php cam-stop-12.php;
php cam-stop-13.php;
php cam-stop-14.php;
php cam-stop-15.php;
php cam-stop-17.php;

/var/www/html/xmlservices/cam-start-11.php

<?php
$ip = "192.168.0.211";
$uri = "http://192.168.0.34/xmlservices/cam-11.php";
$uid = "admin";
$pwd = "cisco";

function push2phone($ip, $uri, $uid, $pwd)
{
$auth = base64_encode($uid.":".$pwd);
$xml = "<CiscoIPPhoneExecute><ExecuteItem Priority=\"0\"URL=\"".$uri."\"/></CiscoIPPhoneExecute>";
$xml = "XML=".urlencode($xml);

$post = "POST /CGI/Execute HTTP/1.0\r\n";
$post .= "Host: $ip\r\n";
$post .= "Authorization: Basic $auth\r\n";
$post .= "Connection: close\r\n";
$post .= "Content-Type: application/x-www-form-urlencoded\r\n";
$post .= "Content-Length: ".strlen($xml)."\r\n\r\n";

$fp = fsockopen ( $ip, 80, $errno, $errstr, 30);
if(!$fp){ echo "$errstr ($errno)<br>\n"; }
else
{
fputs($fp, $post.$xml);
flush();
while (!feof($fp))
{
$response .= fgets($fp, 128);
flush();
}
}

return $response;
}

echo push2phone($ip, $uri, $uid, $pwd);
?>

/var/www/html/xmlservices/cam-stop-11.php

<?php
$ip = "192.168.0.211";
$uri = "Init:Services";
$uid = "admin";
$pwd = "cisco";

function push2phone($ip, $uri, $uid, $pwd)
{
$auth = base64_encode($uid.":".$pwd);
$xml = "<CiscoIPPhoneExecute><ExecuteItem Priority=\"0\"URL=\"".$uri."\"/></CiscoIPPhoneExecute>";
$xml = "XML=".urlencode($xml);

$post = "POST /CGI/Execute HTTP/1.0\r\n";
$post .= "Host: $ip\r\n";
$post .= "Authorization: Basic $auth\r\n";
$post .= "Connection: close\r\n";
$post .= "Content-Type: application/x-www-form-urlencoded\r\n";
$post .= "Content-Length: ".strlen($xml)."\r\n\r\n";

$fp = fsockopen ( $ip, 80, $errno, $errstr, 30);
if(!$fp){ echo "$errstr ($errno)<br>\n"; }
else
{
fputs($fp, $post.$xml);
flush();
while (!feof($fp))
{
$response .= fgets($fp, 128);
flush();
}
}

return $response;
}

echo push2phone($ip, $uri, $uid, $pwd);
?>

Last but not least, the open-door.php.
(My intercom door system requires digits #9 to be pressed during a call to unlock the door.)
/var/www/html/xmlservices/open-door-11.php

<?php
$ip = "192.168.0.211";
$uri = "SendDigits:#9";
$uid = "admin";
$pwd = "cisco";

function push2phone($ip, $uri, $uid, $pwd)
{
$auth = base64_encode($uid.":".$pwd);
$xml = "<CiscoIPPhoneExecute><ExecuteItem Priority=\"0\"URL=\"".$uri."\"/></CiscoIPPhoneExecute>";
$xml = "XML=".urlencode($xml);

$post = "POST /CGI/Execute HTTP/1.0\r\n";
$post .= "Host: $ip\r\n";
$post .= "Authorization: Basic $auth\r\n";
$post .= "Connection: close\r\n";
$post .= "Content-Type: application/x-www-form-urlencoded\r\n";
$post .= "Content-Length: ".strlen($xml)."\r\n\r\n";

$fp = fsockopen ( $ip, 80, $errno, $errstr, 30);
if(!$fp){ echo "$errstr ($errno)<br>\n"; }
else
{
fputs($fp, $post.$xml);
flush();
while (!feof($fp))
{
$response .= fgets($fp, 128);
flush();
}
}
return "Das HAUSTOR wurde entriegelt, bitte HÖRER auflegen und FENSTER schliessen! DANACH im KAMERAFENSTER auf Taste AKTUAL. drücken.";
}
echo push2phone($ip, $uri, $uid, $pwd);
?>

One LineButton on the Cisco 7975s is configured to execute the script.
SEP.conf.xml

 	<line button="8">
	<featureID>20</featureID>
	<featureLabel>HAUSTOR ÖFFNEN</featureLabel>
	<serviceURI>http://192.168.0.34/xmlservices/open-door-11.php</serviceURI>
	</line>
1 Like

Glad you got it working, but looking at what you are trying to do I might split the process into three logical steps to improve your experience:-

Step one, send the snapshots to all the phones, to make sure you don’t answer a guy with a stripy shirt and a mask :slight_smile: .

Step two, on answer, use a regular agi script to turn off pictures on all phones that didn’t answer and turn on a live feed to the extension that answered.

Step three, call the same (or another) agi script in the “hangup” extension to turn off the video feed when the call is completed (maybe you should wait a few seconds to make sure the visitor gets entrance.)

Thanks dicko for your helpful suggestions.
I have no programming skills, I just search for scripts or code pieces and try to understand, adapt and use them.

I actually send the snapshot to all phones. For every extension I have one cam-start-script (and stop and open-door script). All Cisco 7975 phones ring and display the webcam image. The cam-stop-scripts turn off the cam image after 40s or so on every extension.
Once you answer the call, the camera image disappears and you can press the “door open” button, which dials #9 (inband audio). After hang up, the camera image shows up again and you have to press the refresh button to see the visitor entering the building.
I did try to use a refresh header to automatically reload the cam image every 3 seconds or so, but it somehow interfered with the dial digits script.
I think the Cisco 7975 is not designed for a video live feed, it is 7 years old :wink:

Thanks
Reinhard

An Auerswald-TFS-300 door intercom system calls FreePBX through a trunk (Fritzbox>freePBX), see above. The agi-script creates and uploads a cam-jpeg to all Ciscos in a ringgroup. It has been working for years now.
I currently try to set up a new FreePBX-14-system with Asterisk 13 (FreePBX distro). It seems to me that the old workaround (FreePBX 13 and Asterisk 11) is not applicable.

extensions_custom.conf
[from-trunk-sip-fritzbox]
exten=>s,1,TrySystem(/var/lib/asterisk/agi-bin/showcam.agi > /dev/null 2>&1 &)
exten=>n,Hangup()

Nothing happens…I don’t see anything in the asterisk log. If I start showcam.agi by hand (terminal) all Ciscos display the cam image.

Any ideas? Did the dialplan change from Asterisk 11 to 13? If yes, what is the proper way to accomplish this?

Thanks
Reinhard

By the way, this works on my Cisco 7975s and 8961s…but I cannot get it working on a new FreePBX 14 system, which might be related to a different dialplan structure…

ok…I can confirm this webcam-jpeg-door-intercom-cisco-solution still works, even on freePBX 14 and Asterisk 13. Somehow I got confused with the incoming and outgoing sip settings of the trunk.
I had to put this
context=from-trunk-sip-fritzbox
in the outgoing settings of the trunk…dont know why…the intercom calls come in on this trunk…anyway, it works happy0045

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.