News:

On Tuesday September 6th the forum will be down for maintenance from 9:30 PM to 11:59 PM PDT

Main Menu

Possible to send incoming Caller ID to a PC for logging?

Started by sofakng, January 03, 2013, 09:38:46 AM

Previous topic - Next topic

sofakng

I use XBMC on my PC as a HTPC (Home Theater PC) that lets me play movies, TV shows, etc.

I'd like to "notify" XBMC of an incoming call with the caller ID and name.

Even if nobody has done this before, does anybody know if it's possible to have the OBi send a notification of some sort to a PC?  (i.e. writing a text file, making an HTTP call, etc, etc)

jeffml

I have XBMC set up to display Caller ID info.

- OBI sends syslog data to rsyslog (syslog server) on another machine
- rsyslog runs a program/script based on match of syslog data (OBi CID)
- script formats CID, does local name lookup for friendly name display and sends notification to XBMC machine.


sofakng

Very interesting!

Would you be willing to share your scripts?

I'm also thinking about using ncid (network caller id) and sniffing the SIP traffic (through port mirroring on my switch), but I don't think that would work for Google Voice since it uses XMPP and not SIP (?)

jeffml

Not going to share the scripts because they are beyond ugly but they aren't anything special.  A total of about 10 lines in bash shell script using about four unix commands/programs (cut, grep, echo, curl)

Example syslog:

[0]DAA CND 01020959,01638123456,,#001,,

You just need to isolate the phone number (in my case, 01638123456) and do what you want with it.

QBZappy

sofakng,

Brian Hasden (OBi forum member) has offered an app like this in the past. Looking at his site, it doesn't look like he has put up a current version to download, although I suspect that he has worked out the kinks since then. I remember that one of his goals was to broadcast CID over XBMC. Send him PM, he's friendly. Tell him QBZappy sent you.   :)

GrowlerID
http://riotouslabs.com/
Owner of the 1st OBi110/100 units in service in Canada & South America. 1st OBi202 on my street. 1st OBi1032 in Montreal.


infin8loop

Quote from: jeffml on January 03, 2013, 12:43:42 PM
Not going to share the scripts because they are beyond ugly but they aren't anything special.  A total of about 10 lines in bash shell script using about four unix commands/programs (cut, grep, echo, curl)

Example syslog:

[0]DAA CND 01020959,01638123456,,#001,,

You just need to isolate the phone number (in my case, 01638123456) and do what you want with it.

Oh come on. An ugly script has never stopped me from posting it. I haven't been openly mocked yet. Ok, maybe QBZappy has mocked me, but he doesn't count... he's Canadian. I'm sure more than a few have snickered though. And if it's not documented or commented well, all the better I say!
If it has regex in it, forgetaboutit. If this was Survivor, we'd have to vote you off the island.  ;D

Rube Goldberg is my hero.
"This has not only been fun, it's been a major expense." - Gallagher

DMcK

Hi,
I just started using an OBI202 with voip.ms.  So far it is exceeding my expectations.

It's disappointing people aren't sharing their scripts openly so we can all have better experiences. Especially when we use other peoples' software (e.g., xbmc) Oh, well.

Here's my crappy caller ID to xbmc and YAC Listener script!  It's not pretty, but it seems to work (with very little testing!) I hope somebody takes this and improves it!  You'll need a linux server for this to work. I'm using Ubuntu 12.04 and the following instructions are for that.

~/YourScript.sh:
#!/bin/bash
##############
## lockfile ##
##############
exec 9>/tmp/callerid-lockfile
if ! flock -n 9  ; then
  exit 1
fi
# this script now runs under the lock until 9 is closed. it will be closed automatically when the script ends.

####################
##  Configuration ##
####################
LOGLOCATION="/var/log/obi202.log"    # the location of your syslog log
IPADDRESSSTART="192.168.0."   # only the first 3 values and dots for your LAN IP Address
XBMCIPs=(116 115 112)    # the last value(s) of the ip address(es) of your xbmc devices(s)
XBMCPORT="8080"        # default port for xbmc webserver
XBMCPOPUPDURATION="7000"     # in msecs (i.e., 7000 = an xbmc popup for 7 seconds)
YACIPs=(234 190)      # the last value(s) of ip address(es) for computer you want YAC popups
YACPORT="10629"     # default port for YAC is 10629.

####################################
##   Extract string from the log  ##
####################################
sleep 0.1        # allow a bit of time for log messages to complete.
STRINGFROMLOG=$(tac $LOGLOCATION | grep -B 1 -m1 'Command: 1, 3, 0, 0, 4, 1086133200,' | tac)         # invert log to find first line before "Command: 1, 3, 0...". This is the last Caller ID entry.
STRINGFROMLOG=$(sed -n -e 's/^.*1086133200, //p' <<< $STRINGFROMLOG)         # Strip off everything after "1086133200, " to leave just the CID info.
DATE=${STRINGFROMLOG:0:15}
UNIXDATE=$(date --date "$DATE" +%s)
NOW=$(date +%s)
TIMEDIFF=$(($NOW-$UNIXDATE))
if [ "$TIMEDIFF" -gt "10" ]    # if the current date/time and the date/time from the log are more that 10s apart, then the log updated from something other than an incoming call. exit.
then exit
fi
NAME=$(sed "s/.*'\(.*\)'[^']*$/\1/" <<< $STRINGFROMLOG)    # strip out the name between the single quotes
NAMEFORCURL=${NAME// /%20}                        # curl command doesn't like spaces so use %20 instead
NUMBER=$(sed 's/.*\ //' <<< $STRINGFROMLOG)       # gets all characters after the last space (i.e., the number)

####################
##  XBMC Portion  ##
####################
MIDDLE='","message":"'
END='"\},"displaytime":'$XBMCPOPUPDURATION',"id":1\}'
for i in ${XBMCIPs[@]}; do
   START='http://'$IPADDRESSSTART${i}':'$XBMCPORT'/jsonrpc?request=\{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":\{"title":"'
   URL=$START$NAMEFORCURL$MIDDLE$NUMBER$END   # assemble the URL string for curl
   curl --request GET $URL    # send the notification request to xbmc
done

####################
##   YAC Portion  ##
####################
START="@CALL"
MIDDLE="~"
for i in ${YACIPs[@]}; do
   MESSAGE=$START$NAME$MIDDLE$NUMBER      # assemble the message string for netcat
   echo $MESSAGE| nc -w 1 $IPADDRESSSTART${i} $YACPORT       # send the message to the YAC Listeners
done

exit 0


Change the configuration section of the script as required. Enable the webserver (Settings>Services>Webserver>Allow control of XBMC via HTTP) in xbmc.  Install YAC on any computers you want Caller ID notification and put a YAC Listener shortcut in your start folder. If you have passwords set up in the xbmc webserver, you'll need to modify the START variable in the xbmc section accordingly (i.e., 'http://' becomes 'http://username:password@'.  

Make the script executable:
sudo chmod 777 ~/YourScript.sh

My syslog is going to /var/log/obi202.log. configure rsyslog to write the log file there:
sudo touch /var/log/obi202.log
sudo nano /etc/rsyslog.conf
->Add the following:
#
# Log from OBI202
#
local7.*    /var/log/obi202.log



Add the '-r" switch as shown below:
sudo nano /etc/default/rsyslog
->change the last line to:         RSYSLOGD_OPTIONS="-c5 -r"


I changed ownership of the file while testing. I think you'll need to also, but I'm not sure. It doesn't hurt:
sudo chown yourusername:yourusername /var/log/obi202.log

Rotate the log occasionally so it doesn't get too big:
sudo nano /etc/logrotate.d/obi202.log
->Add the following:
/var/log/obi202.log monthly
{
   rotate 4
   missingok
   notifyempty
   compress
   create }


restart rsyslog:
sudo service rsyslog restart

Change the ownership and permissions of the lockfile:
sudo chown yourusername:yourusername callerid-lockfile
sudo chmod 777 callerid-lockfile


I monitor the log file and launch the script using incron:
sudo apt-get install incron
sudo nano /etc/incron.allow
->Add this:    root
sudo incrontab -e
->Add this:   /var/log/obi202.log IN_MODIFY /bin/bash /home/yourusername/YourScript.sh


I think that's everything. With the exception of the script, much of that was from memory or some simple notes. So I hope I got it all.

Enjoy!

QBZappy

@DMcK

Thanks for sharing. Can you include your project with other 3rd party apps thread to group them and make it easier to find.

3rd party apps development for the OBi 110/100
http://www.obitalk.com/forum/index.php?topic=1648.0
Owner of the 1st OBi110/100 units in service in Canada & South America. 1st OBi202 on my street. 1st OBi1032 in Montreal.

DMcK

I've posted it there too now.  I've also added a few things to the script to make it a bit more functional and easier for others to use.