Showing posts with label asterisk. Show all posts
Showing posts with label asterisk. Show all posts

Monday, October 26, 2009

utils.c broken pipe error - Asterisk or Application error? Fix

I had debated myself whether it could be asterisk or application error. I'm trying to write something to the receiver and the receiver already closed my acceptance.

Should I need to produce an error or not?

To sort this problem if you have certain delay (like sleep or usleep to .5 secs) to receive the data from Asterisk you are fine. Any scripts or remote manager sockets calling this need to wait for the same to get this error go away.

sleep(.5); // or if it can take only integers you can have sleep(1);
Make sure you consider this time when handling call.

Alternatively if you want to get the error to ignore, you can edit utils.c and comment the line producing this error. Also keep in mind when you have errors with file or socket, it will get ignored.

Hope it helps !

Monday, June 29, 2009

Automate your dialling with Bookmarklets !

It is more often these days we need to look in the number in the website and dial the same number reach the service. Instead you can create a bookmarklet in your browser to send the number by selecting it to asterisk and connect your phone with the service provider with a select and click.

So nothing to paste or no wrong number dialling. Just Select and click.

Asterisk can be communicated through http interface, send an AMI originate command with the number you want to dial in with the format. It goes from there.

Wednesday, June 24, 2009

Asterisk How to Capture Events and Handle it with PHP easily, works with all 1.2, 1.4 & 1.6

PHP makes the life easily when it comes to string parsing. Just enjoy to handle the events from asterisk.

#!/usr/bin/php -q

ob_implicit_flush(false);

$socket = fsockopen("hostname or ip","port", $errornum, $errorstr);
if(!$socket) {
print "Couldn't open socket. Error #" . $errornum . ": " . $errorstr;
} else {
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: username\r\n");
fputs($socket, "Secret: password\r\n\r\n");
fputs($socket, "Action: Events\r\n");
fputs($socket, "EventMask: on\r\n\r\n");

fgets($socket); // Ignore the welcome message

$change = false;
$agentid = NULL;
$agentchannel = NULL;
$login = NULL;

while(true)
{
while(!feof($socket) )
{

$readbuf = "";
$resp = fread($socket,8192);
$readbuf .= $resp;
$allevents = split("\r\n\r\n",$readbuf);
foreach($allevents as $event)
{
$eventdetails = split("\r\n",$event);
$event_assoc = "";
foreach($eventdetails as $value ) {
$namevalue = split(": ",$value);
$event_assoc[$namevalue[0]] = $namevalue[1];
}
switch( $event_assoc['Event'] )
{
case 'Link': // Calls getting bridged
break;

default:
if( !empty($event_assoc['Event']) )
print_r($event_assoc);
}
}
fputs($socket, "Action: Ping\r\n\r\n");
usleep(1000000);
}

}

}

?>