My Doc's Got No Nodes

Looking for a punchline since 2002

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 type of modem I used below.

TRIXES USB 56K External Dial Up Voice Fax Data Modem Windows 7

Comments

Hi Mark, Could your project be modded to show ca…

Anonymous - Feb 03, 2013

Hi Mark,

Could your project be modded to show caller ID over a network?


Maybe, but if networked caller ID is the only feat…

Mark Lambert - Feb 03, 2013

Maybe, but if networked caller ID is the only feature you need, you could try getting ncidd working, from http://ncid.sourceforge.net/ncid/ncid.html


Thanks for the reply, I have the same modem as the…

Anonymous - Feb 03, 2013

Thanks for the reply, I have the same modem as the one listed above and am I correct in thinking this should work out the box with the Pi or if not do you have a more detailed guide showing how to get it working? i have played with NCID on Ubuntu but I could not get it working.


Yes, it connected without drivers on raspbian. The…

Mark Lambert - Feb 03, 2013

Yes, it connected without drivers on raspbian. The only tricky bit was finding the /dev/... entry, which I did with the lsusb and ls commands in the post.
But to get it set to UK standards, I connected it to a Windows box and set the modem properties to UK, then put it back on the Pi.


NCID 0.86 (released Mar 24 2013) now has support f…

Anonymous - Mar 25, 2013

NCID 0.86 (released Mar 24 2013) now has support for Raspberry Pi. http://ncid.sourceforge.net/ncid/INSTALL-Raspbian.txt


That's great. Thanks for letting me know!

Mark Lambert - Mar 25, 2013

That's great. Thanks for letting me know!


No problem. I was looking for the same type of so…

Anonymous - Mar 27, 2013

No problem. I was looking for the same type of solution as you were and ran across your blog where I learned the RPi could talk with a modem. Aside from the initial challenges of setting up ncid, it is very stable on the RPi for the couple of weeks I have been running it.

After fitting an IDE SSD in my aging laptop, I found that although Windows 7 (and Windows 8 Preview) would install to it, they wouldn’t boot – instead claiming that there was a disk error.

After some experimentation, I found that the Super Grub2 Disk, booted from a CD, could start Windows via its “Detect any other operating system” option.

But booting from a CD every time sort of defeats the point of a faster drive, so I tried to get grub to boot into Windows from the hard drive. It worked – (almost every time), and here’s how.

  1. Get an Ubuntu Live disk.

  2. Boot into Ubuntu and repartition the disk using gparted. Create one ext2 partition of 256Mb (aligned to none) and set its flags to bootable. Create a second partition for NTFS that fills the rest of the disk.

  3. From the terminal, start a su shell and mount the ext2 partition as /boot, then install grub

    sudo –i
    mount /dev/sda1 /boot
    grub-install /dev/sda
    
  4. Install windows to the second partition, you might need the Super Grub2 disk to help it through the reboots.

  5. Boot into Ubuntu again, mount the boot partition, and find the volume info for the NTFS partition using the blkid command.

  6. Create a /boot/grub/grub.cfg that looks like this

    set default=0
    set timeout=0
    
    menuentry "Windows 7" --class windows --class os {
        insmod part_msdos
        insmod ntfs
        insmod ntldr
        set root='(hd0,msdos2)'
        search --no-floppy --fs-uuid --set=root *BIGHEXNUMBERFROMBLKID*
        ntldr ($root)/bootmgr
    }
    

If you’ve got a phone with a Micro USB power connector (say, for instance, an HTC Android model) and you occasionally find yourself running out of battery power, here’s something that I’ve found to work really well.

A 4xAA to Micro USB battery pack. I’ve stocked mine with Duracell ACCU / Stay charged NiMH batteries so they don’t self-discharge while they’re in waiting.

It’s not a fast charge, but if you can cope with having the phone connected to the charger in your bag / jacket pocket it will get your phone battery back into the green.

(Amazon associate) links:

  • Battery Extender Charger for Motorola Atrix, Palm Pre 2, HTC Desire HD, Samsung Google Nexus S (no longer available)
  • Duracell AA 2000 mAh Stay Charged Batteries - 4 Pack (now 2500mAh)

If you’re looking to use a 16-bit grayscale (Gray16) BitmapSource as an input to a Pixel Shader BitmapEffect – say for brightness / contrast adjustment, you’re likely to hit a problem. It seems that the 16-bit values are knocked down to 8-bit precision by the time you get the float values in the pixel shader (so a range from 0 to 1, but only 256 distinct values). But you can instead pack the 16 bits into two of the 8-bit colour channels of an RGB image (an approach suggested by ken_s in the msdn thread Debugging Pixel Shaders for WPF effects. Create a Bgr32 format WriteableBitmap, and use WritePixels to copy the 16-bit values from a ushort array, with one blank ushort between each pixel. This way the high byte goes into the green channel, the low byte into the blue, and the red and unused channels get zeroed. In your pixel shader code, you can reconstruct the 16-bit value from the float values passed for green and blue.

float4 main(float2 img : TEXCOORD) : COLOR
{
 float4 gb = tex2D(input, img);
  int high = gb.g * 65280; // Fix by Rick Burke (see comments)
 int low = gb.b * 255;
 int grayVal = high + low;

 // ... 
 // Calculate a 0-1 grayscale value ‘processed’ from grayVal 
 // ... 

 float4 result; 
 result.a = 1; 
 result.r = processed; 
 result.g = processed; 
 result.b = processed; 
 return result; 
}

(Or how to store 4.0 / 5.1 at 96khz 24-bit on a DVD-R, in a way that plays back properly over HDMI from a Sony BDP-S370) Yes, another exciting audio howto :-) but if I don’t record it, I won’t be remember (or be willing to rediscover) how. If starting from one-track-per-file, use foobar2000 to create a single wav file and a cue sheet. The key here is to multi-select the files, and do a convert to wav with the destination type set to “Generate multi-track files”. This will produce the cue sheet. Next find the duration of the combined wav file, and use ffmpeg from the command prompt to create a still video file:

ffmpeg.exe -loop 1 –i somepicture.png -c:v libx264 -s hd720 -t hh:mm:ss.mmm video.mkv

Then use multiavchd, add video.mkv and click on the entry under “compilation”. Add the audio, then edit the chapters and fill in the values from the cue sheet. On the Author tab I also changed TV system to PAL. Hit Start, and choose AVCHD (Strict) under the Optical Media section. From the command prompt multiavchd folder, Use oscdimg to create a UDF disc image of the AVCHD folder

oscdimg -u2 AVCHD myaudiodisc.iso

Burn myaudiodisc.iso to DVD-R. If I let the disc play automatically on loading, the receiver claimed it was being sent 88.2Khz sound. I had to select “AVCHD disc” from the blu-ray player menus to get 96khz.

Previous 3 of 8 Next