Calling Between Devices

 

So far we've only configured one SIP peer and made a simple test extension that interacts with Asterisk its self.  But ultimately we want to call other people, whether it's another phone across the hall or a real phone number of someone on the other side of the country.  We'll start with the former, by configuring another peer that our TestPhone-A peer can call.

Open up /etc/asterisk/sip.conf and add a new peer at the bottom:

[TestPhone-B]
type=peer
host=dynamic
secret=somepassword
context=internal

Looks pretty much the same as the TestPhone-A peer we created in the Configuring SIP section.  Reload the SIP module from the Asterisk console to load the new peer:

primer*CLI> sip reload

Now configure another device (like another softphone) just like we did previously with TestPhone-A, but using TestPhone-B as the username and whatever password you chose above.  Make sure it registers by looking at the console, and even dialing our previously made 777 test extension.

Now we need to create some extensions in the dialplan to allow the two phones to call each other.  We are going to make up some arbitrary extension numbers for each device;  We'll assign TestPhone-A extension 100, and TestPhone-B extension 200.

Again open /etc/asterisk/extensions.conf and add some new extensions under the [internal] context we previously created:

exten => 100,1,Dial(SIP/TestPhone-A)
exten => 200,1,Dial(SIP/TestPhone-B)

As you can see, we've created two extensions, each with only one priority, that use the Dial application to make a call using a SIP channel to a named peer.

What's a channel?

Internally, a line of communication between Asterisk and something else (a device or some other entity) is called a channel, which is an abstraction layer between a particular technology and Asterisk.  Channel drivers exist for technologies ranging from VoIP protocols like SIP, IAX, H.323 and SCCP, to hardware-based technologies like analog and digital telephone interface cards through a driver layer called DAHDI.

When you use the Dial application to make a call, you are creating a channel of a specific type and then passing it arguments that mean something specific to the channel driver.  The general syntax for specifying a channel with Dial is Dial(Technology/Resource).

Technology in our case is SIP, the name of the channel type the SIP channel driver provides.  Resource varies on the channel type and has a syntax of its own depending on that type.  With SIP, we're using one form which specifies the name of a SIP peer.

So, with the two extensions we created, dialing 100 will cause Asterisk to ring the peer TestPhone-A, and dialing 200 will cause Asterisk to ring the peer TestPhone-B.  Reload the dialplan on the Asterisk console with dialplan reload and give them a try!

The Dial application has a litany of additional arguments to control its behavior, which you can read about with "core show application Dial" on the console.  Just to expand our example slightly, let's quickly use the first argument, timeout.

As it stands now, if you dial 100 or 200 and don't pick up the ringing phone, it will continue to ring indefinitely - until you hang up the phone you called from.  Let's make Asterisk play a message if no one answers after 15 seconds.  Edit /etc/asterisk/extensions.conf and change the 100 and 200 extensions:

exten => 100,1,Dial(SIP/TestPhone-A,15)
exten => 100,n,Playback(number-not-answering)

exten => 200,1,Dial(SIP/TestPhone-B,15)
exten => 200,n,Playback(number-not-answering)

Now the Dial application will timeout after 15 seconds if the channel isn't answered, and continue executing priorities for the extension - which in this case is to play a short "your party is not answering" message before hanging up.

Hint: Although we're not going to set it up here, the Dial timeout is the basis for using the Asterisk voicemail system to allow the caller to leave a message for someone.

Now that you've got the rudimentary concepts of SIP peers and the dialplan down and have successfully made internal calls between two local devices, let's talk about making and receiving calls to and from the outside world.