Asterisk @ Home

This is the infrastructure used

  1. A Fit-PC3 for PBX, ultra low power machine for Asterisk
  2. A LinkSys SPA3000 as FXO/FXS port (connection to and from public telephone network)
  3. An old analog phone
  4. A couple of semi-old Cisco IP Phones


How an incoming call works

An inbound call comes in over the SPA3000 from the Public telephone network. That call is converted to SIP and routed to the PBX (step 2). The PBX then distributes the call to all 3 SIP clients: SPA3000 (now the 2nd port), the Wireless IP phone and the wired IP Phone (step 3 and 4).

How an outgoing call works

When one of the 3 phones makes a call it is sent to the PBX (1, 2, 2a, 2b) who then looks at the number dialed. It then makes a decision to route it to a SIP provider via the Internet connection (3) or route it over the public telephone network again (3 and 4). This was done because the PSTN provider has better rates for calling a mobile phone (+316xxxx)

Setting up the Cisco IP phone

Setting up the individual VOIP phones can take a bit of time, for Cisco a TFTP service is needed and the phone must be equiped with SIP firmware (if this is not already done). A good tutorial can be found here. The SIP firmware only applies to the non-wireless phones, the Cisco 7970. An other Cisco 792x can be connected to asterisk using the SCCP firmware

Setup the SPA-3000 for incoming and outgoing analog calls

There are lots of configuration settings for the SPA-3000, but I think the following are the major ones which need to be set. Using the advanced web menu configuration: the following settings will configure 2 sip clients to the asterisk PBX which you can then use to route incoming and outgoing traffic. This is a pretty cool feature of the SPA3000: basically this small device is 2 analog-to-SIP clients glued together. registering them both to the PBX makes a powerfull setup.

In the Line 1 tab:

Line Enable: Yes
Proxy: <IP Address of Asterisk Server>
Register: Yes
User ID: spa3000
Password: PASSWORD
Dial Plan: (1233|xxxxxxxxxx|000S0<:@gw0>|106S0<:@gw0>|1[38]xxxxxxxxS0<:@gw0>|13[1-9]xxxS0<:@gw0>|1[9]xxxxxxxxS0<:@gw0>|0[23478]xxxxxxxxS0|[2-9]xxxxxxxS0|001xxxx.S5|xxx.<:@gw0>|*xx.|<*,:>xx.|<#,:><:@gw0>)

The dial plan syntax for the SPA-3000 is in the documentation. This is mine and forwards all to the asterisk pbx.

In the PSTN Line tab:

Line Enable: Yes
Proxy: <IP Address of Asterisk Server>
Register: Yes
User ID: pstn
Password: PASSWORD
Dial Plan 2: (S0<:ip-of-asterisk-colon-5060>)
PSTN-To-VoIP Gateway Enable: Yes
PSTN Ring Thru Line 1: No
PSTN Caller Default DP: 2
Disconnect Tone: 425@-30,425@-30;1.4(.5/.5/1+2)

Ring Thru Line1 is set to NO now: this means that even though the SPA300 will route the call to the PBX, and that PBX will route it back again: the SPA3000 is not allowed to let it already ring. It needs to wait for the PBX. You may set this setting to true if you wish the analog port to start ringing earlier than the IP phones.

In the regional tab (skip if not in NL):

Make the SPA3000 analog line sound like it’s from the Netherlands

Call Progress Tones
Dial Tone:
Second Dial Tone:
Outside Dial Tone:
Prompt Tone:
Busy Tone:
Reorder Tone:
Off Hook Warning Tone:
Ring Back Tone:
Confirm Tone:
SIT1 Tone:
SIT2 Tone:
SIT3 Tone:
SIT4 Tone:
MWI Dial Tone:
Cfwd Dial Tone:
Holding Tone:
Conference Tone:
Secure Call Indication Tone:
VoIP PIN Tone:
PSTN Warning Tone:
Feature Invocation Tone:
Distinctive Ring Patterns
Ring1 Cadence: Ring2 Cadence:
Ring3 Cadence: Ring4 Cadence:
Ring5 Cadence: Ring6 Cadence:
Ring7 Cadence: Ring8 Cadence:


the sip.conf file is where you configure each individual SIP endpoint that you connect to (or is connected from) in this installation: 2x SPA3000, 2x IP phones and 1 SIP internet telephony provider. 5 in total

; part of the [general] context
;     This registers the SIP client to the VOIP provider (voipbuster)
register =>

 type=friend                    ; This device takes and makes calls 
 host=dynamic                   ; This host is not on the same IP addr every time 
 username=cisco7970             ; Username programmed into Cisco phone 
 secret=PASSWORD                ; Password for device 
 context=local_phone            ; Inbound calls from this phone go to this context 
 nat=no                         ; nat=yes if this phone is behind a NAT box or firewall 
 callgroup=2                    ; the group to which this phone belongs for *8 phone ringing pickup 
 pickupgroup=2                  ; the pickup group allowed from this phone when *8 is dialed 
 mailbox=3000                   ; Activate the message waiting light if this voicemailbox has messages in it 

 disallow=all                    ; need to disallow=all before we can use allow=
 allow=ulaw                      ; Note: In user sections the order of codecs
                                ; listed with allow= does NOT matter!
 allow=g723.1                    ; Asterisk only supports g723.1 pass-thru!
 allow=g729                      ; Pass-thru only unless g729 license obtained

 mailbox=3000                    ; Mailbox number (numerical so can be selected through phone)
 disallow=all                    ; need to disallow=all before we can use allow=
 allow=ulaw                      ; Note: In user sections the order of codecs
                                ; listed with allow= does NOT matter!
 allow=g723.1                    ; Asterisk only supports g723.1 pass-thru!
 allow=g729                      ; Pass-thru only unless g729 license obtained
 context=local_phone             ; This links sip.conf with the 
                                ; entry local_phone in extensions.conf
 context=incoming               ; This connects incoming calls to the corresponding entry in extensions.conf
 allow=g723.1                    ; Asterisk only supports g723.1 pass-thru!
 allow=g729                      ; Pass-thru only unless g729 license obtained


Extensions.conf wires it all together: all SIP endpoints previously configured can now be connected to each other using this dailplan. there are two contexts: a local_phone and an incoming handling outgoing/local traffic (local_phone) and incoming calls (incoming)

The dailplan you see here lets all international and landlines be routed throug the SIP telephony provider and all mobile calls to the pstn.

exten => 1233,1,VoiceMailMain(s3000)
exten => 1,1,Dial(SIP/spa3000,20)
exten => 2,1,Dial(SIP/cisco7970,20)
exten => 3,1,Dial(SIP/mac,20)
exten => _06XXXXXXXX,1,Dial(SIP/${EXTEN}@pstn)
exten => _00316XXXXXXXX,1,Dial(SIP/${EXTEN}@pstn)
exten => _+316XXXXXXXX,1,Dial(SIP/${EXTEN}@pstn)
exten => _0XXXXXXXXX,1,Dial(SIP/+31${EXTEN:1}@voipbuster)
exten => _XXXXXXX,1,Dial(SIP/+3172${EXTEN}@voipbuster)
exten => _00X.,1,Dial(SIP/${EXTEN}@voipbuster)

exten => s,1,Dial(SIP/spa3000&SIP/cisco7970, 20); Dial for 20 sec.
exten => s,2,VoiceMail(3000)

unfortunatly: even if the SPA3000 has the most recent firmware, it’s still not stable. After a call the line state/loop current can ‘hang’ causing the incoming line to be busy. There is no real solution for this other than a check+reset script.

crontab -e
# m h  dom mon dow   command
 */2  *  *   *    *    /srv/ spa3000

using the following script check if the line-state and the loop current are in sync. if not: reset the SPA3000. If you do not implement this script, you run the risk of the inbound  phone line being busy all the time.


ECHO="logger -t $SPA3000 -p user.notice"

        STATUS=`$WGET --keep-session-cookies --quiet --output-document=- http://$SPA3000/ |
            sed -n -e '/PSTN Line Status/,/Current/p' |
            sed -e 's/<\/font>/,/g'             \
                -e 's/<td>/ /g'                 \
                -e 's/<[^>]*>//g'               \
                -e 's/, Registration.*//'`

        echo $STATUS | grep "Hook State: On" > /dev/null
        if [ $? -eq 0 ]; then
                echo $STATUS | grep "Loop Current: 0.0" > /dev/null
                if [ $? -eq 1 ]; then
                        return 1
        return 0

if [ -z "$SPA3000" ]; then
        echo usage: `basename $0` '<spa-3000>' >&amp;2
        exit 4


$ECHO "Status $STATUS"

if [ $? -ne 0 ]; then
        $ECHO "$SPA3000 locked up - attempting to reboot"
        $WGET --keep-session-cookies --quiet --output-document=/dev/null http://$SPA3000/admin/reboot

        # allow time to reboot
        sleep 15


        $ECHO "Status $STATUS"

        if [ $? -ne 0 ]; then
                $ECHO "$SPA3000 locked up and reboot failed"
                exit 2
        exit 1
exit 0

Recording calls

If you wish to record (on demand) your calls done via asterisk, use this tutorial.





1 Reactie naar Asterisk @ Home

  1. Bas schreef:

    echo “Hello nerdy world”

Geef een antwoord

Het e-mailadres wordt niet gepubliceerd.

Time limit is exhausted. Please reload the CAPTCHA.