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

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