2009-10-20, 20:32
Just thought of posting to see if this interests anyone.
I have my media center in the basement and dont have phone in the basement all the time. I would like to get notified of phone calls when the phone rings so that I dont miss too many important calls while XBMC-ing
I had old USR 56k Sportster modem, so I put together a bunch of scripts to notify XBMC when the phone rings.
This assumes you have modem hooked up and working to /dev/ttyS1 or /dev/ttyS0.
Assumptions
Step 0. Attach your modem to your COM port and ensure you can connect to it. Also make sure your modem supports CallerID
Step 1. Install mgetty
mgetty is a program that you can configure to anwer the phone and present it a terminal.
Step 2. edit /etc/mgetty/mgetty.config, add the following code to the end of the file.
What this does it tell mgetty to answer the call in 2 rings. But before it does this it executes a script to check if can answer the call. This where we hook in and send a notification to xbmc. The init-chat parameters sets up the modem and enables fully formatted caller ID.
Step 3. Setup a BASH script to notify XBMC. I call my script xb-callerID and put it under /home/xbmc/bin/xb-callerid. Some of the functions inside this script like the url encoder uses perl, so you might need to add that your system, but my base xbmc already seemed to have perl installed.
Note the exit 1 is very important, as this return code is what mgetty uses to choose to answer the call or let it ring. An exit code of 1 tells mgetty to not answer the and letit ring.
Adjust the username/password and HOSTNAME to match your setup.
The code that actually notifies XBMC is
You can run this on its own first to make sure you can send notifications.
Step 4. Configure mgetty to start with system.
In /etc/event.d/ folder add a file called ttyS1
This will cause the OS to spawn a mgetty process at start up and keep it running.
Step 5. Reboot and test.
Reboot your box,
ensure you mgetty is running should be able to see it using a
Then call your phone line and you should see a nice notification popup on your XBMC screen!
Should see something cool like the screen shot with a pop-up.
Enjoy!
I have my media center in the basement and dont have phone in the basement all the time. I would like to get notified of phone calls when the phone rings so that I dont miss too many important calls while XBMC-ing
I had old USR 56k Sportster modem, so I put together a bunch of scripts to notify XBMC when the phone rings.
This assumes you have modem hooked up and working to /dev/ttyS1 or /dev/ttyS0.
Assumptions
- You are running Ubuntu 9.04
- You have XBMC up and running and have the Web Interface activated, such that the HTTP API can be accessed and used.
- You have a working modem hooked up to /dev/ttyS1 that supports Called ID and you phone line supports Caller ID
- You are not a complete linux noob and have some knowledge of how to edit files and make changes, understand file permissions, and what commands like "sudo" do.etc.
- You know how to trouble shoot your modem and send AT commands to it etc.
- Keep a backup of files as you go along, so you can roll back if you break something!
Step 0. Attach your modem to your COM port and ensure you can connect to it. Also make sure your modem supports CallerID
Code:
AT#CID? should return 0,1,2 which means your modem indeed supports Caller ID
Step 1. Install mgetty
Code:
sudo apt-get install curl mgetty
mgetty is a program that you can configure to anwer the phone and present it a terminal.
Step 2. edit /etc/mgetty/mgetty.config, add the following code to the end of the file.
Code:
port ttyS1
rings 2
init-chat "" AT#CID=1
cnd-program /home/xbmc/bin/xb-callerid
What this does it tell mgetty to answer the call in 2 rings. But before it does this it executes a script to check if can answer the call. This where we hook in and send a notification to xbmc. The init-chat parameters sets up the modem and enables fully formatted caller ID.
Step 3. Setup a BASH script to notify XBMC. I call my script xb-callerID and put it under /home/xbmc/bin/xb-callerid. Some of the functions inside this script like the url encoder uses perl, so you might need to add that your system, but my base xbmc already seemed to have perl installed.
Quote:#!/bin/bash
NAME="N/A"
NUMBER="N/A"
toLower() {
echo $1 | tr "[:upper:]" "[:lower:]"
}
capitalize() {
for i in $1; do B=`echo -n "${i:0:1}" | tr "[:lower:]" "[:upper:]"`; echo -n "${B}${i:1} "; done
}
urlencode() {
echo $1 | perl -MURI::Escape -lne 'print uri_escape($_)'
}
TITLE="Incoming Phone Call"
NAME=`toLower "${3}"`
NAME=`capitalize "$NAME"`
NUMBER=`urlencode "$2"`
NAME=`urlencode "$NAME"`
LENGTH=`expr length $NAME`
TITLE=`urlencode "$TITLE"`
if [ $LENGTH -le 1 ] ; then
INFO=${NUMBER}
else
INFO="${NAME}%0A${NUMBER}"
fi
echo `date` $* >> /var/log/callerid.log
curl -get "http://user%3Apass@XBMCHOST:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(${TITLE},${INFO},60000))" > /dev/null 2&>1
exit 1;
Note the exit 1 is very important, as this return code is what mgetty uses to choose to answer the call or let it ring. An exit code of 1 tells mgetty to not answer the and letit ring.
Adjust the username/password and HOSTNAME to match your setup.
The code that actually notifies XBMC is
Code:
curl -get "http://username: password@XBMCHOST:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(TestTitle,TestINFO,60000))" > /dev/null 2&>1
You can run this on its own first to make sure you can send notifications.
Step 4. Configure mgetty to start with system.
In /etc/event.d/ folder add a file called ttyS1
Code:
start on stopped rc2
start on stopped rc3
start on stopped rc4
start on stopped rc5
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
respawn
exec /sbin/mgetty /dev/ttyS1
This will cause the OS to spawn a mgetty process at start up and keep it running.
Step 5. Reboot and test.
Reboot your box,
ensure you mgetty is running should be able to see it using a
Code:
ps aux | grep mgetty
Then call your phone line and you should see a nice notification popup on your XBMC screen!
Should see something cool like the screen shot with a pop-up.
Enjoy!