Tag Archives: pbx

How to setup Asterisk with Ooma voip using a Linksys SPA-3102

Asterisk is one of the coolest pieces of open source software that I have come across. Its possibilities are endless, and its almost completely free (aside from all the cool gadgets you buy to expand its functionality). The reason for this blog post is to provide a better guide for setting up asterisk to communicate with an spa-3102 and interface it with ooma. In this setup, I have asterisk 1.4 running on an NSLU2 running unslung 6.10beta. Being that the nslu2 does not have much in terms of support for fxo/fxs built in or through its USB ports, the super handy dandy and small form factor of the SPA-3102 is a perfect option to get an FXO port to interface with asterisk via ethernet and be able to make and receive calls with asterisk to the PSTN (in this case to dial out and receive calls from my ooma hub).

The real motivation for me to use asterisk and ooma was to save moolah. With ooma, albeit with the up-front cost of $200, one can cancel their phone line and stop paying those pesky monthly bills. Our monthly bills were not as absorbitant as others, yet the reasoning behind me getting it was to get more for the same. I canceled my ATT $10 internet (768k down) and $10 phone with only local calling…(total monthly charge of $32-$37 with taxes and long distance charges that we didnt make), and opted for a 12mb down 512k up cable internet connection for $37.99. I would then still have a home phone number which I could take with me if I moved, and have super fast internet (in my standards). With asterisk in the mix, I could then share out my ooma with my family and allow them to make calls to the US for free as well (my sister lives in australia). Also, if I am overseas, I can make free calls to the US. I also have gizmo5 and google voice working together to provide my individual extensions in asterisk with DID numbers, but thats for another post.

For those of you who do not know what ooma is, its a VOIP hardware solution which gives you a dedicated phone line and “unlimited” calling to the US, all you need is an internet connection. I got my ooma core from radio shack for $199 and will never have to pay phone bills again (ooma core does not have an annual regulatory fee, while the ooma telo, and ooma hub only, does). Ooma makes its money off the upfront cost of hardware, and also by selling its ooma premier service. This service gives you cool features, but features that asterisk allows you to do and with more customization (and maybe for a little more effort). The Linksys SPA-3102 is an ethernet voice gateway with FXO port that has the added functionality of routing, and it also acts as an ATA to allow your regular analog phone to connect with a VOIP provider using the FXS port (If you don’t have an SPA-3102 yet, you can get one from here).

Ooma hub wiring setup

The Ooma hub can be hooked up to your existing phone lines in several ways. Currently, I have my ooma phone port plugged directly into my existing home wiring jack with a splitter which also has my fax/answering machine plugged into it. This configuration allows all the phone jacks in my home to access the ooma hub without the use of the ooma scout. This is essentially the same wiring configuration as one receiving phone service from the telco. However, you lose the instant second line feature you would otherwise be provided when using the ooma scout adapter. To connect the SPA-3102, just plug a phone cord from the Line port on the adapter to a jack in the wall, or if it is near the ooma hub, into a splitter which shares a line plugged into the Phone port on the Ooma hub (or directly into the hubs phone port without a splitter). If you are on a call using a phone plugged into my wiring configuration and dial out using asterisk through the Line port on the SPA, the adapter will report a 503 message to asterisk and stop the call from taking place and interrupting.

If one wants to make sure the line is not busy when receiving/making a call when using the ooma as a regular analog telephone line as well, another configuration one can use, is to hook up the ooma scout and connect it directly to the ooma hubs ‘wall’ port via phone line. One would then connect a phone line from the SPA-3102 Line port to the scouts ‘wall’ port. This enables the scout to communicate with the ooma hub and enables the instant second line feature should the first line be active when a call out from the asterisk box takes place.

Linksys SPA-3102 Configuration

SPA-3102 Remote Management for LAN Setup

The SPA-3102 has four interface ports in the rear, Internet, Ethernet, Phone, and Line. If you plug in a computer to the ethernet port via cable, it will provide your computer with an ip address with which you can then enter in the gateway address from an ipconfig and hit the spa3102 web gui. With this web gui, youll be able to configure the device. We dont want to have to plug in a cable each time to configure the device, so we will enable the web interface on the spa3102 when it is connected to the Internet port (with which it will receive a dhcp address handed out to it from your router currently on your network).

-Log into the webgui for the spa-3102 when you are connected to the ethernet port
-Click on the admin and advanced links at the top right to get the elevated setup access
-Goto ‘WAN Setup’ Tab
-Change ‘remote management’ option to ‘yes’
-Click the ‘submit all changes’ button at the bottom.

-Connect your spa-3102 to your network via the internet port.
-Log into your spa-3102 and look at the status screen with the computer still plugged into the ethernet port on spa3102. You will find the dhcp address the spa-3102 received from your router which is connected to the Internet port.
-Disconnect your computer from the ethernet port on the spa-3102
-Log into your 3102 via the dhcp address that it received from the internet port.

SPA-3102 PSTN Line Setup:

Now we begin the configuration of the SPA to be used with asterisk. In this setup, I will not enable Line1 which makes the SPA-3102 an ATA adapter as well (allowing calls made to your voip provider to ring the analog phone connected to the PHONE port). In this setup, I just use the SPA as a gateway which allows me to make and receive calls (using the LINE port on the SPA) from any extension that is connected to my asterisk pbx. Under the LINE 1 tab in the SPA, ive set “Line enable” to no.

NOTE: When things are configured properly, and the PSTN Line is registering with asterisk, the LINE LED on the SPA will light up and remain lit (same with the Phone port if Line 1 is enabled). If things arent communicating correctly, the LED will not be lit (I have the spa registering to asterisk).

-Log into the SPA web gui
-Click on the admin and advanced links at the top right to get the elevated setup access
-Click the ‘PSTN Line’ tab

Proxy information

Where you enter in your asterisk server IP info and whether or not it will register to asterisk.

Proxy and Registration

Proxy – Change 192.168.1.77 to the ip address asterisk is on your network. I put the ip in the outbound proxy, its not necessary as ‘Use Outbound Proxy’ is set to ‘no.’
Register – ‘yes’
Make call without reg and Ans call without reg – Change options to ‘no’

Subscriber Information

Display name – can be anything
User Id – can be anything but for simplicity sakes when configuring asterisk, use a name without spaces
Password - can be anything

Dialplan stuff

This is where you enter dialplan information, and options to configure sending calls from asterisk to the pstn port.

Dial Plans

This section of dial plans are accessed by the entire page of the SPA PSTN Line tab. There are eight DP fields because it allows you to create different dial plan options to be used throughout this tab. Voip-to-PSTN, and PSTN-to-VOIP sections both reference these dialplan fields as ‘DP.’ As you can see in my screenshot, Dial Plan 2: is filled out. In my setup, this command tells the SPA that any calls answered after the PSTN-to-VOIP gateway option answer delay is reached, to be sent to the S extension in asterisk. You may enter any extension such as (S0<:102@asteriskIP>).

VOIP-to-PSTN Gateway Setup

VOIP-to-PSTN gateway enable – ‘yes’
Line caller DP – set to ‘1’ (this option references Dial Plan 1:  and the default (xx.). This just passes anything sent from asterisk to the SPA without any change)
One Stage Dialing – set to ‘yes.’ If set to no, then the SPA uses 2 stage dialing, and it screws up asterisks calling out to the Line port.

voip spa-3102

The PSTN-to-VOIP configuration, where you configure how to send calls from the Line port (pstn) to asterisk

PSTN-to-VOIP Gateway Setup

PSTN-to-VOIP Gateway enable - ‘yes’ (in the screenshot above, i have it set to ‘no’ as I do not want the spa to pick up the line and forward to my extension s@192.168.1.77 as defined in Dial Plan 2:. This essentially turns off any calls going to my asterisk system. I have my asterisk system setup to forward the call from the pstn to my cell phone when this is turned on, and only used while traveling far away from home. When I am not traveling I have a fax/answering machine on my ooma and want it to pick up instead, so it is disabled.

If you are in an asterisk/voip only configuration and want all calls to be routed straight to your asterisk system without worrying about any analog answering machines or fax picking up/ringing, then set to ‘yes’

PSTN CID For VoIP CID – set to ‘yes’ if you want callerid to be passed onto your asterisk system
PSTN Caller Default DP – set to ‘2’ as in my Dial Plan 2: it allows calls to be routed from Line port (pstn), to extension S on my asterisk pbx

FXO timer values (sec)

PSTN answer delay – this option is to change the length of time the SPA-3102 picks up the call coming in from the PSTN and forwards it to your asterisk system. The default is 16 which allows the line to ring for a little too long before sending it off to Asterisk. A number of 3-5 should be good for callerid to be gathered and sent along with the call to asterisk.
PSTN Dial Digit Len – set to .1/.1 otherwise calls may take longer to start connecting. This essentially shortens the speed at which digits are dialed at. You dont want digits to take forever to be entered do you?

Awesome. You are now finished configuring your SPA-3102 to act as a SIP trunk on the SPA-3102 side. All you need from here to configure asterisk is the username and password you specified in the Proxy and Registration section. Now on to the Asterisk side of things…

Asterisk Configuration

This setup is for asterisk 1.4. I found that many guides found on the internet do not seem to work for my setup. I was not able to set my SPA as a peer, but had to configure my 3102 to register to asterisk as an extension in order for everything to work correctly. I also found many internet guides had sip trunk settings which were no longer used for version 1.4. Now lets tell asterisk theres a device to communicate with in the Users.conf (for you it might be Sip.conf) file in the asterisk directory.

Users.conf or Sip.conf

Users.conf or sip.conf configuration in asterisk. this command sets up the SPA to be used as an extension from which calls can be made and received.

[pstn] – Put the username you specified on the SPA-3102 in between brackets. In my example above, replace [pstn] with your username. The tricky part here is that the name between brackets is your username, even if you specify username = as something else, asterisk will not allow your 3102 to register with it.
type = friend – Sets as an extension which can be dialed out from (see here for more info)
port – I saw several guides saying to put in port = 5061, this is unecessary as this configuration automatically connects to this port. You may need this if it was set to type=peer, but I was never able to get it to work as one.
disallow – This configuration also disallows any voice codec other than ulaw, alaw, and gsm as the NSLU2 does not have enough horsepower to transcode the higher compression the other codecs use.
context = pstn-in – this is the label for where incoming calls are sent to in my extensions.conf file.
host = dynamic – as the spa is registering to asterisk, the ip address of the 3102 does not need to be specified here and will be obtained during the spa-3102 device registration. I could change the ip address of the spa-3102 on the unit and it would still register with asterisk.
secret = passwd – replace ‘passwd’ with the password you entered in the spa-3102

Other than that, this is all thats needed for the PSTN Line to register to asterisk and send and receive calls.

Extensions.conf

Extensions.conf is the the file which tells asterisk how to handle incoming/outgoing phone calls.
Lets configure outgoing calls first, as it requires very little configuration. Below is all i need to put into my default context in order to make outgoing calls out of the Line port (we previously specified ‘pstn’ as a trunk/user in users.conf/sip.conf) on my SPA-3102. Below, the _XXXX. tells asterisk that any number dialed with more than 4 digits should go out through the SPA (I have 4 digit extension numbers configured). Without this configuration, asterisk would try to place a call to an internal extension number, only to find that the extension (the phone number dialed) did not exist.

Outgoing to pstn

Simple outgoing dialplan used in the default context in my extensions.conf

In my users.conf (maybe your sip.conf) file, I had the pstn user (pstn is the username specified in the spa3102) use context pstn-in as the label to goto which contains the code for how to handle the calls coming in from the Line port or PSTN.

extensions.conf

Extensions.conf tells asterisk how to handle a call. pstn-in is the context defined in my users.conf/sip.conf

In my spa-3102, my Dial Plan 2: had code (S0<:s@192.168.1.77>). This essentially sent the incoming call from the PSTN Line to the S extension in asterisk. Asterisk knows that the call is coming from the pstn user defined in the users.conf/sip.conf file, and found that context pstn-in was specified. It then initiated the commands under the pstn-in section. The commands listed above, answers the call, plays a sound file that nobody is available to take the call, then says “call-forwarding” and proceeds to ring my cell phone number (8001112222 is the cell number, change it as desired. proxy01.sipphone.com is my gizmo account which forwards it out through a google voice DID number).

Alternatively, if you just want to have the incoming pstn call sent to several or all extensions on your asterisk system, you can substitute my ‘Dial’ line with the one below and change my extension numbers to match yours (where 6000, 6100, 6200 are my extensions/phones registered with asterisk):

exten = s,n,Dial(SIP/6000&SIP/6100&SIP/6200,20)

Thats all there is to it, good luck!