Using the SPA2000 with Asterisk

Sipura's SPA-2000 device offers an inexpensive and flexible alternative for adding analog FXS ports (Foreign eXchange Station, e.g. telephone handsets) to your Asterisk system.

Sipura's SPA-2000 device offers an inexpensive and flexible alternative for adding analog FXS ports (Foreign eXchange Station, e.g. telephone handsets) to your Asterisk system.

Digium's FXS cards such as the TDM400P are excellent solutions: they "just plain work well" with Asterisk (the author owns one, and loves it). And purchasing Digium products helps to directly support the open-source development of Asterisk. But the Digium cards do require free PCI slots; and specifically PCI v2.2 slots, which many older machines — and even some newer ones — do not have.

Using the Sipura SPA-2000 to connect analog phones to an asterisk system offers several advantages:

  • We won't have to shut down our phone system and open up our computer to install new telephones;
  • Because the SPA-2000 connects to the asterisk box using standard Ethernet cabling, we can place one anywhere on our network;
  • If we have multiple analog telephones, it's a somewhat more affordable solution ($55 per telephone port with the Sipura versus $80 per port for the TDM400P).

In this Voxilla step-by-step "How-To," we're going to set up Asterisk using Free World Dialup as well as VoicePulse Connect! to dial out, although we could easily use a different VoIP provider — or even multiple additional providers.

We'll make a couple of assumptions. First, you have Asterisk up and running — setting up a new system is a complex affair beyond the scope of this "How-to." Secondly, you know how to edit text configuration files on your Linux machines, which, if you have set up Asterisk, you clearly do.

When we're done, we will have edited four of Asterisk's configuration files (in a typical installation, all four reside in /etc/asterisk) and have made changes to the SPA-2000's settings using the unit's web-based configuration screen.

Before we get started, it's appropriate to give credit where it's due. Many of the asterisk configurations in this article were derived from the terrific work of John Todd, whose Asterisk configuration example files are a must-read for anyone trying to get their heads around the often tricky software.

It's also important to note that the settings described here are not complete settings files, but are fairly easy to integrate into a default Asterisk configuration. Below, you'll see many sentences that are preceded by a semi-colon. We did this so that you can directly enter the snippets of code into your configuration files, along with the comments. Any text following a semi-colon is disregarded by Asterisk.

In the following guide, you will notice various references to "context." In the world of Asterisk, a context is simply a group of extensions (i.e., numbers that can be dialed.) A context has a unique name — this allows us to reference the same context in different places, to do useful things e.g. associate a specific voice mailbox with a certain extension, or to allow incoming calls from FWD to be directed to our Sipura device rather than to another phone, or to be able to dial out through different VoIP providers from a single phone.

For much more detailed information on configuring and administering asterisk, please see Digium's handbook (a PDF document and work-in-progress), Digium's documentation page, and the excellent Wiki for the Asterisk community at Jim Thompson's VoIP-info.org.

1. Asterisk Dial Plan

First we edit our "dialplan," which defines how we call out from our various lines and phones, and also what happens when people call into our lines and devices.

The "dialplan" is contained in "extensions.conf" (which you should be able to find in /etc/asterisk), where the following code should be inserted:

; In the the globals section, we define some constants which we can use later
; to make things neater and more efficient.
[globals]
;
;
; First, our two Sipura lines, which we will call extensions 2201 and 2202 in this
; example. Any extension number could be used as long as we are consistent across
; all .conf files as well as in the SPA-2000 configuration screens.
; SIP/ tells asterisk that we are referring to a SIP device or channel.
;
; line 1
;
PHONES1=SIP/2201
PHONES1VM=2201
;
; line 2
;
PHONES2=SIP/2202
PHONES2VM=2202
;
; Second, we need to enter our login for VoicePulse Connect! In your order
; confirmation email from VoicePulse, you should have received information
; that looks something like this:
; Login: 1234567890
;
; So we want to put that login information here:
VOICEPULSEID=1234567890
;
;
; Next, we'll enter our number for Free World Dialup
;
FWDUSERID=94896
;
;
; Now we need to provide our outgoing caller ID information, which can be
; set to whatever we like. VoicePulse Connect! will send it exactly as we specify
; here. So make sure it looks right to you!
;
MYNAME=Dorian Gray
MYPHONE=2125551212
;
;
;
; We'll include a simple macro that takes an extension as its argument,
; connects the caller to the voice mailbox of that extension, and then hangs up after
; playing a couple short messages.
;
[macro-vmessage]
exten => s,1,VoiceMail2(u${ARG1})
exten => s,2,Playback(groovy)
exten => s,3,Playback(goodbye)
exten => s,4,Hangup
;
;
; And also a fairly simple macro for dialing out using VoicePulse Connect!
; (note how we re-use the globally defined constants. slick, eh?).
;
[macro-dialvpconnect]
;
; Here we can set caller ID number and name, if we like
;
exten => s,1,SetCallerID(${MYPHONE})
exten => s,2,SetCIDName(${MYNAME})
;
; Here is where we dial out through VoicePulse Connect! and use a couple
; arguments that must be passed to the macro: ARG1 will be the number we're
; trying to dial (e.g. 12125551212) and ARG2 will be how many seconds to try
; before giving up, e.g. 60
;
exten => s,3,Dial(IAX2/${VOICEPULSEID}@voicepulse/${ARG1},${ARG2},Tr)
exten => s,4,Hangup
;
;
;
; The dialout context can be included in contexts which should have access
; to an outside line. Normally we would include many different outgoing contexts,
; but for simplicity, we mention only "vpconnect-forced" and "fwd-out" in this case.
;
[dialout]
;
; if someone dials a "6" in front of their number, send out via VoicePulse Connect!
;
include => vpconnect-forced
;
; If someone dials a "7" in front of their number, send to Free World Dialup
;
include => fwd-forced
;
;
; It's "forced" because we require a "6" to be dialed to match this context.
; In fact, it would certainly be possible to set up our dialplan without the
; "forced" leading "6" or "7" so that numbers of a certain length
; (e.g. 5 or 6 digits) dialed out to FWD, and numbers starting with a "1" or
; even specific area codes dialed out to VoicePulse or another provider.
;
[vpconnect-forced]
;
; Dial out on VoicePulse Connect! and wait for 70 seconds for a connect.
; If no connection is made in 70 seconds, jump to the "fastbusy" macro.
; Note that ${EXTEN:1} will be passed as ARG1 of our macro, i.e.
; strip the leading "6" and pass the rest of the number. "70" will
; then be ARG2 of the macro, the dial timeout in #seconds.
;
exten => _61XXXXXXXXXX,1,Macro(dialvpconnect,${EXTEN:1},70)
;
;
[fwd-forced]
; Check to see if the called number starts with a "7" and
; if so, set the call parameters and bounce the call to the
; Free World Dialup SIP server.
;
; NOTE: Calls to unknown users will result in "invalid extension"
; message being played.
;
exten => _7.,1,SetCallerID(${FWDUSERID})
exten => _7.,2,SetCIDName(${MYNAME})
exten => _7.,3,Dial(SIP/${EXTEN:1}@fwd)
exten => _7.,4,Playback(invalid)
exten => _7.,5,Hangup
;
;
; This is the home context. Any phone or device that has access to this
; context will be able to make outgoing calls.
;
[home]
;
; First, we definitely want to include the dialout context,
; so we'll be able to dial out!
;
include => dialout
;
; Next, add an extension for voicemail —
; now if we dial 8, we can check voicemail.
;
exten => 8,1,VoiceMailMain2
exten => 8,2,Hangup
;
;
; Add some more extensions for the two Sipura lines — now
; we'll be able to call one line from the other.
; And if no one answers, it will go to the mailbox for that line.
;
; Sipura line 1
;
exten => 2201,1,Dial(${PHONES1},20,Ttm)
exten => 2201,2,Macro(vmessage,${PHONES1VM})
exten => 2201,3,Hangup
;
;
; Sipura line 2
;
exten => 2202,1,Dial(${PHONES2},20,Ttm)
exten => 2202,2,Macro(vmessage,${PHONES2VM})
exten => 2202,3,Hangup
;
;
; NOTE: it will be important to remember the name of the context
; "from-sip" — later, we will need to use it in sip.conf
;
[from-sip]
; To receive calls inbound from FWD, we set the extension
; to our FWD user ID, in this case 94896
;
; As currently written, incoming calls from FWD will ring
; only line 1 of the SPA-2000. However, changing the "Dial"
; directive to something like this:
; Dial(${PHONES1}&${PHONES2},15,Ttm)
; would cause both lines of the Sipura device to ring
;
exten => 94896,1,Dial(${PHONES1},15,Ttm)
exten => 94896,2,Voicemail2(u${PHONES1VM})
exten => 94896,3,Hangup

 

2. Setting up IAX

IAX is the Inter-Asterisk eXchange protocol. It's not as widely recognized a standard as SIP, but it has a lot of excellent advantages (e.g. unimpaired usage through NAT/masquerading firewalls, high performance, internationalization) and it happens to be the only way to access the VoicePulse Connect! service.

We will edit "iax.conf," which should be in /etc/asterisk.

; First, we need to configure what codecs we will use. That is, how much
; bandwidth and CPU power do we want to use vs. what kind of sound quality
; we'd like to have. iLBC (internet Low Bitrate
; Codec) is a free, low-bandwidth
; codec of very high quality, and VoicePulse Connect! supports it — so let's use it.
;
; You can fine tune codecs here using "allow" and "disallow" clauses
; with specific codecs. Use "all" to represent all formats.
;
disallow=all ; only use the codecs we specify
disallow=g723.1 ; Hmmm… Proprietary, don't use it…
disallow=lpc10 ; Icky sound quality… Mr. Roboto.
;
; Asterisk doesn't pay attention to the order in which we list our
; codecs, generally choosing the lowest bandwidth consuming codec
; available.
;
allow=ilbc
allow=gsm ; Always allow GSM, it's cool 🙂
allow=ima-adpcm ; aka g726, another decent low bandwidth user
;
;
; Next, we define how to connect to VoicePulse.
; The name of the context "voicepulse" here has to exactly match the
; @voicepulse in our dialing macro from extensions.conf
;
[voicepulse]
type=friend
;
; Context "foo" does not actually exist in our dialplan, but that's ok.
; If we had also registered a DID (Direct Inward Dialing, A.K.A. an incoming
; phone number) with VoicePulse, then it is important to define what happens
; when someone calls that number in "extensions.conf."
context = foo
; Your VoicePulse Connect! order confirmation email should
; have included a line such as:
; Password: yyyyyyyyyy
; so set it as the secret here:
secret=yyyyyyyyyy
auth=md5
host=gw5.voicepulse.com
;
; If we want to force the use of ILBC, the following is necessary as Asterisk
; will otherwise choose GSM first.
disallow=gsm
allow=ilbc
; denying iaxtel server ip addresses prevents cross-registration issues
deny=216.207.245.47/255.255.255.255
deny=69.73.19.178/255.255.255.255

3. Setting up SIP  SIP is the Session Initiation Protocol. It's a worldwide standard, and quite  a lot of hardphones (such as our SPA-2000) use it.

We will edit sip.conf, most likely in /etc/asterisk.

[general]
;
;
; here we set the context to "from-sip" exactly as in extensions.conf,
; so that incoming calls from FWD can be sent to the Sipura device.
;
context = from-sip
;
; As in iax.conf, specify what codecs we will allow
disallow=all ; Disallow all codecs
allow=gsmallow=ilbc
allow=ima-adpcm
allow=ulaw
allow=alaw
;
;
; Here we register our FWD phone number so that when someone calls it,
; we'll be able to receive that incoming call over SIP.
;
register=94896:myfwdpassword@fwd.pulver.com/94896
;
;
; Next we set up some more info for FWD — this part is what will
; allow us to make outgoing calls over SIP using FWD.
;
[fwd]
type=friend
secret=myfwdpassword
username=94896
host=fwd.pulver.com
dtmfmode=inband
;
;
; Here is where we define those two extensions that were mentioned earlier,
; and attach them to the two lines on the SPA-2000
;
; line 1
;
[2201]
type=friend
;
; Although the SPA-2000 can be set to a static IP address, its registration will
; fail unless we set host as dynamic.
host=dynamic
;
; Here, the context is very important! We want to allow access
; to "home", which is where all outgoing calls are made in
; our dialplan.
context=home
;
; This password must match the one we later set in the Sipura device
secret=mysecret2201
;
; This is the caller id that will show up if we call line2 from line1.
callerid="SPA1" <2201>
;
; If the voice mailbox specified here has new messages,
; this line will have a stuttered dialtone when we pick up the phone.
mailbox=2201
;
; Note: dtmfmode=inband will only work with g711, not gsm!
; On the SPA-2000 configuration screen, rfc2833 is called "AVT."
; This does not need to be changed unless Asterisk is having
; trouble recognizing keypad input from our telephone.
dtmfmode=rfc2833
;
; Since our SPA-2000 is only talking locally to our asterisk machine,
; special consideration for NAT (Network Address Translation) is not needed.
nat=0
;
; The configuration of the second line is very similar to the first.
; line 2
[2202]type=friend
host=dynamic
context=home
secret=mysecret2202
callerid="SPA2" <2202>
mailbox=2202
dtmfmode=rfc2833
nat=0

4. Setting up Voicemail

As long as we define them here, Asterisk will automatically create mailbox directories (under /var/spool/asterisk/voicemail) for our Sipura extensions.

Here we will edit voicemail.conf, again in /etc/asterisk.

[general]
;
; We want to save voicemails as gsm format, it's nice and small.
;
format=gsm
;
; Should the email contain the voicemail as an attachment
;
attach=yes
;
;
; Here again is that "from-sip" context, which in this case will
; allow voicemail from incoming FWD calls to be associated with
; our SPA-2000 lines.
;
[from-sip]
;
; Each mailbox is listed in the form
; <mailbox>=<password>,<name>,<email>,<pager_email>
; if the e-mail is specified, a message will be sent when a message is
; received, to the given mailbox. If pager is specified, a message will
; be sent there as well.
;
2201 => 4444,SPA_line1,me@example.com
2202 => 5555,Arbitrary_Name,roommate@example.com,roommates_pager@example.com

 

5. Reload Asterisk

A nice feature of Asterisk is that most configuration changes do not require a restart, but simply a reload of the config files. So just go into the Asterisk console and enter "reload", that's it!

asterisk*CLI> reload

6. SPA-2000 Configuration

Editing the settings on the SPA-2000 so that it can speak with Asterisk is very simple. It is all done on the SPA-2000's comprehensive web-based configuration screens.

To get to the SPA-2000's configuration screens, you first need to determine the IP address of the unit. The simplest way to do this is through your telephone: Dial "****", at the voice prompt, type "110#". The voice menu will then read out the SPA-2000's IP address. Enter this IP into your web browser to reach the configuration screens.

We'll want to edit "Line 1" and "Line 2" in Advanced mode. All options not specifically mentioned should be assumed left as default.

In the networking options (first set of options, doesn't actually have a label on the SPA-2000) make sure that the NAT settings are set to "no" and leave the defaults for the rest.

In Proxy and Registration, enter the IP address of our Asterisk server under "Proxy", make sure "Outbound Proxy" is blank, "Register" is set to "yes", and set the pulldowns for "Use Outbound Proxy", "Use OB Proxy In Dialog", "Make Call Without Reg" and "Ans Call Without Reg" all to "no".

For Subscriber Information, "Display Name" can be set to whatever you like (does not really matter as Asterisk will be setting caller ID for us). "User ID" should be set to the extension we defined earlier, e.g. "2202" and "Password" should be set to the respective secret for that extension, namely "mysecret2202".

Supplementary Service Subscription can be left as defaults.

  

     Spa2000 config image 1  

Next, we have Audio Configuration. Since our SPA-2000 will only be communicating locally with Asterisk, bandwidth is not such a big issue. However, we do need to take into consideration CPU usage and the fact that our Asterisk machine will have to constantly transform between the iLBC it's using over IAX with VoicePulse and whatever codec it's using over SIP with the Sipura device.

One of the g726 flavors would be a good choice as they are fairly low-complexity; the -16, -24, -32 and -40 designations merely mean how many kbits/sec we'd like to use.

"DTMF Tx Method" should be set to "Auto" (or could be set to "AVT" which matches our rfc2833 setting in sip.conf). "Use Pref Codec Only" can be set to "no" — if, for some reason, our Asterisk server decides that it wants to use a different codec than the one we've selected, this should allow the SPA-2000 to continue working properly. Other options can be left at their default settings.

Finally, Dial Plan. We want to have a dialplan that somewhat mirrors the one we have in extensions.conf, so that leading "command" digits still get sent to Asterisk. Something like the following allows dialing of FWD numbers as well as numbers with a leading 6 that tell Asterisk to use our VoicePulse Connect! macro.

(xxx|xxxx|xxxxx|xxxxxx|1xxxxxxxxxx|61xxxxxxxxxx|7*1xxxxxxxxxx|7**1xxxxxxxxxx)

Spa2000 config image 2

Now that line 2 has been configured, line 1 can be configured in a similar fashion.

Finally, attach phones to line 1 and line 2, pick up and see if you have a dial tone, and try calling out, e.g. 786 for FWD voicemail, or 612125551212 for directory service.

As you have seen, it's fairly easy to add new devices and VoIP service providers to our Asterisk system. As long as our Internet connection has enough bandwidth to support them, several SPA-2000s could be located wherever we have network connectivity; and through Asterisk, each separate line on a Sipura device is able to have its own unique voice mailbox. This is an ideal environment for the home or small office — a complete, centralized PBX in software, and the flexibility to put affordable phone devices wherever we like.

Be Sociable, Share!