[LINUX] HOW-TO get Caller ID working with XBMC for Linux and a analog modem
#1
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
  • 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!

Image

Should see something cool like the screen shot with a pop-up.


Enjoy!
Reply
#2
I'm not a linux guy but I got this old script working awhile back....http://forum.xbmc.org/showthread.php?tid...ght=caller
Reply
#3
Nice, I guess YAC is windows software.

This is just a 100% Linux solution. That does't need any Widows stuff to get this working.
Reply
#4
Nice! I'll have to stop by an old parts store and grab me a modem.

I do miss this as I have it on my cable box
Reply
#5
Yeah, very nice.
Would be great to have it for mobile phones via bluetooth as well... Smile
Reply
#6
olympia Wrote:Yeah, very nice.
Would be great to have it for mobile phones via bluetooth as well... Smile

I had my cellphone doing this over bluetooth until I upgraded cell phones albeit I was running it on a mac not linux
Reply
#7
drivesoslow Wrote:I had my cellphone doing this over bluetooth until I upgraded cell phones albeit I was running it on a mac not linux

good idea will see if can hack something up.
Reply
#8
I am running this on debian and get the following error:


expr: syntax error
./xb-callerid: line 26: [: -le: unary operator expected
יונתן בן-חיים
Reply
#9
nokdim Wrote:I am running this on debian and get the following error:


expr: syntax error
./xb-callerid: line 26: [: -le: unary operator expected


Assuming you are testing it standalone, you need to call with three arguments, a name and number maybe that is it.

./xb-callerID ttyS0 SOMENAME 5555555555
Reply
#10
Does this actually answer the phone or just passively get the caller id information?

I want caller-id information but still have the answering machine pickup, etc.

Also - does anybody have any suggestions on a very cheap, low-profile, PCI, linux compatible modem? Smile
Reply
#11
(2011-06-10, 16:49)SofaKng Wrote: Does this actually answer the phone or just passively get the caller id information?

I want caller-id information but still have the answering machine pickup, etc.

Also - does anybody have any suggestions on a very cheap, low-profile, PCI, linux compatible modem? Smile

this just gets the callerID and the passes the ring onto the phone or the answer machine.
Reply
#12
(2011-06-10, 16:49)SofaKng Wrote: Does this actually answer the phone or just passively get the caller id information?

I want caller-id information but still have the answering machine pickup, etc.

Also - does anybody have any suggestions on a very cheap, low-profile, PCI, linux compatible modem? Smile

I used this one on Ubuntu and it worked fine (note, it's USB, not PCI): http://www.amazon.com/gp/product/B005GQM...UTF8&psc=1
Reply
#13
Also, in case it's useful for anyone, here's some python code I wrote to do CallerID notification on Frodo. I haven't used it in a while, but it worked last time I tried it.

Code:
#!/usr/bin/python
import sys
import urllib
import re
from string import capwords

user=urllib.quote("xbmc")
password=urllib.quote("<redacted>")
host=urllib.quote("<host>:<port>")
title=urllib.quote("Incoming Phone Call")
phone_icon=urllib.quote("/home/xbmc/bin/phone.png")
length=20000
filename="/home/xbmc/bin/xbmc_cid.dat"

def get_local_cid():
    try:
        local_cid={}
        f=open(filename)
        
        for line in f:
            num,name = line.split(":",1)
            local_cid[num.strip()]=name.strip()
        return local_cid
    except:
        return {}
    
def main(argv=None):
    if argv is None:
        argv=sys.argv
    
    caller_num="none"
    caller_name=""
    if len(argv)>=3:
        caller_num = argv[2].strip()

    # strip off the "1" if in front of the area code
    if len(caller_num)==11:
        caller_num=caller_num[1:]
    
    local_cid=get_local_cid()
    if (caller_num in local_cid):
        caller_name=local_cid[caller_num]
    elif len(argv)>=4:
        caller_name = argv[3].strip()
      
    match=re.compile("\s").search(caller_name)
    if match:
        caller_name=caller_name.lower()
        caller_name=capwords(caller_name)
    
    if len(caller_num)==10:
        caller_num="("+caller_num[0:3]+") "+caller_num[3:6]+"-"+caller_num[6:]
    elif len(caller_num)==7:
        caller_num=caller_num[0:3]+"-"+caller_num[3:]
        
    if caller_name == "" and caller_num == "none":        
        message="Unknown"
    else:
        message=caller_name
        if caller_name != "" and caller_num !="none":
            message=message+" -- "
    
        if caller_num != "none":
            message=message+caller_num
        
    
    #print message
    
    message=urllib.quote(message)
        
    #url="http://"+user+":"+password+"@"+host+"/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification("+title+","+message+","+str(length)+","+phone_icon+"))"
    url="http://"+user+":"+password+"@"+host+'/jsonrpc?request={"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"'+title+'","message":"'+message+'","displaytime":'+str(length)+',"image":"'+phone_icon+'"},"id":1}'
    
    #print url
    
    urllib.urlopen(url)
    
    return 1
    
if __name__ == '__main__':
    sys.exit(main(argv=sys.argv))

It allows for a side file (pointed to by "filename") you can provide that associates phone numbers with names, like so:

Code:
9995551234: Name1
9995551235: Name2
Reply
#14
I couldn't get it to work with mgetty correctly (mgetty's fault or mine) but because of the age, the curl line won't work anymore anyway.

Here is an updated curl line, hope it saves someone some time.
Code:
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":${TITLE},"message":${INFO}}}' http://xbmc:[email protected]:8080/jsonrpc > /dev/null 2&>1


and here is a simple test to show you have Kodi setup correctly

Code:
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"Alert Banner","message":"Hello World"}}' http://xbmc:[email protected]:8080/jsonrpc
Using a NUC7PJYHN and a 2820FYKH0 Intel NUC running LibreELEC, and two FireTVs.:)
Reply
#15
Is anyone still following/interested in this thread? I've wondered if there is any way to increase the size of the notification area? In my case I'm (still) using the confluence skin on Kodi 17.6. If I try to POST a longer message, the notification area scrolls instead of adjusting in size (width) and if I want to include an image, the image is scaled to fit the vertical space allocated for Kodi notifications (icon size). I'd like to customize the notification area to include a full size image and perhaps specifiy a font size for the message.  While looking for information on this, I came across another thread where a Kodi user was wanting to send an image captured from his front door camera as a notification. Can't find that post now, but is there a function to create a custom popup window, place it where you want and size it how you want, with content that you specify?
Reply

Logout Mark Read Team Forum Stats Members Help
[LINUX] HOW-TO get Caller ID working with XBMC for Linux and a analog modem0