Friday, March 6, 2015

Create your own Cloud PBX with Asterisk and FreePBX Part 3

We can now go to our web browser and type the IP of our system to manage our FreePBX. The first thing we'll be required to do is set up the admin account. After that, we can just go to "FreePBX Administration" and begin setting things up.



I guess that's expected when you use a t2.micro instance
We can go right ahead and upgrade, this interface makes the whole process too easy.


 

 


And after it's finished, if we check again:


After it's done, we want to "Apply Config", then more modules will become available, so feel free to update everything, applying the config and checking again until there's nothing more to upgrade.

root@localhost:/usr/src/freepbx# amportal a ma refreshsignatures

After you enable and update the modules in FreePBX, you might see the following error: Symlink from modules failed

To correct this error just delete the list of failed files:

root@localhost:/usr/src/freepbx# cd /etc/asterisk
root@localhost:/etc/asterisk# rm ccss.conf confbridge.conf features.conf sip.conf iax.conf logger.conf extensions.conf sip_notify.conf

Then on the FreePBX webUI go to the ‘Module Admin’ and uninstall and reinstall the ‘Camp On’ module. This should resolve the Symlink issue.

Before we move any further, I'd like to recommend something: Head on over to Digium and buy their g729 codec. It's amazing. I am in no way affiliated with Digium but please consider this. Not just because of the fact that Asterisk is a great product and you should support its development team; g729 is really, really worth every cent of its cost.

These are the steps required to install the g729 codec.

We need to know our Asterisk version and our platform before we install it:

root@localhost:~# asterisk -V
Asterisk 11.16.0
root@localhost:~# uname -a
Linux localhost 3.2.0-77-virtual #112-Ubuntu SMP Tue Feb 10 15:34:22 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Right, so we're running Asterisk 11.16.0 on a 64-bit system.

root@localhost:~# mkdir g729_codec
root@localhost:~# cd g729_codec/

After we've received the license key in our mailbox, we need to go to http://downloads.digium.com/pub/register and find which version of the file we need to download.

root@localhost:~/g729_codec# wget http://downloads.digium.com/pub/register/linux/register
root@localhost:~/g729_codec# chmod 700 register 
root@localhost:~/g729_codec# ./register

We now have to go to http://downloads.digium.com/pub/telephony/codec_g729/benchg729 and find which version of the file we need to download.

root@localhost:~/g729_codec# wget http://downloads.digium.com/pub/telephony/codec_g729/benchg729/x86-64/benchg729-1.0.8-x86_64
root@localhost:~/g729_codec# chmod 700 benchg729-1.0.8-x86_64
root@localhost:~/g729_codec# ./benchg729-1.0.8-x86_64 
Results:
Average for flavor 'generic' is 238 milliseconds of CPU time.
Average for flavor 'nocona' is 241 milliseconds of CPU time.
Average for flavor 'core2' is 237 milliseconds of CPU time.
Average for flavor 'opteron' is 440 milliseconds of CPU time.
Average for flavor 'opteron-sse3' is 438 milliseconds of CPU time.
Average for flavor 'barcelona' is 237 milliseconds of CPU time.

Recommended flavor for this system is 'core2' with an average of 237 milliseconds of CPU time.

So the recommended flavor for my Linode is 'core2'. Now go to http://my.digium.com/en/docs/G729/g729-download/ and select your platform and the recommended flavor, which in my case is core2.

root@localhost:~/g729_codec# wget http://downloads.digium.com/pub/telephony/codec_g729/asterisk-11.0/x86-64/codec_g729a-11.0_3.1.7-core2_64.tar.gz
root@localhost:~/g729_codec# tar zxvf codec*
root@localhost:~/g729_codec# cd codec*
root@localhost:~/g729_codec/codec_g729a-11.0_3.1.7-core2_64# cp codec*.so /usr/lib/asterisk/modules
root@localhost:~/g729_codec/codec_g729a-11.0_3.1.7-core2_64# amportal restart

That's it!

root@localhost:~/g729_codec# root@localhost:~# asterisk -rvvvv
Asterisk 11.16.0, Copyright (C) 1999 - 2013 Digium, Inc. and others.
Created by Mark Spencer 
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 11.16.0 currently running on localhost (pid = 839)
localhost*CLI> core show translation
         Translation times between formats (in microseconds) for one second of data
          Source Format (Rows) Destination Format (Columns)

            gsm  ulaw  alaw  g726 adpcm  slin lpc10  g729  ilbc g726aal2  g722 slin16 testlaw slin12 slin24 slin32 slin44 slin48 slin96 slin192
      gsm     - 15000 15000 15000 15000  9000 15000 15000 15000    15000 17250  17000   15000  17000  17000  17000  17000  17000  17000   17000
     ulaw 15000     -  9150 15000 15000  9000 15000 15000 15000    15000 17250  17000   15000  17000  17000  17000  17000  17000  17000   17000
     alaw 15000  9150     - 15000 15000  9000 15000 15000 15000    15000 17250  17000   15000  17000  17000  17000  17000  17000  17000   17000
     g726 15000 15000 15000     - 15000  9000 15000 15000 15000    15000 17250  17000   15000  17000  17000  17000  17000  17000  17000   17000
    adpcm 15000 15000 15000 15000     -  9000 15000 15000 15000    15000 17250  17000   15000  17000  17000  17000  17000  17000  17000   17000
     slin  6000  6000  6000  6000  6000     -  6000  6000  6000     6000  8250   8000    6000   8000   8000   8000   8000   8000   8000    8000
    lpc10 15000 15000 15000 15000 15000  9000     - 15000 15000    15000 17250  17000   15000  17000  17000  17000  17000  17000  17000   17000
     g729 15000 15000 15000 15000 15000  9000 15000     - 15000    15000 17250  17000   15000  17000  17000  17000  17000  17000  17000   17000
     ilbc 15000 15000 15000 15000 15000  9000 15000 15000     -    15000 17250  17000   15000  17000  17000  17000  17000  17000  17000   17000
 g726aal2 15000 15000 15000 15000 15000  9000 15000 15000 15000        - 17250  17000   15000  17000  17000  17000  17000  17000  17000   17000
     g722 15600 15600 15600 15600 15600  9600 15600 15600 15600    15600     -   9000   15600  17500  17000  17000  17000  17000  17000   17000
   slin16 14500 14500 14500 14500 14500  8500 14500 14500 14500    14500  6000      -   14500   8500   8000   8000   8000   8000   8000    8000
  testlaw 15000 15000 15000 15000 15000  9000 15000 15000 15000    15000 17250  17000       -  17000  17000  17000  17000  17000  17000   17000
   slin12 14500 14500 14500 14500 14500  8500 14500 14500 14500    14500 14000   8000   14500      -   8000   8000   8000   8000   8000    8000
   slin24 14500 14500 14500 14500 14500  8500 14500 14500 14500    14500 14500   8500   14500   8500      -   8000   8000   8000   8000    8000
   slin32 14500 14500 14500 14500 14500  8500 14500 14500 14500    14500 14500   8500   14500   8500   8500      -   8000   8000   8000    8000
   slin44 14500 14500 14500 14500 14500  8500 14500 14500 14500    14500 14500   8500   14500   8500   8500   8500      -   8000   8000    8000
   slin48 14500 14500 14500 14500 14500  8500 14500 14500 14500    14500 14500   8500   14500   8500   8500   8500   8500      -   8000    8000
   slin96 14500 14500 14500 14500 14500  8500 14500 14500 14500    14500 14500   8500   14500   8500   8500   8500   8500   8500      -    8000
  slin192 14500 14500 14500 14500 14500  8500 14500 14500 14500    14500 14500   8500   14500   8500   8500   8500   8500   8500   8500       -


Don't forget to reboot after all this is done.

OK, let's begin setting up our FreePBX:

Go to Settings -> Asterisk SIP settings.



What we want to do there is Disallow Anonymous Inbound SIP Calls, enter our IP and our network, define a STUN server (although not really required since this is a public IP), and check the codecs we're planning on using. There's no reason to use codecs our SIP provider doesn't.


Submit and Apply.

Now let's go to Applications -> Extensions. There we select "Generic CHAN SIP device" from the drop-down menu and click on submit.


This one's real easy. We only need to specify the extension number and maybe the Display name. Everything can be left to defaults, except maybe the "secret" under "Device Options", which will be the password your VoIP phone or softphone will need to give to your server, so you might want to change it to something more memorable. Or maybe not.


Submit and Apply Config and repeat the process for as many extensions you want.

Next, we'll create an IVR. We need this so that when someone dials our number, Asterisk will know that it needs to wait for the caller to enter the extension. Ideally we'd have a recording of a person saying "Please enter an extension" or the like, but many companies just leave this without one

So go to Applications -> IVR and select "Add a new IVR". Select a name and a description for it and make sure that "Direct Dial" points to "Extensions". Make a few more choices about what Asterisk should do in the case of an invalid destination or a timeout and finally add all the extensions you added before on the bottom of the page, making sure that "Extensions" is selected under "Destination".


Submit and Apply Config.

Time to create our trunk. Go to Connectivity -> Trunks and select "Add SIP (chan_sip) Trunk".

For a trunk name, I usually select my SIP provider's name. Enter your DID number in the "Outbound CallerID" and select "Force Trunk CID" under CID options.

In Outgoing Settings, Trunk Name just put the same thing you put under General Settings. In the PEER Details box, you should put the settings provided by your VoIP provider. If you weren't provided with any, you could just ask them or google for them.


If your VoIP provider provided you with user (not peer!) connection parameters, this is what you need to enter in USER context and USER Details. Otherwise delete everything from there and leave them blank.


If you left USER context and USER Details blank, then you will need to enter a REGISTER string. That will be in the form of:



username:secret@VoIP_Provider_host/DID

Submit and Apply Config.

Now, on to creating an Inbound route. Go to Connectivity -> Inbound Routes. Here, any Description will do. Just make sure your DID number is in the "DID number" field, and on the bottom of the page under "Set Destination" select IVR and your recently created ivr name (mine was ivr1). You might also want to check Signal RINGING and put 1 in the "Pause Before Answer" field.

Submit and Apply Config.

Finally, let's set up our outbound route. Go to Connectivity -> Outbound Routes. Just put anything in the "Description" field and make sure you put your DID number in the Route CID field. Make sure you enter a dial pattern for this. 

Some examples to get you started can be found here, but you can get away with just entering a dot (literally the character .) in the "match pattern" field. That means that it will route everything. Finally, choose the trunk you created earlier under "Trunk Sequence For Matched Routes".


Submit and Apply Config.

Some VoIP providers require you to have actually activated your DID, or allowed your account to make calls, etc. If you've gone through the process and you're sure there's nothing else to do on that end, you're set. All that remains is for you to get a softphone or a VoIP phone, set it up and start doing calls over IP.




Note that you might need to dial using an international prefix!

3 comments:

  1. I am sure you might have a good experience using a traditional phone system, but trust me a VOIP virtual Phone system is no bad. In Fact, it will save you a lot of money, time, provide you with more flexibility and some amazing featuresPBX phone system

    ReplyDelete
  2. Hmm it seems like your blog ate my first comment (it was extremely long) so I guess I'll just sum it up what I wrote and say, I'm thoroughly enjoying your blog. I as well am an aspiring blog writer but I'm still new to everything. Do you have any suggestions for inexperienced blog writers? I'd certainly appreciate it.Cloud phone system experts Australia

    ReplyDelete
  3. Hi,
    Great Article! Thanks for providing good services. Great explanation of the fire hydrants. People always want to learn something by reading post Keep learning and keep sharing. Anyways, that's amazing Keep up the great work. All the best and You can also visit to the IPPBX/EPABX Suppliers for your project requirements.

    ReplyDelete