[Nexus 4 General] acegolfer:
PIAF (PBX in a flash) + AWS (Amazon Web Service) EC2

If you are making free GV calls using data, then you probably know that setting up an asterisk server is the best but also quite complicated. Thankfully, it just got a little easier because the PIAF team made the PIAF image available on AWS EC2 (a cloud based virtual machine).

Advantages over other asterisk/pbxes methods:

1. very small audio lag. Amazon servers have less latency than any other servers.

2. Since Amazon hosts your server, you don't pay any electricity cost. FYI, a PC running 24/7 costs about $15-20 a month.

3. The PIAF image (AMI) is already optimized: 1000MHZ + pre-installed asterisk and others. If you have used PIAF before, the whole setup process will take less than 30 minutes to complete.

4. You can create a backup image at any time and restore it later.

Disadvantages:

1. EC2 is only free for the 1st year. See the terms carefully to understand what is truly free. Use http://mikekhristo.com/ec2-ondemand-vs-reserved-instance-savings-calculator/ to estimate the cost after the 1st year. After the 1st free year is up, you can port the image to another AWS account.

2. Added security risk. Since EC2 is not in your network, it needs to open 22 (SSH), 80 (WEB) ports for you to access the server to configure. To overcome this issue, restrict who can gain access by known IP addresses from AWS.

3. In addition to some linux knowledge (PIAF runs on CentOS), you also need to learn how AWS works. Personally, I consider this as a plus.

Instructions (estimated minutes to complete in parenthesis, if you have used PIAF before):

1. Launch PIAF image in AWS EC2. (10 minutes)

Detailed instruction: http://nerdvittles.com/?p=5060

updated: there are 2 versions of PIAF: purple uses asterisk 1.8 and green uses asterisk 11 (beta). I am using PIAF-Green which supports silk codec.

2. Configure PIAF using Web GUI. (10 minutes)

Once PIAF is up and running, from your web browser, enter the Elastic IP address (given by AWS) to access web GUI.

2.1. Settings>Asterisk SIP settings>NAT settings. Click "Auto Configure" It will fill out the IP addresses. If you reboot, localnet address may change. You may use "10.0.0.0/8" instead.

* Whenever you make a change in Web GUI, scroll down and click submit. Then "Apply Config" red button will appear at the top. Click it occasionally to reload newly submitted configurations.

2.2. Settings>Asterisk SIP settings>Audio codecs. Select the codecs and reorder. (SILK codec will not show up here.)

2.3. Applications>Extensions. Add new SIP extensions. User extension and the secret are the username and the password you will use in your sip client to register with PIAF. Select nat=yes.

2.4. Other>Google Voice. Fill out your GV information. Asterisk must be restarted to take it into effect. In Web GUI, Admin>Asterisk CLI, execute "core restart gracefully" Once restarted, you can start making outbound GV calls from a registered phone. (Alternatively, you can use "simonics GVGW" service and add it as a sip trunk.)

2.5. Connectivity>Inbound routes. Add your GV number as DID number. Scroll down and set destination as your extension you created in #2.3.

2.6. From Google Voice webpage, confirm that Google Voice forwards all the incoming calls to gchat.

2.7. Register your sip client (such as csipsimple) with your PIAF server. The server address is the "elastic IP" address assigned by AWS.

Test in/out calls before going to the next step.

3. (optional) Add G729 codec. (5 minutes) (See post #2 for adding silk codec, which I'm now using for both wifi/3g.)

G729 codec is one of the best codecs for mobile connection. SSH to your PIAF EC2. In linux CLI, execute

cd /usr/lib/asterisk/modules
wget http://asterisk.hosting.lv/bin/codec_g729-ast18-icc-glibc-x86_64-core2.so
amportal restart

To check whether you added G729 properly, execute in asterisk CLI

core show translation recalc 100

Look for G729 line and check they are not blanks.

Source: http://asterisk.hosting.lv/

4. (optional) Enable TCP transport to save phone battery. (5 minutes)

In my informal testing, TCP battery consumption is half of UDP's.

From Web GUI, asterisk SIP settings>Other SIP settings, add the following 2 lines.

tcpenable = yes
tcpbindaddr = 0.0.0.0

Go Applications>Extensions and change transport to "TCP."

Next, you need to open TCP port 5060 in both EC2 and linux. For EC2, modify the security group. For linux, SSH to your PIAF

nano /etc/sysconfig/iptables

add the following line and save (ctrl-o) and exit (ctrl-x).

iptables -A INPUT -p tcp -m tcp --dport 5060 -j ACCEPT

restart iptables in linux CLI

service iptables restart

Use TCP transport in your sip client to connect to PIAF.

Tips/Tricks and Troubleshooting will be in the next posts.

If you couldn't understand the installation steps, check out a fellow's post. He provided several installation tips. http://xdaforums.com/showpost.php?p=41412908&postcount=184