Friday, April 24, 2009

Asterisk PBX System Install - 06 Two SIP Phones

Issue:
The goal for today is to be able to call another extension on the Asterisk server and talk to someone.

Quick/Visual/Learning:


The goal to have a phone connect to Asterisk and have Asterisk respond should have been accomplished last time.
The new goal is to have two ip phones talking to each other.

We well need a second IP phone configured for SIP.
This should be pretty easy since we got everything in place already in the last post.

Plug in the phone and get the MAC Address of the phone
Copy the MAC Address specific file we created last time (my example SIP000d28f35928.cnf)
Edit the copy to configure the names of the phone to be the new extension name (example replace 207 with 222)
Rename the copy to match the MAC Address of the new phone SIPXXXXXXXXXXXX.cnf (Replace Xs with MAC Address)
Now the phone should come up with SIP loaded and the correct extension name (example 222).

Just to test you may want to look at the ip address on the phone and verify that the Asterisk server can ping that address as we did last time.

Now the task is to configure Asterisk so the phones can call each other.

We need to change the sip.conf file to allow the new phone 222 to connect to Asterisk. These files are in the /etc/asterisk directory. Using vi to edit sip.conf we see the contents of the file on the screen. Get into the insert mode and add the same text for 222 as we have for 207
#vi sip.conf
i

[general]

[207]
context=internal
type=friend
disallow=all
allow=ulaw
host=dynamic

[222]
context=internal
type=friend
disallow=all
allow=ulaw
host=dynamic

Esc-Key
:wq

Connect to the Asterisk console and run the command
#asterisk -r
>sip reload

This loads our changes to the sip file. I am now able to dial extension 401 on the extension 222 phone and here the weasels message played but I still cannot dial the other phone extension because it has not been added to the extensions.conf file yet.

This is a good time to talk a bit more about the Dialplan (extensions.conf) file.
When you create an extension for a phone in the extensions.conf file you are creating a program that runs when the extension is called. Each step for our 207 example extension is defined like this:
exten => 207

The first step is always number 1 (must be labeled this way). You could number the next step 2 but instead you can use n for all the steps after 1 and Asterisk will just do them in order. That way you can move things around without having to renumber everything.

exten=>207,1

Next comes the action or program to be performed (Answer the call in this case) :
exten=>207,1,Answer()

Answer does not require any extra information to work. When we dial the extension in this case we do not want Asterisk to Answer we want it to connect us to another phone we are dialing. You do this with the Dial() application and that does require more information.
Inside the parenthasis be can put up to 4 arguments.
Dial(Destination, timeout, option, URL)
All we are going to use is a destination and a timeout.

exten=>207,1,Dial(SIP/207,15)

This tells asterisk to ring the sip phone 207 that is defined in our sip.conf file for 15 seconds. If no one answers the phone the next step will be to hangup the line. (Later we will look at things like voicemail.)

Now lets update our extensions.conf file.

Get out of Asterisk console
>exit
Edit the extensions.conf file and add the phone extensions as you see below in the internal context (section) of the file.
#vi extensions.conf
[globals]

[general]

[default]

[incoming_calls]

[internal]

exten => 207,1,Dial(SIP/207,10)
exten => 207,n,Hangup()

exten => 222,1,Dial(SIP/222,10)
exten => 222,n,Hangup()

exten => 401,1,Answer()
exten => 401,n,Playback(tt-weasels)
exten=> 401,n,Hangup()

[phones]
include => internal


Esc-Key
:wq

Now reload this configuration in Asterisk. Go to the Asterisk console prompt and issue the command dialplan reload.
>dialplan reload

Since we have verbose turned on you should see the plan load with no error messages. These changes tell Asterisk what to do when the phone extension is dialed. When you pick up the phone on 222 and dial 207 Asterisk will connect or dial the SIP device 207 we created in the sip.conf file and complete the call connection. The same thing will happen if we pick up the 207 phone and call 222.

Next time we will look at connecting to an external phone line.
Asterisk PBX System Install - 07 External Line
Asterisk PBX Install - Index

No comments: