Saturday, January 20, 2007

Meetme by AGI

the script below (meetme.agi) will prompt for a valid pin up to 3 times. If the pin matches one of the defined Admin pins, it will set the dialplan priority to 10 and exit, if User, sets to 20 and exits. Otherwise Hangs up.

In the case of admin, these MeetMe options are used:
a - Admin mode
A - Marked mode
c - Announce number of participants (optional of course)
s - Present Admin menu by pressing '*'
x - close conf when last marked user leaves.

In the case of user:
c s x are used as above, but we add:
w - wait until marked user enters. (Plays MoH until then)

The dialplan assumes you have a static pinless conference setup as conf #10.

exten => 5552323,1,Wait(1)
exten => 5552323,2,Answer()
exten => 5552323,3,AGI(meetme.agi)
exten => 5552323,4,NoOp(Invalid Pin)
exten => 5552323,5,Hangup()

exten => 5552323,10,NoOp(Admin Pin)
exten => 5552323,11,MeetMe(10,aAcsx)
exten => 5552323,12,Hangup()

exten => 5552323,20,NoOp(User Pin)
exten => 5552323,21,MeetMe(10,cswx)
exten => 5552323,22,Hangup()

The script of course requires the Asterisk::AGI module.


use Asterisk::AGI;
my $AGI = new Asterisk::AGI;
my $input = { %{$AGI->ReadParse()} };

#our $DEBUG = 1;

my @UserPins = ('11111','22222');
my @AdminPins = ('99999','88888');

my $mode = collectPin($AGI,5);

$AGI->verbose("collectPin got '$mode'") if $DEBUG;

if ($mode eq 'Admin') {
} elsif ($mode eq 'User') {
} else {


sub collectPin {
my $AGI = shift;
my $maxdigits = shift;

my $tries = 0;

#Three tries to select an existing pin.
while ($tries < 3) {
$AGI->stream_file("please-try-again",'""') if $tries > 0;
my $pin = $AGI->get_data('enter-conf-pin-number', "10000", $maxdigits);
$AGI->verbose("Got PIN $pin.") if $DEBUG;
next unless $pin > 0;

if ( grep(/^$pin$/, @AdminPins) ) {
return 'Admin';
} elsif ( grep(/^$pin$/, @UserPins) ) {
return 'User';
} else {

return undef;

Sunday, January 14, 2007

Mediaproxy with Accounting setup

There is a new MediaProxy release available.

To upgrade go to or download the software directly from:

Changes from version 1.7.2 to 1.8.0

Added support for radius accounting. The accounting type can be specified in the configuration file. To support radius accounting the pyrad module must be installed (available at The old boolead switch dbaccounting in the [Accounting] section of mediaproxy.ini was replaced by accounting which is a string
specifying the accounting type to be used: none, radius or database.

For those using CDRTool, release 5.0 is available, which works with the new Radius accounting of MediaProxy 1.8.0. To upgrade go to or download the software directly from:

Anand Kumar

Monday, January 8, 2007


Whats AGI?
AGI stands for Asterisk Gateway Interface. AGI allows Asterisk to launch external programs written in any language to control a telephony channel, play audio, read DTMF digits, etc. by communicating with the AGI protcol on stdin ad stdout.

N-Way Calling or Three Way Calling by asterisk

How this works

When You speak with other party, press *0 (macro nway-start is executed). Called party is immediately transferred to free conference, and You get dialtone to enter number of party You want to invite. After call established and You talk to third user, You can press ** to invite him to conference and *# to hangup call and return to conference. From conference any user can invite anyone else by pressing 0 (all other steps are same as for *0)

Here is dialplan example:

exten => _XXX,1,Set(DYNAMIC_FEATURES=nway-start)
exten => _XXX,n,Dial(SIP/${EXTEN})

exten => _XXX,1,Answer
exten => _XXX,n,Set(CONFNO=${EXTEN})
exten => _XXX,n,Set(MEETME_EXIT_CONTEXT=dynamic-nway-invite)
exten => _XXX,n,Set(DYNAMIC_FEATURES=)
exten => _XXX,n,MeetMe(${CONFNO},pdMX)
exten => _XXX,n,Hangup

exten => 0,1,Read(DEST,dial,,i)
exten => 0,n,Set(DYNAMIC_FEATURES=nway-inv#nway-noinv)
exten => 0,n,Dial(Local/${DEST}@dynamic-nway-dest,,g)
exten => 0,n,Set(DYNAMIC_FEATURES=)
exten => 0,n,Goto(dynamic-nway,${CONFNO},1)
exten => i,1,Goto(dynamic-nway,${CONFNO},1)

exten => _XXX,1,Dial(SIP/${EXTEN})

exten => s,1,Set(CONFNO=${FindFreeConf()})
exten => s,n,ChannelRedirect(${BRIDGEPEER},dynamic-nway,${CONFNO},1)
exten => s,n,Read(DEST,dial,,i)
exten => s,n,Set(DYNAMIC_FEATURES=nway-inv#nway-noinv)
exten => s,n,Dial(Local/${DEST}@dynamic-nway-dest,,g)
exten => s,n,Set(DYNAMIC_FEATURES=)
exten => s,n,Goto(dynamic-nway,${CONFNO},1)

exten => s,1,ChannelRedirect(${BRIDGEPEER},dynamic-nway,${CONFNO},1)

exten => s,1,SoftHangup(${BRIDGEPEER})

Note, You need to provide FindFreeConf() function (or any other way) to get free Conference number.

And, to make all this work, here is features.conf:

nway-start => *0,caller,Macro,nway-start
nway-inv => **,caller,Macro,nway-ok
nway-noinv => *#,caller,Macro,nway-notok

Sunday, January 7, 2007

Follow-Me using Asterisk

follow me script to allow Asterisk to ring from your desk phone to a cell phone then back to voicemail. If you are not available to answer the cell phone (or choose not to) it will ring back to Asterisk voicemail.
exten => 1234,1,dial(sip/1234,20)
exten => 1234,2,playback(pls-wait-connect-call)
exten => 1234,3,Setvar(NewCaller=${CALLERIDNUM})
exten => 1234,4,SetCIDNum(0${CALLERIDNUM})
exten => 1234,5,dial(${TRUNK}c/9871234321,20,r)
exten => 1234,6,SetCIDNum(${NewCaller})
exten => 1234,7,voicemail2(u1234@default)
exten => 1234,101,voicemail2(b1234@default)
exten => 1234,102,hangup

exten => 1234,1,dial(sip/1234,20)

* Present the caller with a transfer message to let them know that the system is doing something.

exten => 1234,2,playback(pls-wait-connect-call)

* Set a new variable with the current caller id information

exten => 1234,3,Setvar(NewCaller=${CALLERIDNUM})

* Place a 0 before the caller id number to let the called party know that this is coming as a transfer from the desk phone.

exten => 1234,4,SetCIDNum(0${CALLERIDNUM})

* Dial the cell phone 987-123-4321. Display a ring to the caller until # is pressed on the cell phone.

exten => 1234,5,dial(${TRUNK}c/9871234321,20,r)

* If the called party chooses to not accept the call change the callerid information back.

exten => 1234,6,SetCIDNum(${NewCaller})

* Place the caller into voicemail.

exten => 1234,7,voicemail2(u1245@default)

* If the called party is on the phone just go to voicemail (this may be out of step??).

exten => 1234,101,voicemail2(b1234@default)

exten => 1234,102,hangup

  1. The c after the TRUNK command is what causes the connection to wait until the # key is pressed to complete the call.
  2. You can use something other than ,r which causes the caller to hear ringing while the call is being placed to the cell phone. Using ,m as an option will play music on hold until someone answers.

Friday, January 5, 2007

VoIP Codecs

Coders/decoders (Codecs) are used by VoIP networks for converting analog voice signals into digital pulses and then reconvert the digital pulses into analog signals. In order to communicate, the codecs have to be compatible with each other. The algorithms that the codecs use for conversion of the data streams affect the quality of voice as well as the bandwidth consumption.

The solutions to algorithm usage are either proprietary or covered by international standards, where everyone has access to the algorithms. Pulse Code Modulation (PCM) was responsible for the development of the T-carrier systems that are used even today. PCM could yield a data rate of 64 Kbps. The signal was sampled in two ways, Mu-Law in the US and Japan and A-Law in Europe. Both these forms of sampling allowed for a high resolution as the discrete levels were apportioned logarithmically and not linearly.

Recommendation G.711 has been instituted by the ITU in 1988 and is the standardized form of the PCM encoding. PCM does not eliminate the redundancy in the signals, which can result in a high data output rate unsuitable for certain situations, especially when there is a bandwidth constraint. This is the reason why several speech algorithms have attempted to reduce the data rate. Reduction in data rate by half can double the call-carrying capacity of the given bandwidth. G.722.1, G.723.1, G.726, etc are codec standards that reduce the bandwidth requirements. Their data rates are 24/32, 5.3/6.3, 16/24/32/40 Kbps, respectively.

Apart from these open standards, there are proprietary algorithms that may or may not offer an advantage over the ITU-defined algorithms. However, they can tie a business to their implementation for the economic life-cycle of the VoIP system.

Thursday, January 4, 2007

Asterisk Realtime with MySQL.

This is a How-to for the beginners to work Realtime Asterisk with MySQL.

Getting Asterisk-addons.
1. Download asterisk-addons tar from the site (
2. Untar it under /usr/src
3. cd /usr/src/asterisk-addons
4. make clean
5. make install
6. This installs the module for mysql, "" into your asterisk modules dir.
7. Copy "res_mysql.conf.sample" from "/usr/src/asterisk-addons/configs" and place it under "/etc/asterisk/"
8. Rename "res_mysql.conf.sample" it to "res_mysql.conf"

Creating database in MySQL.
I have created a database by name "test" with two tables "sip_buddies" and "extensions"

Create table "sip_buddies" using:
CREATE TABLE `sip_buddies` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(80) NOT NULL default '',
`accountcode` varchar(20) default NULL,
`amaflags` varchar(13) default NULL,
`callgroup` varchar(10) default NULL,
`callerid` varchar(80) default NULL,
`canreinvite` char(3) default 'yes',
`context` varchar(80) default NULL,
`defaultip` varchar(15) default NULL,
`dtmfmode` varchar(7) default NULL,
`fromuser` varchar(80) default NULL,
`fromdomain` varchar(80) default NULL,
`fullcontact` varchar(80) default NULL,
`host` varchar(31) NOT NULL default '',
`insecure` varchar(4) default NULL,
`language` char(2) default NULL,
`mailbox` varchar(50) default NULL,
`md5secret` varchar(80) default NULL,
`nat` varchar(5) NOT NULL default 'no',
`deny` varchar(95) default NULL,
`permit` varchar(95) default NULL,
`mask` varchar(95) default NULL,
`pickupgroup` varchar(10) default NULL,
`port` varchar(5) NOT NULL default '',
`qualify` char(3) default NULL,
`restrictcid` char(1) default NULL,
`rtptimeout` char(3) default NULL,
`rtpholdtimeout` char(3) default NULL,
`secret` varchar(80) default NULL,
`type` varchar(6) NOT NULL default 'friend',
`username` varchar(80) NOT NULL default '',
`disallow` varchar(100) default 'all',
`allow` varchar(100) default 'g729;ilbc;gsm;ulaw;alaw',
`musiconhold` varchar(100) default NULL,
`regseconds` int(11) NOT NULL default '0',
`ipaddr` varchar(15) NOT NULL default '',
`regexten` varchar(80) NOT NULL default '',
`cancallforward` char(3) default 'yes',
`setvar` varchar(100) NOT NULL default '',
UNIQUE KEY `name` (`name`),
KEY `name_2` (`name`)

Create table "extensions" using:
CREATE TABLE `extensions` (
`id` int(11) NOT NULL auto_increment,
`context` varchar(20) NOT NULL default '',
`exten` varchar(20) NOT NULL default '',
`priority` tinyint(4) NOT NULL default '0',
`app` varchar(20) NOT NULL default '',
`appdata` varchar(128) NOT NULL default '',
PRIMARY KEY (`context`,`exten`,`priority`),
KEY `id` (`id`)

Add some data into them, no need to enter all the details in sip_buddies, add only the necessary fields.

I have added a context like

name = 102
canreinvite = no
context = default
dtmfmode = rfc2833
host = dynamic
port= yes
type = friend
username = 102
secret = 102

(if u r getting error in uploadin data, change the field type from NOT NULL to NULL)

Add some data into extensions table also.

500 default VoiceMailMain
123 default Playback welcome

Configuration in res_mysql.conf.
dbhost = localhost
dbname = test
dbuser = username
dbpass = password
dbport = 3306
dbsock = /tmp/mysql.sock

(check the mysql.sock path, it could be /var/lib/mysql/mysql.sock)

Configuration in extconfig.conf.
sipusers => mysql,test,sip_buddies
sippeers => mysql,test,sip_buddies
extensions => mysql,test,extensions

Configuration in sip.conf.


Configuration in extensions.conf.

switch => Realtime/default@extensions

Start the asterisk,
In the CLI mode,
CLI> realtime mysql status

This shows the status of your mysql connection, like

"Connected to test@localhost, port 3306 with username root for 46 minutes, 30 seconds"

Anand Kumar Dayal