Caller ID info from a modem

When things finally click in the brain and work on the machine, happy things happen!

I keep adding to my home automation server. This time I got an old ISA modem. Found it in the piles of cards in my chicken coop (which I use for computer storage now). And I got caller ID working on it.

Setting Up the Modem

If your modem already works, skip this!
Had to get the modem detected and IRQs all set right. Yup, it's that old! Found a free IRQ by running

cat /proc/interrupts

and set the modem jumper as such.

To detect the modem in Linux, I used wvdialconf. For newer (PCI) modems, I suggest using ScanModem

sudo apt-get install wvdial

And then run
sudo wvdialconf

If all works, it should save your modem's configuration to
cat /etc/wvdial.conf

My modem was found on /dev/ttyS1

Setting up Mgetty

Now the fun part. I'm using Mgetty to get the caller ID info. (install mgetty-voice for vgetty - if you want to create an answering machine)

sudo apt-get install mgetty

Setup mgetty.config

sudo nano /etc/mgetty/mgetty.config

Here's my mgetty.conf (change port to the serial port your modem is attached to)
debug 8 # Log everything to /var/log/mgetty/mg_ttyS1.log
rings 2 # Answer phone after 2 rings - Need 2 because caller id info is sent between 1st and 2nd ring
speed 38400 # Buad rate to run modem at

port ttyS1 # Serial port of modem
  init-chat "" AT#CID=1 OK # Turn on Caller ID
  cnd-program /home/kliewer/homeauto/callerid/run_on_ring.sh # Script to run after 2 rings

Here's what happens - After the phone rings twice, it calls the cnd-program script and passes 3 arguments - Serial Port, Phone Number, and Caller ID Name. If the script returns status 0, mgetty will pick up the call. If the script returns 1, mgetty will not answer, and the phone will keep ringing. I've set my script to always return 1, because I do not want mgetty to answer my phone!

Mgetty doesn't run automatically, so we'll use ustart to do so:

sudo nano /etc/event.d/mgetty

Put in the following contents. This will start mgetty on the specified runlevels, and restart mgetty if it is ever killed.
Change /dev/ttyS1 to your modem!
start on startup

start on runlevel 2
start on runlevel 3
start on runlevel 4
start on runlevel 5

respawn
exec /sbin/mgetty /dev/ttyS1

And now you can start mgetty:
sudo start mgetty

Mgetty should now be running and listening for incoming phone calls. It will run the script you specified in mgetty.config under cnd-program after 2 rings.
Here's my example run_on_ring.sh:

#!/bin/sh
NUMBER="$2"
NAME="$3"

# Do here whatever you want with the caller ID info
# Say the info out loud (must have festival installed)
echo "Incoming call from $NAME. $NUMBER" | festival --tts

# Or IM it over the LAN to clients using Bonjour
echo '<message type="chat"><body>Call From '$NAME'\nPhone Number: '$NUMBER'</body></message> ^] quit' | telnet 192.168.10.10 5298
# etc... :D

exit 1 # So mgetty will NOT answer the phone!

There you go! Hope it works!

Comments

Not working under Kubuntu

Not working under Kubuntu 9.10

The above would not work for me under Kubuntu 9.10. Here is what I had to change:

1. for whatever the reason, I could not get upstart to work. So I stuck the initscript in /etc/init/mgetty.conf:

description "start and stop mgetty"
version "0.1"

start on runlevel [2345]
stop on runlevel [!2345]

respawn

exec /sbin/mgetty /dev/ttyUSB0

2. My version of mgetty (1.1.36-Jun15) would not parse out comments at the end of the line. Had to do it like this or it would not work:

set the global debug level to "4" (default from policy.h)
# numer of rings before answer
# tried two but sometimes lost the name in the CID
rings 3

# access the modem(s) with 115200 bps
speed 115200

# config for modem on ttyUSB0
port ttyUSB0
    # configure the modem for caller id
    init-chat "" AT#CID=1 OK
    # run this upon receiving caller id
    cnd-program /usr/local/bin/runonring.sh

I tried two rings, but most of the time lost the name string in the caller id. Three worked all the time.

BTW the modem is a USR Courier V.Everything x2 v.90 connected via a generic usb serial adapter. I bought it at a thrift store for $1.

I hope this helps someone else. There is little fresh info on anything to do with modems these days.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options