Monday, December 31, 2007

Quick and Easy Caller ID on MythTV

I have resisted the urge to display caller id on my MythTV as somewhat obvious. I’m always looking for ways to demonstrate the freedom which comes from using open source software, but I prefer the zesty freshness of an original idea rather than anything that’s been done, redone, and done again. My wife, however, thought that Myth caller id sounded like a great idea and asked me to set it up. What follows is how I did this with the least possible effort.


I already have a couple Custom-Apps which handle direct inward dialing on my inbound routes, so sending caller id to my MythTV box was as simple as adding one line to each Custom-App in extensions_custom.conf:

exten => s,4,System(/bin/echo "Caller: ${CALLERID(name)} ${CALLERID(number)}" | /usr/bin/nc -w 3 myth.example.com 1234)

On the MythTV side I decided to use xosd rather than mythosd because the latter will only work when you are watching live TV or recordings. I created a simple wrapper script called osd.sh:

#!/bin/sh
DISPLAY=:0.0
FONT="-xos4-terminus-*-*-*-*-32-*-*-*-*-*-*-*"
osd_cat --font=$FONT --align=centre --shadow=2 --color=SeaGreen –delay=15


At this point I have the PBX sending caller id to MythTV and osd_cat to display the data on screen, but I need a simple way to catch the data on port 1234 and feed it to my osd.sh script. I did this with one command:

micro_inetd 1234 ./osd.sh &

Micro_inetd is a nice replacement for inetd, xinetd, etc. if, as here, only one service needs to be managed. I set this to always start with xfce4-autostart-editor which naturally only works with the Xfce 4 desktop environment. Gnome, KDE, and other desktops have their own session managers.

Of course, now that we have caller id on the TV, I'll need to create a caller id lookup to compensate for the wretched state of telco support; fortunately I can put that off until next year :)

Update: change osd.sh to format phone numbers

#!/bin/sh
DISPLAY=:0.0
FONT="-xos4-terminus-*-*-*-*-32-*-*-*-*-*-*-*"
cid=`cat | perl -pe 's/(1?\d{3})(\d{3})(\d{4})/$1.$2.$3/'`
echo "$cid" | osd_cat --font=$FONT --align=centre --shadow=2 \
--color=SeaGreen --delay=15

No comments:

Post a Comment