This article was originally published on a website I had setup as an IT Contractor.  The original date will have been late 2016 / early 2017.

Recently I have been getting many unsolicited calls to my landline telephone.

I had seen various off the shelf call blockers but a lot of them seemed to lack flexibility.  So, I had a look into whether a Raspberry Pi could do this and thanks to the NCID Project it can.  Setting up NCID was fairly straightforward, what was a little more tricky was getting the correct hardware as the components I had laying around did not work.  There were also some specific settings for the UK which I had to set.  The following is a rough guide to setting this up, it assumes a general knowledge of the Raspberry Pi as well as an ability to read comments in config files etc etc.

Anything which is intended to be run via a command line shell is highlighted in maroon.  Run them at your own risk and if you are not sure what you are doing, stop and learn first.

 

Kit

  1. Raspberry Pi (mine is just a Pi 1-B)
  2. A US Robotics 5637 USB modem.  Others might work but the basic cheap one I tried first did not, or rather it detected the call but did not pick up the BT Caller ID.  I picked up a second hand USR5637 on ebay.  There are also potential issues with other devices should you want to play audio messages, you need a voice modem to do this which the USR5637 is.  I updated the firmware http://support.usr.com/support/product-template.asp?prod=5637
  3. A USB hub
    1. The modem draws about 350 mA which is more current than the USB on the Pi puts out by some margin.  A cheap USB hub I had did not give out enough power either.  You will likely get spurious errors/crashes or a “couldn’t open socket: connection refused”.
    2. I noticed the USB hub I had actually backfeeds the Pi (to the point where you can pull the plug in the Pi and it stays on).  This bypasses the fuse on the power-in of the Pi.  This obviously puts your Pi at risk but it also reduces power available on the hub, which makes it less likely to be able to reliably power the modem.
    3. I ended up getting a 7 Port USB Hub from Pi Hut which has been designed to not backfeed and to give out enough power for devices.  This new one has a 3A mains plug although I have not tested the output ports for actual output.  It is running the USR5637 fine though.

If anyone has any information on other hubs and modems which work I would be interested in hearing about it.

 

Setup the Raspberry Pi

  1. Install the operating system if you have not done so already.  I used Raspian 2016-05-07.
  2. I do the usual of setting a static IP, SSH, removing as much RAM from the GPU as possible then an update and upgrade using apt

 

NCID and its Pre-Reqs

sudo apt-get install gdebi

This installs a bunch of dependencies as well (~200MB) . . . it includes stuff like Gtk and Cairo and I would like to look into trimming all this down a bit (those are GUI libraries).

wget http://downloads.sourceforge.net/project/ncid/ncid/1.4/ncid_1.4-1_armhf.deb

wget http://downloads.sourceforge.net/project/ncid/ncid/1.4/ncid-client_1.4-2_all.deb

The above were the most recent versions at the time I did this.

sudo gdebi ncid_1.4-1_armhf.deb

  • You can then remove the downloaded file (rm ncid_1.4-1_armhf.deb)

sudo gdebi ncid-client_1.4-2_all.deb

  • You can them remove the downloaded file (rm ncid-client_1.4-2_all.deb)

sudo nano -w /etc/ncid/ncidd.conf

  • Uncomment the line which begins “set ttyport” and contains “Linux USB Modem”
  • Uncomment the line “set hangup = 3”
  • Uncomment the line “set announce = NotInService.rmd”
    1. Or whichever of the standard messages you prefer (still working on custom audio)
  • Ctrl+x to get out of nano (y to save changes)
  • There are settings here to bind to an actual address rather than localhost, should you want client and server on different Pi’s.  The client conf will have a target address as well.

sudo nano -w /etc/ncid/ncid.conf

  • Find “set Country” and change it to “UK”
  • Find “set AltDate” and change it to 1
    • This sets display dates to UK date formats

ncidd &

  • Start the server

ncid –no-gui

  • Start the client

Now call your land-line, it should show your number, or either WITHHELD or No Caller ID if you do not transmit your number.

 

Blocking

sudo nano -w /etc/ncid/ncidd.blacklist

  • By default it uses basic pattern matching although it can be set to use regex (http://ncid.sourceforge.net/man/ncidd.blacklist.5.html)
  • ^07777 123456 # My Mobile
    • The caller display shows a ‘-’ not a space, but a space is what seems to be required for pattern matching.  The ^ simply means match from the start, you could do ^07777 and it would block all 07777 numbers.
  • You can block names / codes as well like:
    • ^WITHHELD
    • ^No Caller ID

sudo nano -w /etc/ncid/ncidd.whitelist

 

Caveats

NCID does all its work between ring 1 and ring 2.  This means that your phone will ring once unless you have a handset which will “display only” on ring 1 before actually ringing on ring 2.

Message to caller

I am still working on this, I did get it working although only using some of the stock messages (an American “this number is no longer in service”).  I am looking into the audio formats to try and up the quality and play custom messages.

 

Regex

There is an option for “set regex” in ncidd.conf.  I have not played about with it yet and I do not know what if any performance issues there might be, especially on an older Pi like mine.  The basic matching works well enough for catching unknown numbers and specific numbers though (and I get calls from one number in particular all the time).  Regex could be good for filtering out non-valid UK numbers though, like the ones you get with fake Caller ID which look like UK numbers but are for example one digit short.

 

Socket Error / Connection Refused

I sometimes get this when launching the client, I am not sure if it is because I do not give the server enough time to start properly or if it is due to something else.  When I try and start the client again after killing it, then it always seems to go up.  This is also the error you get if the server has not detected the modem (like if you have power issues).

 

Other Things You Could Do

By capturing the output of NCID Client you could send yourself email alerts or otherwise log legit missed calls.