[GUIDE] Setup Your Own Asterisk Server With Google Voice on Amazon EC2

Search This thread

ryuker

Member
Sep 15, 2011
42
11
I posted this in the PIAF thread since I used that method but this will help you guys as well.


Nexus 4 SIP echo fix - It's pretty bad for many users but this solved it 100% for me



It worked for me and I tested numerous different setting and configurations along with measuring my latency to ensure it works. YMMV but it's easy to try. At first I thought it was a Latency issue since echo didn't occur over wifi but with ping times lower than 60ms I still got echo over 3g without this method.

I'm using the silk codec(Silk 24 wifi/Silk 12 or 16 over 3g/4g); YMMV with other codecs.



*Before starting*

Root your phone, flash radio .27 or .33 if your on T-mobile or in Canada: We want to enable Nexus 4g! 3g is usually fine but 4g tends to have significantly lower latency(3G: 50-70ms versus 4g: 20-40ms). Sometimes my 3g speed was fine but latency sucks(100-250+ms)....3g has enough speed for VoIP but any latency issues/spikes/jumps will ruin a call.

This is a good guide to follow: Hippowise"s guide


For the first few steps plus a audio fix some users encountered with the radio downgrade; there are 2 scripts you can run via any terminal emulator app scripter(I used this $Scripter). The actual Script to be run can be found on XDA in the nexus 4 LTE thread(download or save them as txt files). The XML file I suggest editing your self(I just replaced all instances of epc.t-mobile with fast.t-mobile for T-mo users).

If said "scripting...wut?" just follow Hippowise's guide to the tee. Scripting is just faster/easier.

It took a few days for my 4g/LTE to kick in so be patient; It's worth the trouble!



**Now to the guide**


First, get the Faux kernel for Nexus 4 or use another kernel that has applied his patch.

2nd, get his apps from the Play store(they cost money but worth it): Faux Speakers and Faux Sound: Configure them for "voice" and "quality" respectively(you can adjust on your own from there, I upped the gain a bit).

3rd
, Use Csipsimple and enable "Software volume control" instead of the default android/os/hardware based volume/gain control. I wonder if this bypasses Faux and puts volume control solely in the hands of Csipsimple. I would do 1-3 steps anyway because it fixes the SQ issues in general with the nexus 4.

4th
. Enable Echo cancellation; until I did the previous steps, echo cancelation didn't work at all: YMMV.

I choose Echo mode Webrtc becuase Speex echo cancellation didn't work for me. If your codecs are different the other choices or auto might work better. Experiement.

5th: *Optional*

Noise Cancelation: Worked so-so....didn't need so I turned off
Voice Detection: I didn't like it but experiement.

Compact SIP packets: I use it, optional
STUN: I turned it on, I don't think it will hurt.

Audio troubleshooting in the Csip menu has tons of options to mess with. If all else fails, read some guides and experiment. I didn't need to chance anything here but some of it looks promising and has some fixes for specific models like the galaxy.


6TH: ??????

7th: Latency

Get Speedtest app from the play store and test your speed. In some areas over 3g I would get decent down/up speeds but godawful latency (300ms+ :eek: ). If your 3g latency consistently sucks, do the 4g fix for the nexus; Much better latency and I always get 4g in most places on T-mobile.....rural areas might be screwed on getting 4g although I noticed my 3g speeds increased overall after the fix.

8th

Finished; report back in the thread and tell me if it helped!! And if anybody knows a good I.T. position open for a VoIP office/call center; let me know cause I'm quitting mine. ;)
 
Last edited:

ftherese

New member
Sep 18, 2012
2
0
Thanks a lot for the config - "one" lingering issue for me

extensions.conf

Code:
[general]
autofallthrough=yes

; If an unauthenticated request some how gets through, send them to free 411.
[default]
exten => 411,1,Answer()
same => n,Dial(Motif/google/1800...@voice.google.com)

[local]
exten => _1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
exten => _XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
exten => _+1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)

[incoming-motif]
exten => s,1,NoOp()
 same => n,Set(crazygooglecid=${CALLERID(name)})
 same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
 same => n,Set(CALLERID(all)=${stripcrazysuffix})
 same => n,Dial(SIP/USERNAME,20,D(:1))

I am using this set up on my home asterisk setup, connecting with my android phone running sipdroid. Calling out works just fine, but when incoming calls ring my sipdroid, and I answer them I get "no data," while the calling phone just continues ringing until it gets to Google Voice-mail. I finally, today, had the idea of dialing "1" on my sipdroid after answering the call (even though there is no voice prompt or anything) and, voila it works. I thought that was strange because the Dial command under incoming-motif adds a D:)1), and that comes across in the log as well:

Code:
 -- Executing [s@incoming-motif:1] NoOp("Motif/+XXXXXXXXXXXX", "") in new stack
    -- Executing [s@incoming-motif:2] Set("Motif/+XXXXXXXXXX", "crazygooglecid=+XXXXXXXXX@voice.google.com/srvenc-92PWyN+7+//TmnbqAeG1ZyZUOAkykV8i") in new stack
    -- Executing [s@incoming-motif:3] Set("Motif/+XXXXXXXXXX", "stripcrazysuffix=+XXXXXXXXXX") in new stack
    -- Executing [s@incoming-motif:4] Set("Motif/+XXXXXXXXX", "CALLERID(all)=+XXXXXXXXX") in new stack
    -- Executing [s@incoming-motif:5] Dial("Motif/+XXXXXXXXXX", "SIP/ftherese,20,D(:1)") in new stack
  == Using SIP RTP CoS mark 5
    -- Called SIP/ftherese
    -- SIP/ftherese-00000000 is ringing
    -- SIP/ftherese-00000000 is making progress passing it to Motif/+XXXXXXXXXXX
[Sep 14 22:43:00] NOTICE[19355][C-00000000]: chan_motif.c:1636 jingle_indicate: Don't know how to indicate condition '14'
    -- SIP/ftherese-00000000 answered Motif/+XXXXXXXXXXX
    -- Sending DTMF '1' to the calling party.
    -- Locally bridging Motif/+XXXXXXXXXXXX and SIP/ftherese-00000000
  == Spawn extension (incoming-motif, s, 5) exited non-zero on 'Motif/+XXXXXXXXXXX'

Why do I have to dial "1" in my sipdroid to connect the call?
 
Last edited:

omegatotal

Member
Jun 22, 2012
12
1
So has anyone had any luck figuring out the google voice motif timeout issue where it will not detect the connection status of the chan_motif module??

I am leaning towards just scripting an automated test call to something like 909-390-0003 (loopback audio test?) and if it fails to connect reload the chan-motif module (I can confirm that this call is passed and auto answered :)

Code:
   -- Called Motif/gmailtunnel/19093900003@voice.google.com
    -- Motif/19093900003@voice.google.com-4f30 is proceeding passing it to SIP/5003-00000001
    -- Motif/19093900003@voice.google.com-4f30 answered SIP/5003-00000001

but I suck at scripting :/

---------- Post added at 08:36 PM ---------- Previous post was at 08:03 PM ----------

Also a note on the costs

If you are running a regular m1-micro instance without reserving up front, thats $14.64/mo unless you qualify for the free tier which gives you a discount of $-16.84/mo

EBS Volumes, elastic IP's and iop's are extra but trivial, like a few dollars a month for 20GB and 10 iops/sec average over the month

data transfer is stupid cheap too like pennies per gb

if you reserve upfront the m1.micro for 1 year, costs goes down to an effective monthly cost of like 10.71 however you get next to no free tier discount if you choose this and there is a $23 upfront setup fee for 1 year,

REF:
http://calculator.s3.amazonaws.com/calc5.html
 

davidnewton

Member
Jan 5, 2014
23
4
I got the same problem as this. Any solution?

I am using this set up on my home asterisk setup, connecting with my android phone running sipdroid. Calling out works just fine, but when incoming calls ring my sipdroid, and I answer them I get "no data," while the calling phone just continues ringing until it gets to Google Voice-mail. I finally, today, had the idea of dialing "1" on my sipdroid after answering the call (even though there is no voice prompt or anything) and, voila it works. I thought that was strange because the Dial command under incoming-motif adds a D:)1), and that comes across in the log as well:

Code:
 -- Executing [s@incoming-motif:1] NoOp("Motif/+XXXXXXXXXXXX", "") in new stack
    -- Executing [s@incoming-motif:2] Set("Motif/+XXXXXXXXXX", "crazygooglecid=+XXXXXXXXX@voice.google.com/srvenc-92PWyN+7+//TmnbqAeG1ZyZUOAkykV8i") in new stack
    -- Executing [s@incoming-motif:3] Set("Motif/+XXXXXXXXXX", "stripcrazysuffix=+XXXXXXXXXX") in new stack
    -- Executing [s@incoming-motif:4] Set("Motif/+XXXXXXXXX", "CALLERID(all)=+XXXXXXXXX") in new stack
    -- Executing [s@incoming-motif:5] Dial("Motif/+XXXXXXXXXX", "SIP/ftherese,20,D(:1)") in new stack
  == Using SIP RTP CoS mark 5
    -- Called SIP/ftherese
    -- SIP/ftherese-00000000 is ringing
    -- SIP/ftherese-00000000 is making progress passing it to Motif/+XXXXXXXXXXX
[Sep 14 22:43:00] NOTICE[19355][C-00000000]: chan_motif.c:1636 jingle_indicate: Don't know how to indicate condition '14'
    -- SIP/ftherese-00000000 answered Motif/+XXXXXXXXXXX
    -- Sending DTMF '1' to the calling party.
    -- Locally bridging Motif/+XXXXXXXXXXXX and SIP/ftherese-00000000
  == Spawn extension (incoming-motif, s, 5) exited non-zero on 'Motif/+XXXXXXXXXXX'

Why do I have to dial "1" in my sipdroid to connect the call?


I have exactly the same problem. If I use CSipSimple or Linphone, then there is no such problem. Probably SipDroid has some issues?
 

bluespire

Senior Member
Feb 26, 2009
123
17
howdy all.

With the impending XMPP shutdown on May 15h, does this mean this thread basically is kaput? Are there any alternate methods to get SIP working post-shutdown?

SIP with GV? Probably not. I had good luck with Anveo. They are really cheap. US Phone # + e911 was about $5/month IIRC. I'll be moving back to that when GV quits. They offer Fax and Texting, as well, but last I checked their texting service was provided by a UK company, so no US number for that. If that doesn't both you then I would forge onward. There a number of other providers of course, my preference was Anveo.

I think that it's quite possible that Google will unveil a pay service to keep XMPP enabled on a per account basis, or maybe it will still be available with a business account. I guess we will have to see.
 
  • Like
Reactions: jauling

tech128

Senior Member
Oct 14, 2012
177
118
I don't use this method any more. But dslreport ppl say that Google XMPP still works in some cases, and I think this method should work.

It works in all cases. If it doesn't work for you, that means you need to troubleshoot.

It's a setting on google's server and/or your server.

Granted the new Asterisk 11 & 12 seem to be very retarded with respects to GV.

I was able to dial out no problem with it, but calls in wouldn't even get to the asterisk server for some reason. Very odd.

And don't get me started on this "motif" stuff they have now. Very confusing. gtalk and jabber were soooooooooooo much better/easier.

No such issues with 1.8.x
 

omegatotal

Member
Jun 22, 2012
12
1
The problem with the current setup ( I use it ) is that if you sign into the email account it has a high probability of changing the destination for the incoming calls to the email client and the motif plugin for freepbx does not have a configuration option for timeouts

the best thing you can do is just script an rcon to force a reload if there are no active calls every night (which I have been to lazy to do)

It works in all cases. If it doesn't work for you, that means you need to troubleshoot.

It's a setting on google's server and/or your server.

Granted the new Asterisk 11 & 12 seem to be very retarded with respects to GV.

I was able to dial out no problem with it, but calls in wouldn't even get to the asterisk server for some reason. Very odd.

And don't get me started on this "motif" stuff they have now. Very confusing. gtalk and jabber were soooooooooooo much better/easier.

No such issues with 1.8.x
 

tech128

Senior Member
Oct 14, 2012
177
118
The problem with the current setup ( I use it ) is that if you sign into the email account it has a high probability of changing the destination for the incoming calls to the email client and the motif plugin for freepbx does not have a configuration option for timeouts

the best thing you can do is just script an rcon to force a reload if there are no active calls every night (which I have been to lazy to do)

Well if you're having issues with the email client overriding the incoming calls then that's a problem with the priority setting for motif.

It probably sets it below the priority for the email client.

The simonics gateway ran into that problem as well and managed to change the priority higher than the email client's.

Here is the relevant message: https://simonics.com/2012/11/gv-gateway-registration-open-new-features/

So if you can set the priority with motif or whatever they're using atm, then you should be set.
 

tarun1188

Member
Feb 26, 2011
11
1
Unable to install asterisk

Hi, I followed all the steps but when i try to stop/start the asterisk server it says:
Stopping Asterisk PBX: asterisk
No /usr/sbin/asterisk found running; none killed. [ OK ]​

* Starting Asterisk PBX: asterisk Privilege escalation protection disabled!
Illegal instruction​

Also the contents of /var/run/asterisk is empty.

Can anyone help me setting this up. Let me know if i have to provide any more information.

Thanks in advance
 

Top Liked Posts

  • There are no posts matching your filters.
  • 19
    EDIT: THIS SETUP IS FOR PEOPLE WHO WANT A RELIABLE ALTERNATE TO USING MAIN STREAM SERVICES. THIS IS YOUR OWN SERVER -- AND YOU WILL BE THE ONLY ONE USING IT AS OPPOSED TO HUNDREDS OR THOUSANDS OF OTHER USERS. I'VE BEEN USING THIS FOR SIX MONTHS WITH NO ISSUES. BEFORE THIS I WAS USING PBXES.ORG AND THE SERVICE WAS 'OK' AND I MISSED SOME CALLS. I'VE HAD ZERO ISSUES WITH THIS SETUP.

    A few people have asked me for a guide on howto setup Asterisk on an Amazon EC2 micro instance for their Nexus 4. Amazon offers a free micro instance for one year (new signups). Even after your first year it's pretty cheap to keep it running. Amazon's bandwidth will be faster than setting up Asterisk on your own home server (in most cases).

    Once you have the server up and running you can easily configure your favorite SIP client on your Nexus 4 to enjoy free calling with your Google Voice account. This is particularly useful for people such as myself who are on the $30 T-Mobile plan.

    As a bonus, I've also included the steps to setup a PPTP VPN.

    This guide assumes that you've already setup your AWS account and figured out how to set the security group. You will need to open some ports (TCP: 22, 1723, 5060. UDP: 5060, 10000-20000)

    Step 1. Goto: http://uec-images.ubuntu.com/releases/10.04/release/ and pick the t1.micro instance (ebs 64 bit) for the region that you setup in AWS. Launch this instance (there is a button) and get it working with the security group that you configured. After it's launched you need to setup an Elastic IP and associate it with the instance. After that go ahead and log into your new micro instance server. Once you get to this point, then you can continue with the guide. There are TONS of resources (including youtube videos) on how to get to this point. It's not rocket science.

    Step 2. Setup firewall settings for pptpd and asterisk. Lucid also has firewall settings that need to be adjusted.

    Code:
    #Uncomplicated Firewall
    sudo ufw enable
    sudo ufw allow 22/tcp
    sudo ufw allow 1723/tcp
    sudo ufw allow 5060/tcp
    sudo ufw allow 5060/udp
    sudo ufw allow 10000:20000/udp
    
    #check status
    sudo ufw status
    
    #edit /etc/default/ufw and enable forward policy
    DEFAULT_FORWARD_POLICY="ACCEPT"
    
    #edit /etc/ufw/sysctl.conf and uncomment
    net/ipv4/ip_forward=1
    
    #edit /etc/ufw/before.rules and add this after the header comments
    
    ---<BEGIN>--- (DON'T COPY THIS LINE)
    # nat Table rules
    *nat
    :POSTROUTING ACCEPT [0:0]
    
    # Forward traffic through eth0.
    -A POSTROUTING -o eth0 -j MASQUERADE
    
    # don't delete the 'COMMIT' line or these nat table rules won't be processed
    COMMIT
    ---<END>--- (DON'T COPY THIS LINE)
    
    #disable and enable to apply changes
    sudo ufw disable && sudo ufw enable

    Step 3. Recompile Kernel. The default kernel is set at 100HZ timing, this will give you HORRIBLE VOIP quality. The kernel needs to be recompiled to 1000HZ timing.

    Code:
    # Make yourself root
    sudo su
    
    # Update source list:
    aptitude update
    
    # Upgrade everything:
    aptitude upgrade 
    
    # Install dependencies:
    apt-get build-dep linux-image-$(uname -r)
    apt-get build-dep linux
    apt-get install fakeroot build-essential
    apt-get install crash kexec-tools makedumpfile kernel-wedge
    apt-get install libncurses5 libncurses5-dev
    apt-get install libelf-dev asciidoc binutils-dev kernel-package
    apt-get install git-core
    
    cd /usr/src
    git clone git://kernel.ubuntu.com/ubuntu/ubuntu-lucid.git 
    cd ubuntu*
    git checkout --track -b ec2 origin/ec2
    fakeroot debian/rules clean
    fakeroot debian/rules editconfigs
    
    # Configuration window should now appear, do the following:
    
    Select YES
    
    # Navigate to:
    Processor type and features -> Timer frequency
    # Select the 1000HZ frequency 
    Exit 
    Exit 
    Yes (Save)
    
    #After saving and returning to prompt it may ask you to do it again for i386, select yes and repeat!

    This next command will take about 7 hours to recompile the kernel. But, there is a shortcut. Amazon charges by the minute for each instance type that you use. I recommend shutting down your instance at this point and changing it to a m1 extra large instance type (this will cost you about 70 cents). This will increase your micro instance from:

    613 MiB memory
    Up to 2 EC2 Compute Units (for short periodic bursts)
    EBS storage only
    32-bit or 64-bit platform
    I/O Performance: Low
    EBS-Optimized Available: No
    API name: t1.micro

    to:

    15 GiB memory
    8 EC2 Compute Units (4 virtual cores with 2 EC2 Compute Units each)
    1,690 GB instance storage
    64-bit platform
    I/O Performance: High
    EBS-Optimized Available: 1000 Mbps
    API name: m1.xlarge

    The compiling time will be reduced to about 25 minutes.Once you got the instance backup with the m1.xlarge instance, continue like so:

    Code:
    sudo su
    cd /usr/src/ubuntu*
    fakeroot debian/rules binary 
    
    #Check if your deb files were created
    cd ..
    ls *.deb
    
    #install new kernel
    #IF A GRUB MENU POPS UP PICK PACKAGE VERSION
    sudo dpkg -i linux-*.deb

    Then shutdown your system again and change it back to a micro instance. Then boot it back up.

    #Check your new Kernel version
    Code:
    uname -r
    
    #Check if Kernel HZ value change persisted:
    cat /boot/config-`uname -r` | grep HZ
    
    #If value 1000HZ=yes then you did it right!

    Step 4. Install Asterisk 11

    Code:
    #become root
    sudo su
    
    # Install dependencies:
    apt-get install libiksemel-dev libsqlite3-dev libssl-dev libnewt-dev libxml2-dev  
    
    #get source
    #note: dahdi needs to be installed to compile and install libpri -- we don't really need it for any other reason
    
    cd /usr/src/
    wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
    wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz
    wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz
    
    #extract source
    
    tar zxvf dahdi-*
    tar zxvf libpri-*
    tar zxvf asterisk-11*
    
    #resolve error for compiling dahdi
    
    ln -nsf /usr/src/linux-headers-`uname -r`/include/asm-x86 /usr/src/linux-headers-`uname -r`/include/asm
    
    #install dahdi
    
    cd /usr/src/dahdi*
    make && make install && make config
    
    #install libpri
    
    cd /usr/src/libpri-1.4*
    make && make install
    
    #install asterisk
    #note: once the menu pops up check and make sure you have chan_motif and xmpp (should have a * next to them)
    
    cd /usr/src/asterisk*
    ./configure && make menuselect && make && make install && make config && make samples

    Step 5. Configure Google Voice

    Backup original conf files (you should still be root)

    Code:
    cd /etc/asterisk
    cp extensions.conf extensions.conf.orig
    cp motif.conf motif.conf.orig
    cp sip.conf sip.conf.orig
    cp xmpp.conf xmpp.conf.orig

    New Config files compiled by jhax01 - GO TO POST #85 FOR MORE DETAILS. Now you will want to replace the following files with these (change USERNAME to whatever you want and make sure you google account info is correct):

    #extensions.conf - Don't forget the USERNAME on the last line
    Code:
    [general]
    autofallthrough=yes
    
    ; If an unauthenticated request some how gets through, send them to free 411.
    [default]
    exten => 411,1,Answer()
    same => n,Dial(Motif/google/1800...@voice.google.com)
    
    [local]
    exten => _1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
    exten => _XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
    exten => _+1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
    
    [incoming-motif]
    exten => s,1,NoOp()
     same => n,Set(crazygooglecid=${CALLERID(name)})
     same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
     same => n,Set(CALLERID(all)=${stripcrazysuffix})
     same => n,Dial(SIP/USERNAME,20,D(:1))

    #motif.conf
    Code:
    [google]
    context=incoming-motif
    disallow=all
    allow=ulaw
    connection=google

    #sip.conf - Pay attention to externhost, secret, and USERNAME
    Code:
    [general]
    allow=all
    allowguest=no
    nat=force_rport,comedia
    tcpbindaddr=0.0.0.0
    tcpenable=yes
    
    externhost=ELASTICIP
    localnet=10.0.0.0/8
    
    [USERNAME]
    type=peer
    secret=PASSWORDYOUGENERATE
    host=dynamic
    context=local
    transport=udp,tcp

    #xmpp.conf
    Code:
    [general]
    [google]
    type=client
    serverhost=talk.google.com
    username=YOUREMAIL@GMAIL.COM
    secret=GMAILPASSWORD
    priority=100
    port=5222
    usetls=yes
    usesasl=yes
    status=available
    statusmessage="VOIP"
    timeout=5

    Code:
    #
    # Stop/Start asterisk
    #
    sudo /etc/init.d/asterisk stop
    sudo /etc/init.d/asterisk start

    If everything went at planned your Asterisk Server with Google voice should be working, you can now login with your SIP client utilizing the extension username and password that you chose in sip.conf.

    BONUS STEP. PPTPD VPN

    install (make sure you are still root)

    Code:
    apt-get install pptpd

    Now take the following code and copy it into a script and execute as root:

    Code:
    echo "localip 10.40.1.1" >> /etc/pptpd.conf
    echo "remoteip 10.40.1.20-50" >> /etc/pptpd.conf
    echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd
    echo "ms-dns 8.8.4.4" >> /etc/ppp/options.pptpd
    echo "ms-dns 172.16.0.23" >> /etc/ppp/options.pptpd
    
    pass=`openssl rand 8 -base64`
    if [ "$1" != "" ]
    then pass=$1
    fi
    echo "VPN pptpd ${pass} *" >> /etc/ppp/chap-secrets
    
    echo -e "VPN service is installed, your VPN username is \033[1mVPN\033[0m, VPN password is \033[1m${pass}\033[1m"

    Done. Just a reminder, do not upgrade the system to Ubuntu 12.04 or you will lose the recompiled Kernel. If you update the kernel you will need to recompile...
    4
    Ok, so now I know more about Asterisk then originally planned, but that 's not a bad thing...lol. I'll share a few of my findings to hopefully help others who give this a try.

    I did a lot of chasing to figure out what was wrong with my inbound calls, but as it turns out the solution was very simple. The short version is that my inbound call issues were tied directly to the Gtalk server. Setting Asterisk's priority to "1" made sure it was dead last when it came to initiating any inbound connections whatsoever. And, in fact, any inbound calls would terminate at the Gtalk server and never even hit Asterisk's horizon. It all worked initially for me because I wasn't logged in anywhere at first, but when I booted up the N4, it auto logged into Gtalk. So, if you're using a dedicated email/voice acct, you may not run into this issue, but for me, the fix was as simple as setting the priority in XMPP.conf to 100. Just FYI - A side effect of this is most likely to be that now all inbound connections terminate at Asterisk and Gtalk doesn't get a chance at them.

    As a cautionary item, setting sip.conf to allow guests is a bit dangerous unless you define their limitations or are on a local network behind a hardware firewall. The current one is written in this guide will allow *anyone* to utilize your PBX and by extension, your google voice account. If your GV account is set to auto refill with $$....well, you get the idea... Additionally, for this particular application, most of the parameters specified in the [general] section of sip.conf aren't needed. Just specify the no guest thing and any protocols you would like to use.

    There is also some danger to use the [default] section in extensions.conf if you are trying to operate privately as Asterisk will look there to dial whenever it receives an undefined request. This again exposes you to potential mischief.

    One other tip is on your outbound calls you can define multiple formats so you don't have to change the way you normally dial, in addition to local calls, like so:


    exten => _1XXXXXXXXXX,1,Dial(Motif/USERNAME/${EXTEN}@voice.google.com,,r)

    ** this covers dial requests formatted as 1-555-444-1234

    exten => _XXXXXXXXXX,1,Dial(Motif/jhaxgvsip/${EXTEN}@voice.google.com,,r)

    ** this covers dial requests formatted as 555-444-1234

    etc, etc....

    Thanks again, errorcod3! I never would have even attempted this if it weren't for your guide! :D
    2
    This worked for adding call recording. All calls are recorded and saved to: /var/spool/asterisk/monitor

    replace extensions.conf with this (Don't forget to change USERNAME on last line):

    Nice, nice, nice....

    Haven't been able to get TLS working over SIP, but I did add an IAX channel which allows md5 and rsa authentication out of the box. Apparently IAX coupled with G729 has much lower latency and bandwidth requirements than a SIP connection. Call quality has been very good for me, but I haven't had a truly dodgy connection to know how well it works. The only drawback is that it is UDP, so there is potentially the battery issue if your keep alive intervals are short. Set up couldn't be simpler, all that needs to be done is to mod iax.conf like so:

    Code:
    iax.conf
    
    [general]
    autokill=yes
    allow=all
    jitterbuffer=yes
    
    [USERNAME]
    type=friend
    auth=md5,rsa
    secret=YOURPASSWORD
    host=dynamic
    context=local

    USERNAME and YOURPASSWORD obviously need to be different than the ones used in sip.conf. context=local points the outbound calls @ the google voice extensions. Now the only other thing to do is add inbound support in extensions.conf:

    Code:
    extensions.conf
    
     same => n,Dial(IAX2/IAXUSERNAME,20,D(:1))

    Add the above line just underneath the last line under [incoming-motif] in extensions.conf.

    You will also need to open port 4569/udp in your security group as well as ufw.

    After modding, you may need to reboot the EC2 server to get the IAX channel functioning properly. Simply restarting Asterisk didn't work for me.

    I'm using Zoiper as an IAX client. Now on an inbound call, Asterisk will ring both the SIP and IAX client concurrently. Obviously you don't want to be logged in to both on the same phone at the same time as you will get a double ring.

    I also have multiple Google Voice numbers via the same client functioning. Inbound calls from any number of GV#s ring the phone just fine. Selection of which number to use for the outbound calls is made through some case management of the exten commands. It seems that Asterisk is willing to ignore the * and + sign...so one, both, or a combo is used to select the outbound phone line. I'll post up what I have tomorrow. The only thing that is lacking is parsing the inbound call to show which phone line is being used. I'm sure someone around here will be able you figure that out quite easily.
    2
    In the battle to get this working for myself, I happened to learn a few things proving that you can, in fact, teach an old dog new tricks...lol. I'm going to add my *.conf here with a bit of explanation that may help others understand what's going on with each of the files. I certainly didn't understand at first, but as I researched my issues a little deeper, the light bulb slowly started to come on.

    I'll start with "motif.conf"...the sole purpose here is to let Asterisk know that we are intending to utilize Google as a conduit for communication and that calls will originate or terminate in the context defined in motif.conf. We also make sure that Asterisk knows to only use the ulaw protocol as that is the only way Google Voice knows how to communicate.

    Code:
    motif.conf
    
    [google]
    context=incoming-motif
    disallow=all
    allow=ulaw
    connection=google

    Next is xmpp.conf - This is where we define the resource that is available to Asterisk to accomplish the connection to the google account. As errorcod3 stated - make sure you put in the correct gmail info.... Also note that we are generically defining a connection type below and coupling this with the context of "incoming-motif" above gives us a mechanism for making and receiving calls. Essentially, the "how" that Asterisk will apply to make or receive a call. Additionally, make sure you set the priority high if you are using a google account that make be logged into Gtalk somewhere else. If it is set to 1 under those circumstances, the call will never make it to Asterisk.



    Code:
    xmpp.conf
    
    [general]
    [google]
    type=client
    serverhost=talk.google.com
    username=YOUREMAIL@GMAIL.COM
    secret=GMAILPASSWORD
    priority=100
    port=5222
    usetls=yes
    usesasl=yes
    status=available
    statusmessage="VOIP"
    timeout=5


    Now we can define our soft phone or SIP client. This is our connection into Asterisk just as motif/xmpp are Asterisk's connection to google chat.


    Code:
    sip.conf
    
    [general]
    allow=all
    allowguest=no
    nat=force_rport,comedia
    tcpbindaddr=0.0.0.0
    tcpenable=yes
    
    externhost=EXTERNALIP
    localnet=IFCONFIG/SUBNETMASK
    
    [USERNAME]
    type=peer
    secret=PASSWORDYOUGENERATE
    host=dynamic
    context=local
    transport=udp,tcp

    Here's where I differ from errorcod3's methodology a bit. In the general section, I'm telling Asterisk that it's ok to accept any compression protocols for the SIP => Asterisk portion of the connection with "allow=all". The only drawback to this is that if the compression type is not supported or compiled with Asterisk, then it will attempt to pass through the protocol rather than transcode it. Gtalk itself supports several types, but Google Voice, on the other hand, only supports ulaw. So if it passes through something unsupported there will be no audio. The upside is that it allows you to switch protocols on the fly easily. *allowguest=no* - this one is important if your server is in the open (i.e. - EC2). Leaving it out, or setting the parameter to *yes* will allow anyone to use your PBX to dial out unconditionally as long as they know the IP. The next lines allow TCP as a protocol and set nat to yes, essentially. Everything after USERNAME defines your actual soft phone connection and lets Asterisk know that when you initiate a call, it should use the context *local* to route it.


    Lastly, we have extensions.conf. This is where we set our dial plan for Asterisk or the "conditions" that tell it to do what and when.

    extensions.conf

    Code:
    [general]
    autofallthrough=yes
    
    ; If an unauthenticated request some how gets through, send them to free 411.
    [default]
    exten => 411,1,Answer()
    same => n,Dial(Motif/google/1800...@voice.google.com)
    
    [local]
    exten => _1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
    exten => _XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
    exten => _+1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
    
    [incoming-motif]
    exten => s,1,NoOp()
     same => n,Set(crazygooglecid=${CALLERID(name)})
     same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
     same => n,Set(CALLERID(all)=${stripcrazysuffix})
     same => n,Dial(SIP/USERNAME,20,D(:1))

    Ok, line by line, this is what we are doing here.

    autofallthrough - we set this to yes so that if Asterisk runs out of things to do with an active connection or has problems, it will send a busy signal, or hang up, or whatever. Otherwise, it will just sit there will an open connection and wait for another extension to be dialed.

    [default] - This is what Asterisk will do if it receives a dial request from an un-authenticated guest. We already have it set to not allow guests, but just in case, if something gets through somehow, we are going to send them to free 411. It will effectively ignore any dial requests that are not made from the SIP client we define in sip.conf.

    [local] - think of this context as our outbound calls or the connection from your soft phone to the world. When you dial out, sip.conf points your request at the context of *local*, then under local Asterisk matches a formatting case to the appropriate extension. Then in the case of the above, Asterisk places the call through the "Motif" technology via the "google" account we defined in xmpp.conf.

    [incoming-motif] - This context handles our inbound calls from google voice by first stripping out everything but the phone number on the inbound transmission. Then, in the last line, it dials the soft phone defined in sip.conf to complete the connection.


    The above conf files will provide an audio only connection. I'm also currently working on adding TLS authentication for the SIP client instead of sending the user name and password in the clear and if the OP is in agreement, I will add the directions. (your authentication into google voice is already sent encrypted) Hope I didn't overstep my bounds... Just trying to help clarify what is going on for folks like myself who didn't have a clue at first. :D

    ---------- Post added at 10:49 PM ---------- Previous post was at 10:44 PM ----------

    Some people claim that simonics is more reliable than asterisk GV module and chan_motif. Haven't verified it myself though.

    In fact, I use both in my PIAF. If I call a 10 digit number, GV module places the call. If I call a 1+ 10 digit number, then GVGW (w/ a different GV number). No difference in call quality (tested with 2 N4's side by side).

    Oh, I see... As near as I can tell, reliability is more a function of your SIP client and it's ability to keep connected with the server. I haven't had any issues...so far anyway. :)

    Call quality-wise, I added g729 to my setup and am pretty happy with it so far.

    ---------- Post added at 10:55 PM ---------- Previous post was at 10:49 PM ----------

    In addition to what acegolfer said:
    As far as I know, it simplifies the process of using GV with VoIP devices. It also has Caller ID name lookup for incoming calls through your GV number, but I believe it's possible to add that functionality to Asterisk. If anything, I'm just enjoying the learning process involved with messing around with different Asterisk configurations B)

    Yep, you definitely can.... A couple other interesting things I came across are sending blocked calls to a privacy manager that requires them to input their number before it will complete the call & blacklists, etc.... Asterisk has a ridiculous amount of options....
    1
    No, I haven't tried it. Asterisk 11 supports G722. If anyone is interested in using it just add an allow=g722 to the sip.conf file under [general].

    Does Google Voice support G729?

    gtalk trunk only supports PCMU (g711 ulaw), which is used at PSTN. asterisk will transcode PCMU to other codecs such as G729.