Network Caller ID (NCID)

From MythTV Official Wiki
Jump to: navigation, search

Time.png Outdated: This script no longer works with the in-development version, 0.25.

Caller ID

Caller ID is defined as "The service that allows someone being called to see the caller's name and phone number." MythTV does not come configured with the ability to display Caller ID information, but with the right tools this can be made to work.

Displaying Arbitrary Text On The MythTV Screen

As part of the entire MythTV bundle, there is a small script called mythtvosd which allows for displaying any kind of text on the screen. Note that this only works when LiveTV, Recordings, or Videos are being displayed; it will not display at any other time.

MythTV Compatibility

As of 0.24, MythTV no longer supports the mythosd command, thus breaking NCID support. This has been replaced with mythmessage in the 0.25 HEAD development branch and will require some updates to this documentation in order for an NCID implementation to work.

Hardware

Getting the right hardware can be a pain. Although it initially seems appealing to use an internal modem with caller-id support, the problem is that the PCI modems are near brainless. They rely on software to do most of the work, and that software, in most cases, hasn't been ported over to Linux. I had some luck with an older PCI card under i386-based linux, but it wouldn't work under x86-64. You can try using an external modem, but, the easiest solution is to get your hands on a NetCallerID box which simply plugs in to the system's serial port and in to the phone line.

As of February 2008, they can be obtained from: [discountsales.com] for $29.99US (price recently increased). You may also be able to find them on [eBay].

Believe me, although the desire is to save money, the few dollars that you try to save by using another system (internal PCI card, external modem, etc) just aren't worth it.

USB modems based on the Conexant CX93010 also seem to work fine with the cdc-acm driver from a recent Linux kernel and a small [patch]. Note: recent versions of this modem no longer work: http://sandeen.net/wordpress/computers/a-hardware-usb-modem-for-linux/

Network Caller ID (NCID)

Network Caller ID is a freeware package that can be obtained from SourceForge. It contains both the client and server package. Configuring the server side of the package is outside the scope of this document, but some notes have been included below. This document focuses on the client configuration and its integration with MythTV.

Download the source for NCID and built it on each of the Frontend systems that you have. If they are all the same architecture, then you can just build it on one and copy the tar file over to the others. If you are running an RPM based distribution (like Fedora), simply use the RPMs available on the Sourceforge project page and install it on each of the clients.

The NCID Server on a MythTV Backend

While the installation of the NCID server is not directly MythTV related, it is necessary to cover some of the basics in order to get it working with the clients. It is possible to run the NCID server on a variety of hosts (I had it running on my Tivo for a while). The important part is configuring the clients to point to the master NCID server. It is not unusual, though, to utilize the mythtv system for this purpose.

If you use the RPM method of installation, you will need to enable the server daemon and disable the client daemon on startup. Although this is the default, it is best to make sure.

#> chkconfig --level 345 ncidd on
#> chkconfig --level 345 ncid off


Within /etc/ncid/ncidd.conf, be sure to configure the CallerID device accordingly. For example, if the NetCallerID unit is to be used, it connects to the computer via the serial port. A snippet from the configuration file might look like this:

#####################
# TTY Configuration #
#####################

# The default tty port: /dev/modem
# set ttyport = /dev/cu.modem # Macintosh OS X
set ttyport = /dev/ttyS0

# The default tty port speed: 19200
# The tty speed can be one of: 38400, 19200, 9600, 4800
set ttyspeed = 4800 # NetCallerID port speed

# Ignore tty control signals for internal modems and 3 wire serial cables
#   Disable tty control signals: ttyclocal = 1
#   Enable tty control signals: ttyclocal = 0 (default)
# set ttyclocal = 1

# The lockfile name is generated automatically
# If tty port is /dev/modem, lockfile is: /var/lock/LCK..modem
# set lockfile = /var/lock/LCK..ttyS0

#######################
# Serial or No Serial #
#######################

# Require a serial device for startup.  This is useful if you are
# using a network based plugin
#  network: noserial = 1 (do not try to initialize a serial port)
#  serial: noserial = 0 (default - Look for a serial port)
set noserial = 0

#####################
# Modem or No Modem #
#####################

# Obtain CallerID from a CID device or a modem
#  device: nomodem = 1 (do not send AT commands)
#  modem: nomodem = 0 (default - send AT commands)
set nomodem = 1

Or to use network packet sniffing, only the following lines need to be updated (uncommented out) in /etc/ncid/ncidd.conf:

set nomodem = 1
set noserial = 1

When attempting to follow the installation instructions at SourceForge on a Gentoo system it was noticed that the following had to be done to enable normal startup (Note: I am using NCID via VOIP, so I am using sip2ncid and ncidd): Created /etc/init.d/sip2ncid

#!/sbin/runscript

start() {
        ebegin "Starting sip2ncid"
        start-stop-daemon --start --quiet --exec /usr/sbin/sip2ncid
        eend $?
}

stop() {
        ebegin "Stopping sip2ncid"
        start-stop-daemon --stop --quiet --exec /usr/sbin/sip2ncid
        eend $?
}

Created /etc/init.d/ncidd

#!/sbin/runscript

start() {
        ebegin "Starting ncidd"
        start-stop-daemon --start --quiet --exec /usr/sbin/ncidd
        eend $?
}

stop() {
        ebegin "Stopping ncidd"
        start-stop-daemon --stop --quiet --exec /usr/sbin/ncidd
        eend $?
}

Instructed the system to start these services at boot time

rc-update add ncidd default
rc-update add sip2ncid dedault

The NCID Client on a MythTV Frontend

If you use the RPM method of installation, you will need to disable the server daemon and enable the client daemon on startup. For some reason, the authors have the server daemon automatically enabled and the client daemon automatically disabled.

#> chkconfig --level 345 ncidd off
#> chkconfig --level 345 ncid on


When manually compiling and installing NCID v0.72 on a Gentoo system, none of the steps below regarding patching are needed.


Patching the Startup Script

The other catch is that, although there is an /etc/ncid/ncid.conf file, that file appears to be nothing more than a place holder under the RPM distribution. You need to edit /etc/init.d/ncid in order for the client to do what we want it to:

#!/bin/sh
#
# ncid          Start/Stop Network Caller ID client
#
# chkconfig: 2345 96 05
# description: the ncid client sends the CID to an external program

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

RETVAL=0
prog="ncid"
shell="tclsh"
extprog="ncid-mythtv"
opts="--no-gui -r 0 -C -P $extprog"
...

As seen above, the "extprog" has been set to "ncid-mythtv". NCID has a plug-in to talk to mythtv via mythtvosd. Save the updated init.d file.

Patching the Plugin

As of NCID 0.68, this patch has been integrated in to the source, so this step can safely be skipped.

The only other piece is to actually update the plugin "ncid-mythtv". At some point in time, the option "--template" became a required option to "mythtvosd" and the "ncid-mythtv" plugin was not updated to reflect this new requirement.

With that said, edit /usr/share/ncid/ncid-mythtv and make the code at the end of the file look like:

...
if [ -n "$CIDNMBR" ]
then
    # Display Caller ID information
    mythtvosd --template="cid" \
              --caller_name="$CIDNAME" \
              --caller_number="$CIDNMBR" \
              --caller_date="$CIDDATE" \
              --caller_time="$CIDTIME"
else
    # Display Message
    mythtvosd --template="alert" --alert_text="$CIDNAME"
fi

exit 0

Configuring the Client

The last step is to configure the client such that it knows where the server is. Thankfully, this is pretty easy just by editing the file /etc/ncid/ncid.conf. A lot of the options in that file are overridden via the integration in to mythtv or they just do not have any bearing in this configuration. The main ones to look for are the host and the port, making sure that they match with that of the server:

...
# Set Host to the NCID server address
# Host defaults to 127.0.0.1
set Host        192.168.0.100
# The NCID port default is 3333
set Port        3333
...

In lieu of using the steps mentioned under "patching" above, all configuration changes can be made in /etc/ncid/ncid.conf. The below example indicates how to update this file:

# Header text in /usr/share/ncid/ncid-mythtv provided an example of command line arguments
#  which can be used when using ncid-mythtv.  These command line arguments can then be
#  mapped to the below options in /etc/ncid/ncid.conf.
#
#  Example in /usr/share/ncid/ncid-mythtv is below 
#  "ncid --no-gui --message --call-prog --program ncid-mythtv"
set EXTPROG     ncid-mythtv
set Host        127.0.0.1 # set to 127.0.0.1 since ncidd running on the same machine in this case
set NoGUI       1
set Callprog    1
set MsgFlag     1

Start the Client

Start the daemon:

#> /etc/init.d/ncid start

or

#> service ncid start

And, with that, your MythTV FrontEnd will display incoming caller id information on the screen any time you are watching LiveTV or watching a Recording, all without having a phone line run to the box. It will not display information when you are in the menus, watching a DVD Video in MythVideo, or at any other time.

Note: At this time, the process does not detach from the current tty. Starting ncid by hand will cause your session to hang when you attempt to log out. This is not an issue when NCID is configured to automatically start up upon boot up.

Asterisk Based PBXs

The above can be used with asterisk based systems (PIAF and FreePBX). One needs to ensure that the port setting for ncid is updated for the extension's port address in asterisk. In addition, one can use a more complete solution using xyac and asterisk functionality to display callerid information no matter if your frontend is displaying video or on a menu. [mythtdora] and [voip-info.org] are references that can be used. The mythdora site was used by this author.