Friday, April 17, 2009

Asterisk PBX System Install - 04 PBX Test Config

Issue: With Asterisk running we want to communicate with it. First step in doing is to configure Asterisk to do something.


Configuring Asterisk
The first goal is to use a phone to connect to Asterisk and have Asterisk respond.

#cd /etc/asterisk (this is the directory where the asterisk configuration files are)
#mv extensions.conf extensions.conf.sample (mv renames the original sample to extensions.conf.sample)
#touch extensions.conf (This creates a new blank extensions.conf file)

Edit the extensions.conf file to create something we can use to test that the system is working. This is where you setup phone extensions but this is also where you tell Asterisk what to do and how to respond to key presses from the user. This is called the Dialplan for the Asterisk server. There are more details about Dialplans in chapter five of the book but just a quick look for now. Extensions.conf is made up of

Contexts - are sections set apart by labels in square brackets []. Each section is independent and they do not interact unless you allow them to do so.
Extensions - are not just a phone extension but a set of instructions that are executed when that extension is dialed.
Priorities - determine in what order the extension command are executed.
Applications - execute specific commands like Answering the line or Hanging up the line.

More about this later but for now I just want to configure the file to give me some indication that Asterisk is working. I am going to use the “vi” editing tool so there is some information on how to use it below.

#vi extensions.conf
I like to use vi because it is a common editor on LINUX and UNIX systems but it takes some getting use to.

OK the real truth is, I use vi becuase I took a UNIX class many years ago and that is what I learned how to use. I got an email saying that nano is a good editor. If you want to use it you can install it using yum.

# yum install nano (or emax-nox or vim or any other editor that makes you happy- ;)

Just a quick overview of how vi works if you choose to use it.
I will open a new file called test
#vi test
This opens up a file with the cursor at the top of the file.
In vi there are two modes, Command mode and Insert mode.
You cannot enter text into the file until you get into the Insert mode.
Press the letter i to enter insert mode (use lower case i)
Now you can type some text (you can use the arrow keys to move around)
When you are done you have to go back to Command mode to save and exit.
Press the Esc key to get back to Command mode.
Use the shift key to enter a colon: After the colon, enter wq, which means write and quit like this-
:wq (press enter and you will be out of the vi editor)

Now lets edit our extensions.conf file
#vi extensions.conf

i (you will see the text -- INSERT -- at the bottom of the screen
You can now start entering text.





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

include => internal

Esc key to get out of insert mode
:wq Enter key to write and exit

Note if you need to exit vi without saving :q! will force quit with no write.

Most of the sections are empty for now. Under the internal context, the commands labeled 401 will execute when extension 401 is dialed. The call will answer, play a sound file, and then hang up the line.

Now we are going to do the same kind of thing with the sip.conf file.

#mv sip.conf sip.conf.sample (mv renames the original sample to sip.conf.sample)
#touch sip.conf (This creates a new blank sip.conf file)
#vi sip.conf




In the sip.conf file under the section [207] is where I configure Asterisk to allow my phone to connect with Asterisk. More about this later when we configure the Cisco 7940 phone to use sip (Session Initiation Protocol) commands. Notice that under [207] is the context of internal. This is the context name I used to setup the 401 test in the extension.conf file.

To recap the sip.conf file is going to allow my phone (extension 207) to connect to asterisk using the context of internal. The extensions.conf file has the 401 extension defined in the same context of “internal” and is configured to play back a sound when I dial that number from my phone.

Now we need to load the new configuration into Asterisk.
If asterisk is not running you can start it by typing at the command line:
#asterisk –vvv (set verbose to 3 which gives you more info in the console screen)
If Asterisk is running you can connect to the Asterisk console by typing “asterisk –r”
#asterisk –r

Your command line changes a bit and you have ServerName*CLI> which indicates you are in the Asterisk Console view.

In asterisk the interface is a bit like cisco command line interface.
>? A question mark will bring up help information
>dialplan ? Will tell you what options you can use with the dialplan command

To load the changes made to extensions.conf type:
>dialplan reload
Some lines of text will show up on the screen. (you may have to press enter to get back to the prompt)

Note: If anyone knows how to keep the console screen from scrolling off before you can read the output please let me know. The workaround is to use the PuTTY program to connect to the asterisk server and launch the Asterisk console. This allows you scroll back the screen.

To load the changes made to the sip.conf file type:
>sip reload
Some lines of text will show up on the screen. (you may have to press enter to get back to the prompt)

To get out of the Asterisk console type exit

Next we need to Load sip on the phone.

Asterisk PBX System Install - 05 Cisco SIP Phone

Asterisk PBX Install - Index

1 comment:

rajivkumar thanraj said...

A good explanation on the asterisk PBX setup and the related concepts with it. One can easily setup by just seeing the above information.