Hack79.Build a 100 PSTN Gateway in 10 Minutes or Less

Hack 79. Build a $100 PSTN Gateway in 10 Minutes or Less

The Sipura SPA-3000 is a marvel of engineering. For less than a hundred bucks, you can interface your phone line with your VoIP network. What's cooler than that?

When your phone line is connected to your plain-old analog phone, it works and works well. But when it's connected to your VoIP network, it takes on a whole new personality. Suddenly you can do all kinds of cool stuff.

This hack will show you how to connect a PSTN phone line to an Asterisk-based VoIP network using the Sipura SPA-3000 ATA. This device is like other ATAs in that it has one FXS port. However, the SPA-3000 has a trick up its sleeve: a single FXO port as well. Not only does it have the hardware, but Sipura's firmware is actually quite flexible, allowing you to do all kinds of things to impress your friends and make life easier (hopefully). For this hack you'll need an Asterisk machine nearby [Hack #4].

I am going to demonstrate this hack using Asterisk and the SPA-3000. But because the SPA-3000 speaks SIP, you can just as easily use it in conjunction with most other SIP-compatible devices out there. (In fact, the Clipcomm CG-200 gateway [Hack #43] would make a fine substitute.)

The Asterisk server has a sip.conf file that allows calls to be placed into the default context from remote SIP endpoints. I am going to assume that you want incoming calls to the FXO port on the Sipura to be forwarded to an extension on that existing Asterisk server; I'm using 1000 for this hack. I'm also assuming the Sipura and the Asterisk server are on the same LAN and the server's IP address is

On your Asterisk server, open up /etc/asterisk/sip.conf and create a new entry at the bottom of the file:

 [spa3k] type=friend username=spa3k secret=spa3k ;<----- Pick a new password and write it down! dtmfmode=rfc2833 host=dynamic context=default nat=yes allow=all 

Save sip.conf and reload Asterisk with asterisk -rx reload. If you would like to place outbound calls using your new SPA-3000, continue reading. Otherwise, you can skip ahead to the section "Configuring the Sipura." Next we will need to edit /etc/asterisk/extensions.conf. Underneath the [globals] section, add a new line:


If you already have a TRUNK variable defined, it is up to you to figure out how you want to mix and match your existing trunk(s) with your SPA-3000. Now, scroll down to the bottom of the file and add a new section here:

 [spa-trunk] exten => _NXXXXXX,1,Dial(${TRUNK}/${EXTEN},20) exten => _NXXXXXX,2,Congestion exten => _NXXNXXXXXX,1,Dial(${TRUNK}/${EXTEN},20) exten => _NXXNXXXXXX,2,Congestion exten => _1NXXNXXXXXX,1,Dial(${TRUNK}/${EXTEN},20) exten => _1NXXNXXXXXX,2,Congestion exten => _011.,1,Dial(${TRUNK}/${EXTEN},20) exten => _011.,2,Congestion exten => _NXX,1,Dial(${TRUNK}/${EXTEN},20) exten => _NXX,2,Congestion 

This dial plan will enable NANPA-style dialing of local, 10-digit local, long-distance, international, and emergency/information services from your system to the SPA-3000. You will want to make sure to include this new section in your local phone configuration. So, if your SIP phones, as defined in sip.conf, are in the "local" context, you will want the local context in extensions.conf to contain this line:

 include => spa-trunk 

This will enable your SIP phones to use your new PSTN gateway. Save extensions.conf and reload Asterisk with asterisk -rx reload.

6.9.1. Configuring the Sipura

Once you have unpacked the Sipura, connect your POTS telephone line to the RJ11 jack labeled LINE, connect an analog telephone to the RJ11 jack labeled PHONE, connect Ethernet, and then power up. Once the Sipura has powered up, dial **** from the analog telephone. As soon as you hear the voice prompt, dial 110#. The answering voice will read back the SPA-3000's IP address.

Moving to your PC, enter the SPA-3000's IP address in your web browser. You should see a gray screen with some status information. In the upper right-hand corner, click Admin, and then click Advanced. You should see a wealth of new options appear.

Move over to the PSTN Line tab. Table 6-1 shows you the values to fill in for this page.

Table 6-1. Values to place in the PSTN Line configuration

Field name



IP address of Asterisk server



Display Name






Make Call without Register


Ans Call without Register


Dial Plan 8


PSTN Ringthrough


PSTN Default DP


PSTN Answer Delay


After you have entered these changes, click "Submit all changes." The Sipura will reset, and once it reboots, you should have a fully functioning SIP/PSTN gateway, connecting calls between your Asterisk server and the PSTN.

Kristian Kielhofner

VoIP Hacks
VoIP Hacks: Tips & Tools for Internet Telephony
ISBN: 0596101333
EAN: 2147483647
Year: 2005
Pages: 156

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net