or
How to Automatically Hang Up on Telesales Using .net, a Modem and Caller ID
or
Using Serial Ports from Mono on Raspbian
Since we seem to get a never-ending series of calls from telesales, market research and “your ISP”, I decided to start adding their caller IDs to our cordless phone book as “Scam n”.
The problem with this plan was that you still had to head to the phone to see that it wasn’t someone you wanted to bother with. If only there was something that could read a caller ID and automatically pick up the phone and hang up.
Like a modem.
Connected to a Raspberry Pi.
So I bought a cheap USB modem from Amazon, and wrote something in C# to check incoming CLID against a blacklist. I tested it on a Windows laptop, and then installed Mono on the Raspberry Pi. Watched it do nothing. Then I wrote it again. Twice.
1. Getting the modem to work
One important step was to tell the modem which country it was in, I did this via the properties page on the Windows laptop. Without this stage, it didn’t recognise the caller id information coming along with the calls.
The name of the port can be found on the device properties page in Windows, or on Raspbian / Debian / Ubuntu / whatever-linux by running
lsusb
And finding the entry for the modem
Bus 001 Device 007: ID 0572:1329 Conexant Systems (Rockwell), Inc.
And then finding the symlink to that device, of the form /dev/tty…
ls -l `find /dev -name '*Conexant*'`
(there’s backqoutes and single quotes in there, not smart quotes gone nuts)
2. Getting Mono on the Raspberry Pi
sudo apt-get install mono-complete
wait.
3. Using Serial Ports in Mono
Forget the DataReceived event. Spin up threads for the reading and writing from the serial ports.
4. TimeSpan in Mono 2.10.8.1 on Raspbian 3.2.27+ #250 PREEMPT
Forget it. Use an int for milliseconds. The following code
Console.WriteLine(TimeSpan.FromSeconds(1));
Produces
00:00:00
5. The source code
It’s quick and dirty, and it’s available on bitbucket.
6. Get your own
You can get a Raspberry Pi here, and there’s an Amazon ad for the modem I used below.
TRIXES USB 56K External Dial Up Voice Fax Data Modem Windows 7