Sunday, December 30, 2012

Using Google Voice as a landline

-->

Have you ever wanted to stop paying for a landline but didn't know how?  In this article I'll review the steps I used to configure a VoIP land line using a SIP interface through a Raspberry Pi based PBX with Freeswitch and Google Voice.  In other words, make free calls!  NOTE: You will not have 911/Emergency services with this solution!

I spent the better part of the weekend reading wiki's, blogs, manuals and other posts and had to piece them all together to get my own personal solution working.  I thought it would be useful to write it up and share my experiences.



I've tried to capture my steps as best as I could .  Please let me know if anything does not work or needs to be amended.

Things you'll need:
  1. Raspberry PI with "wheezy-raspbian" connected to your network.
  2. A SIP device or software, like XLITE.  I'm using an old Sipura SPA-2100.  One end connected to your physical phone line and the other to your network.
  3. A Google voice account.
  4. Test your Google voice account, try calling a number from the web UI.
  5. Log into Google Voice:
    • Click on Settings > Phones
    • Uncheck all phones
    • Check Google Chat
    • Log out of gmail ( Or turn off chat at the bottom of the gmail page)

Steps: (on your Raspberry Pi as root)
  • Install dependencies 
    • #apt-get install autoconf automake gawk g++ git-core libjpeg62-dev libncurses5-dev libtool make python-dev gawk pkg-config  libperl-dev libgdbm-dev libdb-dev libssl-dev
  • Download, Compile and install freeswitch. NOTE: This step takes a few hours to compile.  
    • #mkdir /usr/local/freeswitch 
      #useradd freeswitch -d /usr/local/freeswitch
      #chown -R freeswitch:freeswitch /usr/local/freeswitch
    • #cd /usr/local/src
      #git clone git://git.freeswitch.org/freeswitch.git
      #cd /usr/local/src/freeswitch
      #./bootstrap.sh && ./configure --prefix=/usr/local/freeswitch && make clean && make clean modwipe && make && make install
    • Make sure the following line is present and uncommented in /usr/src/freeswitch/modules.conf
      endpoints/mod_dingaling
      
      And build mod_dingaling:
      #make mod_dingaling-install
  • Make sure mod_dingaling is not commented out in file conf/autoload_configs/modules.conf.xml
    •  <load module="mod_dingaling"/>
  • Edit the conf/jingle_profiles/client.xml and replace all its contents with the following.  Then replace  only the highlighted fields with your Gmail username and password.
    • <include>
        <!-- Client Profile (Original mode) -->
        <!-- to use this profile take the x- away from the open and close tags so its <profile> and </profile> -->
      <include>
        <profile type="client">
          <param name="name" value="gtalk"/>
          <param name="login" value="YOUR_GMAIL@gmail.com/talk"/>
          <param name="password" value="GMAIL.PASSWORD"/>
          <param name="server" value="talk.google.com" />
          <param name="message" value="Thanks Google!" />
          <param name="dialplan" value="XML"/>
          <param name="context" value="default"/>
          <param name="exten" value="2001"/>
          <param name="rtp-ip" value="auto"/>
          <param name="auto-login" value="true"/>
          <param name="sasl" value="plain"/>
          <param name="server" value="talk.google.com"/>
          <param name="tls" value="true"/>
          <param name="use-rtp-timer" value="false"/>
          <param name="vad" value="none"/>
          <param name="candidate-acl" value="wan.auto"/>
          <param name="local-network-acl" value="localnet.auto"/>
       </profile>
      
      </include>
      

  • Start freeswitch manually and test module
    • #/usr/local/freeswitch/bin/freeswitch 
  • You should get a console like this:






























  • Try running reload mod_dingaling  if you entered the correct credentials and all was compiled 
  • correctly, you should see the following message:
  • 
    +OK Reloading XML
    +OK module unloaded
    +OK module loaded
    
    freeswitch@pbx> 2012-12-30 19:52:59.136376 [NOTICE] libdingaling.c:1674 XMPP server connected
    
    2012-12-30 19:52:59.356369 [NOTICE] libdingaling.c:1686 XMPP authenticated
    

  • Exit the freeswitch console using the shutdown command, and return to the shell prompt.
  • Edit the conf/directory/default.xml and replace all its contents with the following.  Then replace  only the highlighted fields with your SIP device IP address
    • <include>
        <!--the domain or ip (the right hand side of the @ in the addr-->
        <domain name="192.168.0.XXX">
          <params>
            <param name="dial-string" value="{^^:sip_invite_domain=${dialed_domain}:presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(*/${dialed_user}@${dialed_domain})}"/>
          </params>
      
          <variables>
            <variable name="record_stereo" value="true"/>
            <variable name="default_gateway" value="$${default_provider}"/>
            <variable name="default_areacode" value="$${default_areacode}"/>
            <variable name="transfer_fallback_extension" value="operator"/>
          </variables>
      
          <groups>
            <group name="public">
              <users>
                <X-PRE-PROCESS cmd="include" data="default/*.xml"/>
              </users>
            </group>
          </groups>
      
        </domain>
      </include>
      
      

  • Create a file called conf/directory/default/2001.xml and paste the following contents, replacing only the highlighted fields with any random password (save it for later) and your name, which will be used for caller id.
    • <include>
        <user id="2001">
          <params>
            <param name="password" value="MAKEUPONE"/>
            <param name="vm-password" value="1000"/>
          </params>
          <variables>
            <variable name="toll_allow" value="domestic,international,local"/>
            <variable name="user_context" value="default"/>
            <variable name="effective_caller_id_name" value="John Doe"/>
            <variable name="effective_caller_id_number" value="2001"/>
            <variable name="outbound_caller_id_name" value="$${outbound_caller_name}"/>
            <variable name="outbound_caller_id_number" value="$${outbound_caller_id}"/>
            <variable name="callgroup" value="default"/>
          </variables>
        </user>
      </include>
      

  • Login to your SIP (Or SIP software), and enter the following . (NOTE I will only demonstrate on the SPA-2100, other solutions will have different screens).  
    • In the proxy (or domain) type in the IP address or hostname of your freeswitch PBX.
    • The Display Name can be anything you want.
    • User ID should be 2001 (because that is what I set it to).
    • The passowrd  is from the one you made up above.

  • Start freeswitch on the command line /usr/local/freeswitch/bin/freeswitch
  • Save and reboot the SIP device.  You SIP device should now be registered. You can test by way of hearing a dial tone on your phone.
  • Open another login window to your PBX and leave the previous freeswitch console open in the the other window. We'll reference it later.
  • Edit the conf/dialp/default.xml and add the following, right after the "unloop" extension section.  Then replace only the highlighted fields with your SIP device IP address.
    •  <extension name="gvoice_in">
        <condition field="source" expression="^mod_dingaling$">
          <!--<action application="info" />-->
          <action application="log" data="CONSOLE GV CALL IN!" />
          <action application="log" data="CONSOLE ${destination_number}"/>
          <action application="start_dtmf" />
          <action application="set" data="execute_on_answer=send_dtmf 1@2001"/>
          <!--<action application="cidlookup" data="$1"/>-->
          <action application="set" data="hangup_after_bridge=true" />
          <!--<action application="set" data="originate_continue_on_timeout=true"/>-->
          <!--<action application="set" data="call_timeout=35"/>-->
          <action application="bridge" data="user/2001@192.168.0.XXX"/>
          <action application="answer"/>
        </condition>
      </extension>
      
      <extension name="gvoice_out">
        <condition regex="any">
          <regex field="destination_number" expression="^(\d{10})$" />
          <regex field="dialed_extension" expression="^\+1(\d{10})@voice.google.com$" />
          <regex field="destination_number" expression="\+1(\d{10})$" />
          <action application="set" data="hangup_after_bridge=true"/>
          <action application="set" data="ringback=${us-ring}"/>
          <action application="set" data="call_timeout=45" />
          <action application="ring_ready"/>
          <action application="bridge" data="dingaling/gtalk/+1$1@voice.google.com"/>
        </condition>
      </extension>
      
      
  • Edit the conf/autoload_configs/dingaling.conf.xml and replace all its contents with the following.  
    • <configuration name="dingaling.conf" description="XMPP Jingle Endpoint">
        <settings>
          <param name="debug" value="0"/>
          <param name="codec-prefs" value="PCMU"/>
        </settings>
      
        <X-PRE-PROCESS cmd="include" data="../jingle_profiles/*.xml"/>
      
      </configuration>
      
      
      
  • Go back to the freeswitch console window and type reloadxml  then  reload mod_dingaling 
  • Now you are can test making outgoing and receiving calls.
  • If all works to your satisfaction, its time to make freespace start automatically at boot time.
Creating a Freeswitch boot service
  • Create a new file called /etc/init.d/freeswitch paste the contents from this file.
#chown -R freeswitch:freeswitch /etc/init.d/freeswitch
#chmod +x /etc/init.d/freeswitch
#update-rc.d  freeswitch defaults
#/etc/init.d/freeswitch start


  • Reboot the pbx and check that the daemon started successfully and that everything is working.


Voice Codec Optimization
I found that the default codec causes outgoing calls to be choppy.  To fix this, I changed the default codec to PCMA.

Replace the following in conf/vars.xml


<X-PRE-PROCESS cmd="set" data="global_codec_prefs=G7221@32000h,G7221@16000h,G722,PCMU,PCMA,GSM"/>
<X-PRE-PROCESS cmd="set" data="outbound_codec_prefs=PCMU,PCMA,GSM"/>

with the following
<X-PRE-PROCESS cmd="set" data="global_codec_prefs=PCMA"/>
<X-PRE-PROCESS cmd="set" data="outbound_codec_prefs=PCMA"/>

Save the file and stop and start the service
#service freeswitch stop  && sleep 15 && service freeswitch start




34 comments:

  1. Thank you very much for your guide! I have tried it and it works great! I wouldn't have had a prayer of figuring all this out but this work as though a perfect recipe! I am excited about having my google voice on a real phone.

    ReplyDelete
  2. My pleasure. It took me awhile to get it right too. What frustrated me was that I could not find any sources which worked. That's what prompted me to write this up.

    ReplyDelete
  3. for a linux newbie .....

    how does one ..."Create a new file called /etc/init.d/freeswitch " and then "paste the contents from this file."....

    ReplyDelete
  4. Sorry I didn't go into that detail in the blog itself. I'll create a section for using the vi command later but in the meantime.

    - Use the vi command (vi /etc/init.d/freeswitch).
    - hit the "i" key (for insert mode) then paste the contents then hit the "Esc" key.
    - To save, hold the "Shift" key while pressing "Z" and "Z" (twice).

    Hope this helps.

    ReplyDelete
  5. I updated the audio codec to compensate for choppy audio. Please see the "Voice Codec Optimization" section.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Can you please upload an image that i can burn it at SD directly to work with pi

    I am a beginner in this field and hope you can help me by this image

    Thanx

    ReplyDelete
  8. but i am little confused!

    Can I make calls to PSTN by this way you provided!?

    ReplyDelete
  9. These steps will allow you to make/receive calls through Google voice using a landline phone.

    ReplyDelete
  10. this doesn't work anymore the current libjpeg-dev is broken, running install dependencies returns

    The following packages have unmet dependencies:
    libtiff4-dev : Depends: libjpeg-dev

    ReplyDelete
  11. Try removing "libtiff4-dev" from the apt-get .

    ReplyDelete
    Replies
    1. fix it by installing libjpeg62-dev first on it's on, then

      #apt-get install autoconf automake gawk g++ git-core libncurses5-dev libtool make python-dev gawk pkg-config libperl-dev libgdbm-dev libdb-dev libssl-dev

      no errors, everything is up and working thanks Haim very helpful tutorial :)

      Delete
  12. Just to clarify, by "wheezy-raspbian" you mean:

    83-14268 - Raspberry Pi SD Card with OS Preloaded
    This 4GB SDHC card comes preinstalled with Raspbian Wheezy, a Linux Debian based operating system optimized to run on the Raspberry Pi.
    Mfr Name: Distributed By MCM
    Mfr Number: 2113756
    http://www.mcmelectronics.com/product/83-14268

    Right?

    ReplyDelete
  13. you could do that or save your self some money and just download it here http://www.raspberrypi.org/downloads

    ReplyDelete
  14. Wow very interesting stuff! There are alot of phone systems in calgary, but I guess my brother in law, who has a Rasberry Pi, could use it instead.

    ReplyDelete
  15. great post - learnt something .........

    could you teach us all ( or me in particular ) something else ... - have gotten skype mod to work on your pi ? along with the mod dingaling ?

    i could mail u a nice pair of used sneakers to get that one working ... glen

    ReplyDelete
  16. Is there any way to make it work with Google's 2-factor authentication? It doesn't seem to like my normal password or an application-specific password when starting freeswitch.

    ReplyDelete
  17. Yes. I have mine working with the 2 mode authentication. You'll need to create an application specific password.
    https://support.google.com/mail/answer/1173270?hl=en

    ReplyDelete
    Replies
    1. Did that require any changes to the client.xml configuration (other than using the app-specific password)?

      Delete
  18. As regards the need for a PBX, in fact these now are also being pushed into the cloud as well. Basically "cloud computing" if you will for voice services.

    ReplyDelete
  19. I am trying your guide and freeswitch compiles without any errors, but when I try to start it I keep getting:
    [code]
    [INFO] switch_event.c:669 Activate Eventing Engine.
    [WARNING] switch_event.c:651 Create additional event dispatch thread 0
    Cannot Initialize [[error near line 761]: missing >]
    [/code]

    any suggestions?

    ReplyDelete
  20. Thanks for the info. I'd like to do this soon.

    I'm specifically interested in using two GV numbers (separate GV accounts).

    One for a fax number and the other for voice calls.

    1) I've read that some VOIP systems can't transmit fax signals - - something to do with the frequency of the signals involved. Can GV transmit fax signals?

    2) it's my understanding that the spa 2100 has two phone ports. So am I correct in thinking that I could assign each one of these lines to separate GV accounts?

    Thanks again.

    ReplyDelete
  21. Yes to both. I've had success with both in the past. Mind you will you need to play around with your freeswitch codecs till you find one that works with your fax.

    ReplyDelete
  22. I just attempted to the first step in this tutorial. I get the following error messages. Can you offer any suggestions?

    Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main libcurl3-gnutls armhf 7.26.0-1+wheezy3
    404 Not Found
    Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main libperl5.14 armhf 5.14.2-21+rpi1
    404 Not Found
    Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main libperl-dev armhf 5.14.2-21+rpi1
    404 Not Found
    Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-dev all 2.7.3-4
    404 Not Found
    Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/c/curl/libcurl3-gnutls_7.26.0-1+wheezy3_armhf.deb 404 Not Found
    Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/p/perl/libperl5.14_5.14.2-21+rpi1_armhf.deb 404 Not Found
    Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/p/perl/libperl-dev_5.14.2-21+rpi1_armhf.deb 404 Not Found
    Failed to fetch http://mirrordirector.raspbian.org/raspbian/pool/main/p/python-defaults/python-dev_2.7.3-4_all.deb 404 Not Found
    E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

    ReplyDelete
    Replies
    1. 1) I was able to fix it myself. I noticed that it said to try apt-get update. So I did that and then tried again. It worked that time.

      2) I'd like to suggest adding a step in the beginning. I kept getting permission errors. So I ran "sudo su" before going any further and no more permission errors.

      3) I found a typo:

      "/usr/src/freeswitch/modules.conf"
      should be
      "/usr/src/freeswitch/modules.conf".

      Delete
  23. I got freeswitch installed and running. And I connected my linksys phone adapter to my network.

    I used my cell phone to call my GV number. My freeswitch phone never rang -- on my cell phone, I just heard the ringback and eventually my GV voicemail answered the call.

    Then I used the freeswitch phone to call my cell phone. I heard the dialtone before I dialed and then after dialing, I just heard complete silence--I eventually just heard a fast busy signal. My cell phone never rang.

    Following is what freeswitch output to my screen. Obviously, freeswitch is able to receive both incoming and outgoing calls. But it doesn't seem to know what to do with them.

    What can I do?

    2013-11-16 14:50:30.835938 [INFO] mod_dialplan_xml.c:558 Processing
    Google Voice <+12123403333>->2001 in context public
    2013-11-16 14:50:30.855978 [NOTICE] switch_core_state_machine.c:262
    DingaLing/new has executed the last dialplan instruction, hanging up.
    2013-11-16 14:50:30.855978 [NOTICE] switch_core_state_machine.c:264
    Hangup DingaLing/new [CS_EXECUTE] [NORMAL_CLEARING]
    2013-11-16 14:50:30.855978 [NOTICE] switch_core_session.c:1567 Session 2
    (DingaLing/new) Ended
    2013-11-16 14:50:30.855978 [NOTICE] switch_core_session.c:1571 Close
    Channel DingaLing/new [CS_DESTROY]
    2013-11-16 14:51:46.195967 [NOTICE] switch_channel.c:1052 New Channel
    sofia/internal/2001@192.168.0.14 [e7fe2c54-4f00-11e3-9cee-a97cd6bd79df]
    2013-11-16 14:51:46.276006 [INFO] mod_dialplan_xml.c:558 Processing R D
    IRELAND <2001>->12124182222 in context default
    2013-11-16 14:51:46.335984 [NOTICE] switch_channel.c:1052 New Channel
    sofia/external/12124182222 [e8154ac4-4f00-11e3-9cfb-a97cd6bd79df]
    2013-11-16 14:52:13.975920 [NOTICE] sofia.c:6596 Hangup
    sofia/internal/2001@192.168.0.14 [CS_EXECUTE] [ORIGINATOR_CANCEL]
    2013-11-16 14:52:13.995970 [NOTICE] switch_ivr_originate.c:3410 Hangup
    sofia/external/12124182222 [CS_CONSUME_MEDIA] [ORIGINATOR_CANCEL]
    2013-11-16 14:52:13.995970 [INFO] mod_dptools.c:3201 Originate Failed.
    Cause: ORIGINATOR_CANCEL
    2013-11-16 14:52:14.015996 [NOTICE] switch_core_session.c:1567 Session 3
    (sofia/internal/2001@192.168.0.14) Ended
    2013-11-16 14:52:14.015996 [NOTICE] switch_core_session.c:1571 Close
    Channel sofia/internal/2001@192.168.0.14 [CS_DESTROY]
    2013-11-16 14:52:14.035992 [NOTICE] switch_core_session.c:1567 Session 4
    (sofia/external/12124182222) Ended
    2013-11-16 14:52:14.035992 [NOTICE] switch_core_session.c:1571 Close
    Channel sofia/external/12124182222 [CS_DESTROY]

    ReplyDelete
  24. I am very interested in this project, but I am a noob. I own several Pi's, using 2 as HTPC's and one currently as a cloud print server/file server/tor proxy relay running debian wheezy. While I impressed myself doing all this, I set these up using online tutorials and forums.
    My question is two-fold:
    1. Can I use my current wheezy setup as-is to install the PBX and other necessary packages and still keep the other functions intact?
    2. Before I start and get too involved in this, what are the physical network connections needed between the Pi, SIP, and router? Forgive me if I missed this in your write-up, but in looking at the diagram in the beginning, it looks like there are sevral connections to the Pi and I just don't understand this, since the Pi only has 1 Ethernet port and 2 USB ports.
    Any help and answers are appreciated. I am still learning about Linux and the Raspberry Pi in general.

    ReplyDelete
  25. I guess I should have explained further the setup I am looking for. I have one cordless phone base with 2 handsets that want to use for my landline. Fax would be nice, but basic calling is all I'm after for now.
    In reference tomy second question above, do I need to use a Wi-Fi USB dongle to connect to my router since the SIP device Will occupy the Ethernet port on my Pi?
    Again, thanks in advance for any help in this matter. I am excited about this project and having a landline again.

    ReplyDelete
  26. I have followed the instructions but when I get to the install of freeswitch, it takes about 30 mins and this is con the end of the output.

    ./configure: line 2583: config.log: Permission denied
    ./configure: line 2593: config.log: Permission denied

    I used sudo infront of the command "./bootstrap.sh &&........"

    Am I missing something?
    None of the other files are present that are reference later, so I don't think it worked correctly.

    Any help?

    ReplyDelete
  27. I think GV with XMPP is going to die soon.
    http://blog.obihai.com/2013/10/important-message-about-google-voice.html

    ReplyDelete
  28. I'm just new to SIP, telephony, and Raspberry Pi. I'd like to try to implement this prototype to learn. But I'm wondering what is the role of the SIP Device in your diagram? The Pi via freeswitch, is acting as the PBX... and I guess Google Voice is acting as the VoIP Provider??? I have a smart phone with Bria installed. Can I use that as my SIP Device? if so, how would i do that?
    Sorry for the remedial questions.

    ReplyDelete
    Replies
    1. I *think* I may have figured out the role of the SIP Device. Is it acting as the analog terminal adapter... aka converting from analog signal to something SIP would understand?

      Delete
  29. hi i am begineer to embedded systems i am getting an error modules.conf cannot be create permission denied
    what should i do

    ReplyDelete