Asterisk and UK Caller ID
Getting it to work with a TDM400 for incoming call from BT line and internal analogue phone on UK phones
To get callerid to work with the TDM400 you have to add a few options to the zapata.conf, These are,
; in the global section
usecallerid=yes
cidsignalling=v23 ; Added for UK CLI detection
cidstart=polarity ; Added for UK CLI detection
For your incoming BT line connected to an FXO module (red)
signalling=fxs_ks
callerid=asreceived ; propagate the CID received from BT
for your internal analogue phone lines connected to an FSX module (green)
signalling=fxo_ks
sendcalleridafter=2 ; the hidden option given by Slav from Digium
callerid="Dominique DECT"<621> ; the CID that any call make from this line will pushed to other phone
In your file extension.conf I advise you to add a debug statment which will help you to see from your asterisk log if you receive the CID
You need to add the "o" flag in the Dial command to push the CID
incoming ; I assume that incoming call are routed to the incoming context.
exten => s,1,Verbose(Incoming call from BT line — CallerID=${CALLERID}) ; add a debug line with the received CID on asterisk console
exten => s,n,Dial(Zap/1,90,190,o) ;dial DECT base via analog interface the "o" flag push the CID as received
Latest Update
The CVS has been patched to facilitate various non-US caller ID standards including UK CID. However, Mark will not add the specific support for the X100P as "adds otherwise needless bloat to the zaptel side". Ho hum. You must either use a TDM400 with FXO module or use a patch against the latest CVS. This is available from Kevin Walsh ( kevin .at. cursor .dot. biz ). Patches written by Marc McLaughlin for v1.0 are also available and can be downloaded from LUSYN's website.Update
A patch has just been submitted which allows the digium x100p analog line cards to receive UK caller id! It may take a little while before this patch gets included in asterisk but if you need the feature now, it can be done. The patch was designed for cvs head as of late May 2004, YMMV on other versions.The patch
Announcement of patch on mailing list
Asrterisk/zaptel debs, currently with UK Caller ID patch, for Debian/Sarge
Unfortunately, BT does not use the standard bellcore method for transmitting caller ID information which means that Asterisk (or more specifically, the X100P interface card) can't detect it.
There is a way round this of course, and that is to use a modem that supports BT CID information, and read this off the serial port. I've managed to get an old Pace modem working quite well, along with a couple of perl scripts. Unfortunately Pace went out of business in 1999, so the only place I've found to get hold of these modems is Ebay, where you can expect to pay around 20 pounds for one.
Once you have a working modem and have turned caller ID on on it (AT#CID=1 on my Pace modem) you can integrate this with Asterisk. I've used two perl scripts, (provided on the Asterisk-dev mailing list by Jonathan McHarg, edited by me) to collect and process the CID info. The first script runs constantly in the background, listening to the modem port for any line that begins NMBR and grabbing the number it displays.
{CODE()}
- !/usr/bin/perl
$PortObj = open(MODEM,$PortName) || die "Can't open $PortName:$!";
print MODEM "AT S7=45 S0=0 L1 V1 X4 &c1 E1 Q0 #CID=1";
while (1==1) {
local $/ = "\n";
while ($line=) {
chomp;
if ( $line =~ s/NMBR = //) {
open(OUTFILE, ">/usr/share/cid/callerid.txt") or die "Can't open callerid.txt: $!";
$line =~ s/^M//; # Strip off any carriage return chars
$line =~ s/\n//; # Strip off any line feeds
# The output must only contain a single line.
print OUTFILE "$line";
close OUTFILE;
};
}
}
{CODE}
The second script is run using AGI in the extensions.conf file whenever an incoming call is detected and simply sets the CID information. My version also looks the number up in the database and adds the name of the calling party if known.
{CODE()}
- !/usr/bin/perl
use DBI;
open(INFILE, "/usr/share/cid/callerid.txt") or die "cannot open file";
if ($callerID=) {
my $dbh = DBI->connect ("dbi:mysql:host=alice:database=asterisk","asterisk","password")
or die "Can't connect to database: $DBI::errstr";
my $sth = $dbh->prepare( "SELECT cid FROM known_numbers WHERE source='$callerID'" );
$sth->execute();
@row = $sth->fetchrow_array();
print "SET CALLERID "@row"<$callerID>";
}
close INFILE;
{CODE}
To run this script, change the s extension in the default config to look something like:
{CODE()}
exten => s,1,agi,/var/scratch/cid/getcid.pl
exten => s,2,Dial(extensions to ring)
{CODE}
Now, whenever someone rings, the CID info will be processed by asterisk.
Notes:
- NB. You must have CID activated on your line!
- I had some problems with the modem not activating the CID mode. In the end I simply used minicom to access the modem, issued the AT#CID=1 command, followed by AT&W to save the current config.
- To use with a database on numbers, just create a table in a database with two columns; source and cid and populate them with a list of numbers. To not use the database just remove all the database commands from the script (including the use DBI; line)
- For more information on CID, check out: CID FAQ
- In the UK, it is best to turn off the caller ID in zapata.conf by adding a line usecallerid=no to the incoming channel. This makes asterisk pick the call up quicker.
- Non-BT lines in the UK (eg cable company lines) may use another (partially bellcore compatible) standard - see here.
See also:

Comments
333Patch to fix intermittent CID detection
I tried paying with the gain, but it made no difference.
The patch here solved all my detection problems.
To quote the post:
Some UK BT lines seem to be able to trigger a false ring on the tdm400p at exactly 380ms after the CID starts. This results in * giving up on the CID and going into a fallback state where it just gets on with the call
333Caller ID is still not showing up always on Sangoma A200
cidsignalling=v23
cidstart=polarity
callerid=asreceived
usecallerid = yes
;For your incoming BT line connected to an FXO module (red)
immediate=yes ; will take the line on the first ring
context = from-zaptel
;switchtype = national
echocancel = yes
echocancelwhenbridged = yes
echotraining = yes
;add the is option if you are problems with DTMF detection
;relaxdtmf = yes
rxgain = 6.0
txgain = 6.0
signalling = fxs_ks
group = 0
channel => 1-2
language=en
callgroup=1
333Caller ID is still not showing up?
Anyway. The problem seems to be line quality, or actually attenuation.
If it still doesn't work for you try to modify zapata.conf adding following lines:
rxgain=15.0
txgain=5.0
Depending on your line length, quality and many other things you basically have to try different rxgain parameters. If it's too high it won't accept DTMF tones. If it's too low CID won't work.
I suggest you start with 5 and try to increase it by 5... so 5, 10, 15 and so on.
Good luck,
Martin
333UK Caller ID on X100P
I have asterisk 1.2.5 running with the UK Caller ID patch. I have Caller ID enabled on my phone line.
My Zapata.conf :
channels
usecallerid=yes
ukcallerid=yes
cidsignalling=v23
cidstart=usehist
signalling=fxs_ks
language=en
context=test
channel => 1
I am getting the following error when running asterisk and making a call
Mar 27 14:13:12 DEBUG7521: chan_zap.c:5829 ss_thread: Using history buffer to extract caller ID
Mar 27 14:13:12 ERROR7521: chan_zap.c:5837 ss_thread: zt_get_history failed: Inappropriate ioctl for device
— Executing Wait("Zap/1-1", "10") in new stack
Mar 27 14:13:12 DEBUG7521: chan_zap.c:4364 __zt_exception: Exception on 20, channel 1
Mar 27 14:13:12 DEBUG7521: chan_zap.c:3547 zt_handle_event: Got event Ring/Answered(2) on channel 1 (index 0)
Mar 27 14:13:12 DEBUG7521: chan_zap.c:3899 zt_handle_event: Setting IDLE polarity due to ring. Old polarity was 0
......
Any ideas on what I need to do to get CallerID working correctly ?
Thanks Avron
333UK Ring vs. UK Caller ID with Zap
I have a TDM400P and have successfully implemented caller id using the lines shown at the top of this page.
However, I wanted to go one step further and change the ring type to UK, following instructions elsewhere on this site I changed the defaultzone and loadzone in zaptel.conf from US to UK. Sure enough the phones then rang with the UK style double ring but caller ID was lost...
Is there some sort of compatibility issue here, anyone know of a way around this?
Thanks...Jason.
333
in zapata.conf
usecallerid=yes
add below this line the following
ukcallerid=yes
333Trouble with TDM400P and UK CLID...
Kind regards,
Phil Hodges
Zapata.conf
channels
language=en
context=landlines
signalling=fxs_ks
usecallerid=yes
cidsignalling=v23
cidstart=polarity
callerid=asreceived
immediate=yes
echotraining=yes
echocancel=yes
echocancelwhenbridged=yes
musiconhold=default
group=1,2,3,4
pickupgroup=1,2,3,4
rxgain=9.0
txgain=7.0
channel => 1-4
333Trouble with TDM400P and UK CLID...
Kind regards,
Phil Hodges
Zapata.conf
channels
language=en
context=landlines
signalling=fxs_ks
usecallerid=yes
cidsignalling=v23
cidstart=polarity
callerid=asreceived
immediate=yes
echotraining=yes
echocancel=yes
echocancelwhenbridged=yes
musiconhold=default
group=1,2,3,4
pickupgroup=1,2,3,4
rxgain=9.0
txgain=7.0
channel => 1-4
333Re: Thanks!
Update - Now resolved, good old Telewest changed type of caller id from "Name and number" to just "number"
333Thanks!
I also had to make sure I had
cidstart=ring
in zapata.conf.