Diary of a geek

October 2006
Mon Tue Wed Thu Fri Sat Sun

Andrew Pollock


Other people's blogs


RSS feed

Contact me

JavaScript required

Thursday, 19 October 2006

Asterisk and MythTV integration

After much more work than was necessary, I managed to get Asterisk to blat on the TV the caller ID information of an incoming call. Next I need to see if I can pause the TV, and resume it when the call ends.

The MythTV side just needed to be configured to listen on the UDP notify port, the XML templates and whatnot were already there for it (I think installed by MythPhone), so all I had to do was get Asterisk to run this script when a call came in:


use Asterisk::AGI;
use IO::Socket;

# Set this to the broadcast address for your network
$netbroadcast = "";

$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();

my $num = $input{'callerid'};
my $name = $input{'calleridname'};
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$date = sprintf("%02d/%02d/%4d %d:%02d:%02d",$mday,$mon+1,$year+1900,$hour,$min,$sec);

$sock = IO::Socket::INET->new(PeerPort  => 6948,
                              PeerAddr  => $netbroadcast,
                              Proto     => udp,
                              Broadcast => 1 ) or die "Can't bind : $@\n";

print $sock <<EOT;
<?xml version="1.0"?>
<mythnotify version="1"><container name="notify_cid_info"><textarea name="notify_cid_line"><value>Unused</value></textarea>
<textarea name="notify_cid_name"><value>NAME: $name</value></textarea><textarea name="notify_cid_num"><value>NUM : $num</value>
</textarea><textarea name="notify_cid_dt"><value>$date</value></textarea></container></mythnotify>
close $sock;

That was accomplished by just adding an AGI(mythcid.agi) application call to one my existing extensions that handled incoming calls. Future enhancements will involve displaying who the caller wants to speak to after they've selected the appropriate response from the menu we give most callers.

The Asterisk::AGI Perl module was a bit hard to track down. I've made a 2 second (dh-make-perl) Debian package of it, available here. If I get sufficiently motivated, I'll consider cleaning it up and uploading it to Debian.

[09:07] [tech] [permalink]

The definition of frustration

Writing your first Asterisk AGI script, putting it in /var/lib/asterisk/agi-bin because that's where another package has put one, and all of the random documentation on the Internet refers to that location (even though it's in violation of the FHS to go sticking scripts there), and after a marathon debugging session, discovering that Debian's Asterisk package ships with astagidir set to /usr/share/asterisk/agi-bin (which it appears you need to create yourself).

[08:39] [tech] [permalink]