SPA3102 and FreePBX HOWTO

The target configuration

The target configuration for this HOWTO is an SPA3102 connected to the same LAN as the PBX, or at least a routed but non-NATted situation(we use this same configuration for an SPA3102 across a VPN). The SPA3102 will be connected to the LAN through the 'INTERNET' port, and to the PSTN through the 'LINE' port. Setting up the phone port is very easy, and you should look for another tutorial for this. If you decide to use the 'ETHERNET' port for something, that's fine, but you're on your own there too.

Why another howto?

Why another howto for getting the SPA3102 to play with FreePBX? Because the howtos I've seen just don't work for me. There was one I found once, actually, that was excellent: It walked you through steps, just as any other howto would, but broke it up into separate sections where the user would complete a set of steps and then do some tests to make sure that particular functionality was working before moving on. That works well for a user who's not an expert, but wants to narrow down what he has to debug at each step. I tried to follow this approach here. Suggestions welcome!

Audience

I'm quite familiar with UNIX, so it's natural for me to ssh in and run commands at the shell or to edit files. I'm not as familiar with VOIP, but I like to learn. If you know a little UNIX, and you're trying to learn about VOIP, then maybe this tutorial is for you! If you really prefer a cookbook recipe for how to do this and will rely on community support when things go wrong, another author, wiseoldowl on freepbx.org, recommends his excellent HOWTO to you.

I also assume you have a working FreePBX installed, and have set up an extension before, and generally know your way about the menus.

Quick links

LinkSys SPA3102 support page

SPA3102 IVR configuration menu documentation

Sipura dial plan documentation

ATA Administration Guide This 250 page manual covers several devices. It has a whole section on configuring the SPA3102 FXO port.

3am Systems' World PSTN Tone Database has disconnect (and other) tones from many countries. The raw information is available for free, and you can get the information in Asterisk and Sipura format, ready for cut and paste, if you register, which is free of charge, but requires you submit some information about yourself.

Another source for tone information is the International Telecommunication Union, who publish a PDF on this page: "VARIOUS TONES USED IN NATIONAL NETWORKS".

There's a giant thread about disconnect tones here on the Voxilla forums; the basic formula they supply is "f1@-30,f2@-30;n(t1/t2/1+2)", where f1/f2=frequencies in HZ (the same if only one tone), n=number of repetitions of the pattern, t1=seconds of frequency, t2=seconds of silence.

wiseoldowl's HOWTO on freepbx.org contains additional configuration options that you should consult after getting the basic setup working here. His has additional information about adjusting gain levels and other settings that might cause problems.

Planning

You'll need to have/decide the following things:

  • FreePBX's IP address; in this example, 192.168.7.6
  • SPA3102's IP address; in this example, 192.168.7.50
  • DNS names work in place of IP addresses, if desired
  • Make up a user name and password for the trunk; in this example, 'pstn' and 'pstnpass'
  • Choose an extension number and password for Line 1; in this example, '100' and 'line1pass'

Before you start

Before anything, you'll have to get the SPA3102 actually on your network.

  1. The SPA3102 should already be powered on with 'LINE', 'PHONE', and 'INTERNET' ports connected. The 'INTERNET' port should be plugged into your LAN.
  2. Reset the SPA3102 to factory default for good measure, since this tutorial depends on default settings being untouched. With the handset, dial '****', and wait for the IVR to begin. Dial '73738#' ('RESET#'), and '1' to confirm.
  3. Temporarily connect your workstation's NIC directly to the SPA3102's 'ETHERNET' port. Your workstation should grab an IP address from the SPA3102. Navigate to http://192.168.0.1/admin/advanced and use the username 'admin', password 'admin'. If you didn't get to your adapter's configuration page, check your network settings to be sure your NIC has an IP address on the 192.168.0.x subnet.
  4. Now's a good chance to update the firmware. As of 2008/11, the latest is 5.1.7, and these instructions are written for that firmware.
  5. Choose a static IP for the adapter on your LAN. Go to the "Wan Setup" tab.
    • In "Internet Connection Settings" select "Connection Type" "Static IP".
    • In "Static IP Settings" enter the static IP, the netmask, and the gateway. In this example, we'll choose '192.168.7.50'.
    • In "Remote Management" select "Enable WAN Web Server" "yes".
    • Leave other settings as is, and click "Submit All Changes". 01-wan-setup.jpg
  6. Connect your workstation's NIC back to your LAN. You can leave the SPA3102's 'ETHERNET' port unplugged from now on. You should be able to visit the adaptor's configuration page through the 'INTERNET' port through this URL (change the IP to match the one you chose): http://192.168.7.50/admin/advanced
  7. If this didn't work, go back and check your configuration. The IVR may be helpful to find out what's going on too; see the IVR link in the 'Quick Links' section above.
  8. Make sure you know how to log into your FreePBX system and get to the Asterisk command line with
    bash-3.1# asterisk -vvvr
    [...]
    bell*CLI>

Set up syslog on your PBX

Syslog is a handy way to debug the SPA3102.

  1. On the SPA3102 configuration page, 'Voice' tab, 'System' subtab,
    • Set the 'Syslog Server' and 'Debug Server' to the IP of your
      FreePBX, 192.168.7.6 in this example.
    • Set 'Debug Level' to 2 or higher.
  2. To set up syslogd on your FreePBX host,
    • Append the following to /etc/syslog.conf:
      # save messages from SPA3102
      local2.debug,local3.debug                /var/log/spa3102.log
    • Add a '-r' to the syslogd command line. On CentOS (incl. Trixbox), edit /etc/sysconfig/syslogd, and edit this line:
      SYSLOGD_OPTIONS="-m 0 -r"
    • Restart syslogd; on CentOS (incl. Trixbox):
      bash-3.1# service syslog restart
    • Make sure syslogd is listening on UDP 514:
      bash-3.1# netstat -ulnp | grep 514
      udp        0      0 0.0.0.0:514        0.0.0.0:*           1064/syslogd
    • Watch the log:
      bash-3.1# tail -f /var/log/spa3102.log &
  3. Alternatively, if you are running Windows and want to send syslog messages there for debugging (I recommend using your FreePBX host for syslog if possible, but of course each environment is different), install a Windows syslog daemon, such as http://syslog-win32.sourceforge.net/, and from step 1 above, replace the IP address with that of your Windows host.

Set up line 1

You'll need line 1 working for testing. If you already have another extension set up that you'd rather use, then skip this section.

  1. In FreePBX, add a SIP extension.
    1. Set the extension number, '100' in this example.
    2. Set a password, 'line1pass' in this example.
    3. You can configure the Display Name, Voicemail, etc. now if desired.
    4. "Submit" and "Apply Configuration Changes".
  2. On the SPA3102, navigate to the 'Voice' tab, 'Line 1' sub-tab.
    1. Under "Proxy and Registration", set "Proxy" to your FreePBX's IP, 192.168.7.6. Also set both "Make Call Without Reg" and "Ans Call Without Reg" to Yes. 02-1-line-1-setup.jpg
    2. Under "Subscriber Information" enter the extension number '100' as "User ID" and password 'line1pass' as "Password". 02-2-line-1-setup.jpg
    3. Under "Dial Plan", set the "Dial Plan" to "([*x]x.)". This routes every number that begins with '*' or '0'-'9' to the PBX. See the dial plan documentation link in 'Quick Links' above. 02-3-line-1-setup.jpg
    4. Click "Submit All Changes"
  3. Still under the 'Voice' tab, navigate to the 'Regional' tab, and clear out all the *XX entries under 'Vertical Service Activation Codes'. With these in place, the feature codes will be intercepted by the SPA3102 and never make it to the PBX.
  4. At the asterisk prompt now, verify that the SPA3102 has registered using
    bell*CLI> sip show peers
    Name/username              Host            Dyn Nat ACL Port     Status
    [...]
    100/100                    192.168.7.50     D   N      5060     OK (15 ms)
    5 sip peers [Monitored: 4 online, 1 offline Unmonitored: 0 online, 0 offline]
  5. Try dialing an extension to make sure it's really working. If you set up voicemail, you can dial *97 to test.
  6. If you don't see the extension registered or can't dial the PBX, check your settings and get this working before going on.

Configure the PSTN

Next step, the hard part, and the main goal of this tutorial: Configure the FXO port of the SPA3102.

Configure outgoing calls

We'll configure outgoing calls first.

  1. In FreePBX, configure a new SIP trunk.
    1. Set the 'Trunk Name', in this example, 'pstn'. This is the trunk user name you chose in the 'Planning' section above.
    2. Set 'Maximum Channels' to '1', since there is only one PSTN line.
    3. Set the 'PEER Details' as follows (you can leave out comments preceded by ';'):
      canreinvite=no
      context=from-pstn
      host=192.168.7.50
      nat=no
      port=5061
      user=pstn   ; set the same user name as the trunk user name
      secret=pstnpass
      type=friend
      qualify=yes
      dtmfmode=rfc2833
    4. Set your "Dial Rules" if you like, or just leave blank.
    5. Click "Submit Changes", and "Apply Configuration Changes".
  2. On the SPA3102 "Voice" tab, "PSTN Line" subtab,
    1. Under "Proxy and Registration",
      1. Set the "Proxy" to FreePBX's IP address
      2. Set "Make Call Without Reg" and "Ans Call Without Reg" to Yes

      03-1-pstn-setup.jpg

    2. Under "Subscriber Information", set "User ID" to the FreePBX 'Trunk Name' above, 'pstn', and the 'Password' to the FreePBX trunk's 'secret', 'pstnpass'. 03-2-pstn-setup.jpg
    3. Click "Submit All Changes"
    4. Check the Asterisk command line and make sure the SPA3102 has registered:
      bell*CLI> sip show peers
      Name/username              Host            Dyn Nat ACL Port     Status
      [...]
      pstn/pstn                  192.168.7.50     D          5061     OK (7 ms)
      100/100                    192.168.7.50     D   N      5060     OK (7 ms)
      5 sip peers [Monitored: 4 online, 1 offline Unmonitored: 0 online, 0 offline]
    5. If you don't see the 'pstn/pstn' registration, go back and check your settings.
    6. Back in FreePBX, create a new Outbound Route.
      1. Set the route name, perhaps to 'pstn' or something more specific.
      2. Set the 'Dial Patterns', using the wizard, or creating your own custom patterns.
      3. Set the 'Trunk Sequence' to your new trunk, 'SIP/pstn'.
      4. Click 'Submit Changes' and "Apply Configuration Changes".
      5. Try making an outgoing PSTN call. If it doesn't work, check the output at the Asterisk command line and the Syslog.

Configure incoming calls

  1. On the SPA3102 'Voice' Tab, 'PSTN Line' again,
    1. Scroll down to the 'PSTN-To-VoIP Gateway Setup' section.
      1. Set 'PSTN Ring Thru Line 1' to No
      2. Set 'PSTN Caller Default DP' to 2

      03-3-pstn-setup.jpg

    2. Scroll back up to 'Dial Plans', and set 'Dial Plan 2' to 'S0(<:01082113130>)', replacing '01082113130' with your inbound DID number. This routes all incoming calls to 01082113130@pbx.ip.ad.dr. See the dial plan documentation link in 'Quick Links' above. 03-4-pstn-setup.jpg
  2. On the FreePBX page, add an inbound route:
    1. 'Description' could be 'pstn'
    2. 'DID Number' should be exactly the same as the DID in your 'Dial Plan 2', '01082113130' in the example
    3. Scroll down to 'Set Destination' and set to extension '<100>' for now so we can test.
  3. Call your PSTN DID from your cell, and cross your fingers that extension 100 rings!
  4. If it didn't ring, look at the Asterisk command line output, along with the syslog.

Other configuration

The following configurations are recommended, and the first and second should be considered mandatory.

  1. On the SPA3102 'Voice' tab, 'Sip' subtab, 'RTP Parameters' section, set 'RTP Packet Size' to '0.020' instead; check here for a discussion on this. 04-2-sip-settings.jpg
  2. Change the SPA3102's user and admin passwords in the 'Voice' tab, 'System' sub-tab.
  3. Add dialing rules for the trunk, if desired.
  4. China: disconnect?
  5. SPA3102, 'Voice', 'PSTN Line':
    1. 'Subscriber Information' section, set 'Display Name' to something like 'LOCAL PSTN CALL' to send this string as caller ID when no caller ID is provided by the PSTN.
    2. PSTN-To-VoIP Gateway Setup', set 'PSTN CID For VoIP CID' to Yes to support caller ID
    3. 'FXO Timer Values (sec)' section, set 'VoIP Answer Delay' to between 2 and 5 to give the caller ID signal a chance to come through
    4. 'PSTN Disconnect Detection' section, set 'Disconnect Tone' if you're not in the US, and the SPA3102 has difficulty detecting when the PSTN caller has hung up. See the 3am Systems link in the 'Quick Links' section above. In China, set the string to
      450@-45,450@-45;4(0.35/0.35/1+2)
  6. SPA3102, 'Router', 'WAN Setup':
    1. Add a hostname and domain information. Why? Because it's cool.
    2. Add DNS information, especially if the WAN connection type is set to 'Static IP' rather than 'DHCP'.
    3. Add NTP servers so that the time is always synchronized. See http://www.pool.ntp.org/ for a list of servers in your region. DNS must be configured for this to work.
    4. 04-1-more-wan-settings.jpg

Troubleshooting and Debugging

I had all kinds of trouble getting this to work, even though it's a fairly simple setup. As all the other guides will tell you, it's best if you can start from defaults: clear out your trunk and in/outbound route definitions, reset the SPA3102 to factory defaults, and start from scratch, only changing the minimum number of settings. You can enable the fancier settings later on, but they really can mess you up if you try setting them too early without an initial working configuration.

After writing the main part of this article, I then went to repeat these instructions for a remote Sipura at the office. Outgoing calls worked fine, but incoming calls wouldn't pick up. I went through and checked all the SPA3102 settings very carefully, over and over, but nothing helped. Finally I went to the Asterisk side and did some SIP debugging over there. After a few hours of tracing the FreePBX dialplans and comparing them to my home setup, well, it turned out the difference was that I'd turned on NVFAX fax detection early on when I created the inbound route, and forgot all about it. This is an example of why you should keep it vanilla until you have a working configuration.

The way to debug is to log onto your Asterisk box, and use the Asterisk commandline:

bash-3.1# asterisk -vvvr
Asterisk 1.4.20-1 RPM by vc-rpms@voipconsulting.nl, Copyright (C) 1999 - 2008 Digium, Inc. and others.
[...]
bell*CLI>

Enable SIP debugging for your SPA3102:

bell*CLI> sip show peers
sip show peers
Name/username              Host            Dyn Nat ACL Port     Status
pstn/pstn                  192.168.7.50                5061     OK (11 ms)
100/100                    192.168.7.50     D   N      5060     OK (7 ms)
[...]
4 sip peers [Monitored: 4 online, 0 offline Unmonitored: 0 online, 0 offline]
bell*CLI> sip set debug peer pstn
sip set debug peer pstn
SIP Debugging Enabled for IP: 192.168.7.50:5061
bell*CLI>

In this script trace, we listed all peers using the 'sip show peers' command, where we saw
our trunk, 'pstn'. Then we enabled SIP packet tracing with 'sip set debug peer pstn'. This causes all SIP packets to be dumped out on the commandline. There may be copious output, so make sure the scrollback on your terminal software is set large enough to capture everything you need.

To stop the debugging, use 'sip set debug off'. The way I debug is to get everything ready to test, then turn on debugging the very moment before I initiate the call. Once the call fails, I then quickly turn off debugging so that all of the output is relevant.

A typical SIP session goes as follows. I will show the trace from a PSTN to VOIP call, with the SPA3102 initiating:

  • SPA->*: INVITE sip:01082113130@192.168.7.6 SIP/2.0
    • The Sipura 'invites' Asterisk to initiate a call.
    • sip:01082113130@192.168.7.6 is the SIP URL on the asterisk side; the 010...3130 is matched with the 'DID' on the incoming route.
    • Asterisk should output a message like "Found peer 'pstn'" that shows it recognizes the Sipura.
  • *->SPA: SIP/2.0 407 Proxy Authentication Required
    • This is only if you have passwords configured. I think. I set up two indentical Sipura and FreePBX configurations, but one was Trixbox (Asterisk 1.4), the other PIAF (Asterisk 1.6). Trixbox asks for Proxy Authentication, but PIAF doesn't. I don't know why, yet.
  • SPA->*: ACK sip:01082113130@192.168.7.6 SIP/2.0
    • The Sipura acknowledges the '407 Proxy Auth Required' message.
  • SPA->*: INVITE sip:01082113130@192.168.7.6 SIP/2.0
    • The Sipura sends a new invite; this time, there is a 'Proxy-Authorization' header with a username and MD5 password digest.
    • Again, Asterisk should output "Found peer 'pstn'"
    • It will also print some information about audio codecs, RTP ports, etc.
  • *->SPA: SIP/2.0 100 Trying
    • If Asterisk didn't send a 407 Proxy Auth Required, this would have been next after the Sipura's initial INVITE message.
    • Asterisk notifies the Sipura that it is attempting to establish the call.
    • At this point, you should see the normal Asterisk dialplan tracing going on; you can follow along in your files if the problem lies here.
    • Asterisk prints out: "Executing [s@ivr-4:7] Answer [...] in new stack"; everything checks out, and it will begin the call.
  • *->SPA: SIP/2.0 200 OK
    • Asterisk sends an 'OK' along with some data about its own RTP stream.
  • SPA->*: ACK sip:01082113130@192.168.7.6 SIP/2.0
    • The Sipura acknowledges the OK message.
    • At this point, Asterisk and the Sipura have finished setting up the call, and should be exchanging voice data via the negotiated RTP stream.

If you have enabled Sipura debugging through your syslog, you should be able to see an abbreviated version of the Sipura's status.

And that's the basics for debugging. Call set up should go through this basic sequence, which is actually pretty simple, despite the large amount of output. Google is your friend here when deciphering deviations from this sequence.

53 Comments

Tim SmithNovember 18th, 2008 at 6:15 pm

Hi,

This tutorial is great and having followed it, my system is working with one small issue! When I call my DDI from the mobile phone, I get the ringing tone on the mobile but its about 6rings before the phone on extension 100 starts ringing - any ideas? As an aside, it then stops ringing and I get 3 beeps but i i think thats the Sipura answering so I should be able to turn that off.

Is there any way with the dial plans to still by-pass the Voip and which to PSTN when calling from the phone? I want to be able to make it easy if the Asterisk box fails.

Thanks again for the great tutorial!

Tim

jmanNovember 18th, 2008 at 9:30 pm

Hi Tim, glad you got your SPA3102 working. It can be tricky sometimes!

One setting you might look at is “PSTN Answer Delay” in the “FXO Timer Values” section under the “PSTN Line” tab; mine’s set to 3 seconds. I seem to recall it was set to 15 seconds by the factory, but my memory’s flakey.

You should be able to set the Line 1 dial plan to always dial straight out the PSTN line. This may not be necessary though; check the “Line 1″ tab in the “VoIP Fallback To PSTN” section, and set “Auto PSTN Fallback” to yes. You should find that if Asterisk is unavailable, calls will be routed out through the PSTN.

Hope this helps.

Tim SmithNovember 19th, 2008 at 7:02 am

Hi

Thanks for the help. I got the answer delay sorted, but unfortunately the VoIP fall back didnt work. Managed to fix that with the dialplan though…

I hope you dont mind, but I have another question! Everything works great now, with the exception of one thing. When calling in via the PSTN, the call does ring extension 100. I actually set up a ring group to ring Exten100, and then Exten100 and 101, etc… However as soon as Exten 101 starts ringing, the calls drops back and I hear “beep beep beep” and then silence and then the beeps repeated. This happens even if I just have exten 100 ring though.

To me this sounds like the Sipura asking for the PSTN - to - VoIP pin, but I cant understand why. I have used your configuration above and aside from that, the VoIP part of the call (through tho the asterisk) has already happened….

Im really confused and any advice would be appreciated.

Thanks

Tim

jmanNovember 20th, 2008 at 9:21 pm

Hi Tim. The dialplan might be a more elegant solution to PSTN fallback. If you do it right, you should be able to dial internal extensions through your PBX as well as outside numbers through the trunk.

Your new problem doesn’t ring a bell (pun unintended), but you should watch your asterisk console and your syslog to see whether the beeps are coming from the Asterisk side or the Sipura side. Also, you might try setting up X-lite or another softphone on extension 102 to see whether you get the same beeps dialing ext. 100 directly, which would point to Asterisk being the problem.

If you narrow it down to the Sipura, I’d be happy to share my configs with you so you can compare with a fine-toothed comb.

Good luck!

TiminatorJanuary 22nd, 2009 at 6:58 am

Eurika

Tim I was beginning to think this couldn’t be done.
Thank-you!
Thank-you!
Thank-you!

TiminatorJanuary 23rd, 2009 at 1:09 pm

jman

Can you help me please!

I have followed your set up and all works excellent except….

All I get for CID from external callers is my sip trunk name (pstn)

Any help would be appreciated

jmanJanuary 23rd, 2009 at 4:59 pm

Timinator,

I’m glad your setup is nearly working.

In the “PSTN-To-VoIP Gateway Setup”, try setting “PSTN CID for VoIP CID” to yes.

I don’t have CallerID here, so please let me know if this works for you, and I’ll change my HOWTO.

If you have any more suggestions for how this could have been more useful to you, let me know!

TiminatorJanuary 24th, 2009 at 2:27 am

jman,

Tried that and tried that again. Didn’t work.

My linksys spa3102 does show the proper info on the info page, it just doesn’t seem to get to or through trixbox to the extensions (soft or hard)

jmanFebruary 4th, 2009 at 10:52 am

Timinator,

Sorry for the delay, we’ve been on holiday for the Chinese Spring Festival. Happy Niu (Ox) Year!

I don’t know what the problem with your CallerID is, but here are things to check:

Is the spa3102 receiving the CallerID correctly? Check the Voice/Info tab, PSTN Line Status, “Last PSTN Caller” should show the CallerID of the last PSTN caller. The spa3102 syslog file also has this information.

Is the spa3102 sending CallerID, and is asterisk receiving it? As in the “Troubleshooting and Debugging” section above, enable SIP debugging for the spa3102, and phone in from outside. The third SIP packet or so should be a “101 INVITE” packet, with a header like this:

From: CHINA PSTN <sip:15810548686@192.168.3.19>;tag=40a064a83b5e0d94o1

The number “15810548686″ is the CallerID number, and the “CHINA PSTN” is the CallerID name (we don’t have CallerID name in China, so this default comes from the config above in “Other configuration”, 5.1).

Be sure you’ve done the configurations above in “Other configuration”, 5.1 through 5.3.

Get back when you’ve tried these and let me know what you’ve found.

David KFebruary 13th, 2009 at 8:26 am

Hi jman,

Happy Belated Niu Year!

I followed your instructions and everything appears to be working, but I get a busy signal after I dial out.

Do you know how to interpret debug messages from the Sipura?

Feb 12 16:15:07 sipura [1:0]AUD ALLOC CALL (port=16400)
Feb 12 16:15:07 sipura [1:0]RTP Rx Up
Feb 12 16:15:07 sipura AUD:Stop PSTN Tone
Feb 12 16:15:07 sipura CC:Connected
Feb 12 16:15:07 sipura AUD:Stop PSTN Tone
Feb 12 16:15:07 sipura [1:0]ENC INIT 0
Feb 12 16:15:07 sipura [1:0]RTP Tx Up (pt=0->c0a87b48:17622)
Feb 12 16:15:08 sipura [1:0]RTCP Tx Up
Feb 12 16:15:08 sipura FXO:Stop CNDD
Feb 12 16:15:08 sipura [1:0]RTP Rx 1st PKT @16400(2)
Feb 12 16:15:08 sipura [1:0]DEC INIT 0
Feb 12 16:15:08 sipura FXO:CPC
Feb 12 16:15:08 sipura AUD:Stop PSTN Tone
Feb 12 16:15:08 sipura FXO:Stop CNDD
Feb 12 16:15:08 sipura AUD:Stop PSTN Tone
Feb 12 16:15:08 sipura [1:0]AUD Rel Call
Feb 12 16:15:08 sipura DLG Terminated 2b60d8
Feb 12 16:15:09 sipura Sess Terminated
Feb 12 16:15:40 sipura CC:Clean Up

Thanks in advance.

BTW, are you near the CCTV HQ?

jmanFebruary 13th, 2009 at 10:08 am

Hi David, Happy Niu Year yourself! I’m in Wudaokou, not so near CCTV, but not so far. Are you thinking of the fireworks disaster? That’s a pretty inauspicious event for the New Year. Are you in Beijing?

These logs don’t tell me much. It looks like the RTP session is being established, but it doesn’t give much information about the call setup. Do you have the output from asterisk -vvvr as well? That’s probably the place to start, since it’ll tell you how the call’s being routed, and the reason (though probably not verbosely enough) for the call’s termination.

There’s also information on the SPA3102’s Voice Info tab about the last calls made and disconnect reason, so take a look there.

David KFebruary 13th, 2009 at 3:28 pm

Hi jman,

I am writing from Los Angeles. I would love to visit Beijing some day. Yeah, I was thinking of the fireworks disaster. What a shame.

The log shows the following (hope there’s enough detail):

Asterisk: INVITE sip:18665551212@192.168.123.247:5061 SIP/2.0
Sipura: SIP/2.0 100 Trying
Sipura: SIP/2.0 180 Ringing
Sipura: SIP/2.0 200 OK
Asterisk: ACK sip:18665551212@192.168.123.247:5061 SIP/2.0
Sipura: BYE sip:310XXXXXXX@192.168.123.72 SIP/2.0
Asterisk: SIP/2.0 200 OK

On the SPA3102, “Last PSTN Disconnect Reason” is CPC Signal.

jmanFebruary 14th, 2009 at 5:30 pm

Hi David, Beijing is a great place to visit if you’re seeking a crazy adventure rather than relaxation and comfort. I recommend it highly if you like the former style of vacation.

It looks like the Sipura is successfully routing the call to the PSTN, but then hanging up. Do you have a phone line splitter that you could listen in with a handset to confirm the Sipura is actually picking up the phone line? Anyway, it appears the hangup is because it’s detecting a CPC signal. This could be a false positive. Try going to the Voice/PSTN Line tab, PSTN Disconnect Detection section, and set Detect CPC to No. I’m just guessing here, since I don’t have this problem.

Good luck!

jmanFebruary 15th, 2009 at 7:02 pm

David, while avoiding what I ought to be doing, and browsing around about the CPC problem instead, I found a paragraph here that might describe your problem:

There’s often a short open (0 volts DC) on a phone line just after you go off-hook, or just after you’ve finished dialing a phone number. These are usually very short opens, like 20 to 50ms. If your phone system Open Loop Disconnect timer is set at 50ms, you may never be able to make a call because every call would be cut-off as soon as you went off-hook or were finished dialing. That Open Loop Disconnect Timer is very important!

If the “Detect CPC” setting works for you, you might try re-enabling it and playing with the “Min CPC Duration” option, since CPC, if you phone line supports it, can help the Sipura tell if other side of the PSTN phone call has hung up.

David KFebruary 18th, 2009 at 5:44 am

jman,

Didn’t have time to play with the “Detect CPC” setting until now. That certainly did the trick, I can dial out from my PSTN line now! Will try playing with “Min CPC Duration” and report my findings here. Thank you so much!

Will buy you a beer next time I am in Beijing, hopefully, within the next few years :) I travelled for a couple weeks in the Hua Dong area a couple years ago. Can’t wait to go back.

You should blog about your life in Beijing, I am sure a lot of people would be interested.

Thanks again!

David KFebruary 19th, 2009 at 9:41 am

jman,

Bumping the “Min CPC Duration” value from 0.2 to 0.3 worked intermittently, so I settled on 0.5 just in case.

jmanFebruary 20th, 2009 at 11:24 pm

David, Hua Dong means Shanghai, Nanjing, Zhejiang, etc. areas? I’ve spent some time in Suzhou, which has a nice, relaxed atmosphere, in some ways like Austin, my hometown. Can’t wait to go back.

Glad the CPC settings worked for you. If you verify that incoming callers hanging up on your voicemail don’t leave long recordings of busy signal tones, then you’re home free. Enjoy!

LukaszMarch 25th, 2009 at 9:41 pm

Awsome tutorial!! it worked for me.

JCMay 6th, 2009 at 4:36 am

jman, Awesome documentation. I had my AsteriskNOW 1.5 up and running from start to finish in under 1.5 hours. (I’m pretty methodical otherwise it would have been faster!) In any case, now that I can do both inbound and outbound pstn calls I’d like to be able to send all pstn calls to an unattended distribution with both the analog phone and soft ip phones being possible destinations. Is there a doc on this, or is this pretty straight forward. Thanks for you help in advance. JC

jmanMay 8th, 2009 at 12:42 am

Hi, JC, glad it worked for you, but AsteriskNOW, you say? I’m a little confused; these instructions are for CentOS + FreePBX, which is similar to AsteriskNOW, but different.

By ‘unattended distribution’, do you mean an IVR, where the caller is greeted with a recording, and the option to dial your extensions? Just make sure the IVR and recordings modules are enabled, record your greeting, and create an IVR for it. You can set the incoming route’s destination to the IVR. Check the FreePBX docs.

Good luck!

DaveNoviceMay 25th, 2009 at 8:08 pm

Under Configuring incoming calls, the dial paln statement:

“2. Scroll back up to ‘Dial Plans’, and set ‘Dial Plan 2′ to ‘S0()’, replacing ‘5551212′ with your inbound DID number. This routes all incoming calls to 5551212@pbx.ip.ad.dr. See the dial plan documentation link in ‘Quick Links’ above.”

Should that be ‘(S0)’, where XXX is the US area code and 5551212 is your seven digit number? I’m a little confused here.

Also, if the phone service is thru a VOIP provider, how should the tutorial change to incorporate the SIP credentials from the VOIP provider. I have the PSTN (POTS) line working fine, but cannot get the VOIP connect to the PBX. Any help will be welcome.

jmanMay 26th, 2009 at 12:53 am

DaveNovice,

Sorry for the confusion. I fixed the instructions; I have my Beijing phone number in there, and didn’t finish my attempt at removing real numbers. Anyway, check again, everything should be consistent, and make a little more sense now.

As for your VOIP provider, there’s a lot of documentation out there for this, and different providers are different. Here’s my incoming trunk for Vitelity:

Trunk name: vit-in
Peer details:
type=friend
username=myusername
secret=mypassword
context=from-trunk
insecure=very
canreinvite=no
host=inbound2.vitelity.net
disallow=all
allow=ulaw
qualify=yes

Register String: myusername:mypassword@inbound2.vitelity.net:5060

Vitelity requires separate trunks for incoming and outgoing (because different hosts); other companies only need one for both incoming and outgoing. Check your provider (many have asterisk@home/FreePBX sample setups) and the FreePBX forums for samples customized for your provider.

Good luck!

DienoJune 2nd, 2009 at 11:23 am

Is there a way to Avoid the call origination, like it established the full call with SPA3102 rather then wainting for the dialed party to pickup.

Is there any configuration to skip the call establishing before call establish on PSTN, like we do in X100 call never establish unless dialed party picks the Fone.

Thanks in advance.

DanieleAugust 13th, 2009 at 7:52 pm

Many thanks for you guide, it worked perfectly for me, and really good you covered every part of the spa3102 configuration.

Great Work!!!

Daniele

[...] guida la trovate a questo link: Guida, e devo veramente ringraziare l’autore del post/proprietario del [...]

Gerard BraadSeptember 12th, 2009 at 3:32 am

Thanks for the CPC (Calling Party Control) discussion. I had the same error when using my PSTN line (in Beijing)… changed the setting to 0.5 and problem solved. I can now use the PSTN line as intended. Thanks.

RicardoOctober 24th, 2009 at 1:42 am

These are byfar the best instructions on how to implement the SPA3102 with Asterisk. I had actually given up trying to make all components work. Every instructions out there seem to work but could not provide a complete solution i.e. (Inbound, Outbound and FXS) to work all together. Had a down day at work so I reset my device as instructed and everything is working well. I’m so happy, takes a lot to make this nerd happy.

chopetaOctober 28th, 2009 at 5:53 am

Thank you so much!!! You are the man!!!

albertJanuary 11th, 2010 at 7:21 am

¿has anybody answered this comment from Dieno? (see below) The SPA3102 sends the 200 OK SIP message before the called party picks up the phone. Even, it sends this message before off hook the PSTN Line. ¿is there any parameter to configure in SPA3102 to delay the 200 OK SIP message until the called party picks up the phone? I’ve heard GRANDSTREAM ATA alows it.

Is there a way to Avoid the call origination, like it established the full call with SPA3102 rather then wainting for the dialed party to pickup.

Is there any configuration to skip the call establishing before call establish on PSTN, like we do in X100 call never establish unless dialed party picks the Fone.

Thanks in advance.

jmanJanuary 13th, 2010 at 11:01 am

I’m sorry Albert, I’m not aware that the SPA3102 has this capability. As far as I know, POTS doesn’t have special signaling for when the called party picks up. Please correct me if I’m wrong. If this is true, then the Grandstream must listen for the ringing tone, clicks, or voice frequencies, which is non-standard and likely to be unreliable.

If you find a solution, let me know. This is a good reason to go with a VOIP service or a digital line, if you’re in an area where this is feasible and it is not cost prohibitive.

RamoncioApril 13th, 2010 at 6:02 pm

Man thanks a lot for this great tutorial.
I followed some other tutorials (including that Wiseoldolw great one) but never got the PSTN line working, but finally I got it!!
Thanks again, finally I have PSTN working with my imac mini powerpc!

jmanApril 13th, 2010 at 7:53 pm

Awesome Ramoncio, thanks for the feedback, and glad you’re up and running!

alexMay 12th, 2010 at 9:48 pm

Thank You so much for this very concise tutorial, the only one that worked right as expected.
I am now wondering a couple of things if and how would be possible to assign an asterisk extention to the FXS port and
if upon an incoming call on the FXO port, ring more then one asterisk extentions and connect the firtst one to pick up…

Cheers,
alex

jmanMay 12th, 2010 at 11:56 pm

Hi Alex, glad it worked for you.

You’re trying to set up a hunt group. Look up the ‘follow me’ settings documentation on FreePBX. Essentially, go to the extension, click the ‘Add follow me settings’, put the extensions in the list, and choose the appropriate ring strategy.

alexMay 18th, 2010 at 4:40 am

Hi jman,

Thanks for the “follow me” hint, got it working meanwhile with the “Ring groups” module.

It has been working fine so far, but since a couple of hours ago, I’m getting “503 Service Unavailable” messages from the 3102 (congestion from asterisk) on pstn inbound calls… Havn’t touched the 3102 in the last 5 days, and getting insane :(

jmanMay 18th, 2010 at 4:49 am

Hi Alex,

Where are you seeing those 503 errors?

Try to follow the part in the tutorial about sending the SPA’s logs over to your PBX. That may give you some extra clues. Also, there’s a VOIP status page on the SPA (don’t have this in front of me) that tells the reason for the last failed call. See if there’s any more info there.

On the Asterisk side, you should have console logging on (asterisk -vvvr); if the SPA is actually getting SIP messages to Asterisk, there should be info about the SIP conversation logged to the console.

joeleeneJune 8th, 2010 at 12:30 pm

Hi I have a Linksys Spa 3102, I am using a cordless uniden answering machine phone with it. How can I get my answering machine to take the call instead of the Linksys voicemail?

jmanJune 8th, 2010 at 1:43 pm

Hi Joeleene, I’m guessing you’re not using FreePBX? The LinkSys doesn’t have voicemail of its own. What VOIP service are you using? You should check with them and ask them to turn off voicemail, or else increase the number of rings before it answers so the uniden answers first.

Good luck!

[...] Uno lo configuré como extensión conectandolo al puerto que dice Phone (FXS), este fue el má sencillo de configurar siguiendo la guía SPA3102 and FreePBX HOWTO. [...]

Corey KoltzJuly 23rd, 2010 at 6:00 am

Thank you for your post, it helped me get my Linksys SPA3102 connected with my Asterisk/FreePBX system. I had the same problem where the callers phone rang three times before it started ringing my phone. Maybe add that to the tutorial (if you can edit it). I also had it automatically go to voicemail after 10 second (two rings), so I changed it to 30 which was about five rings. Otherwise works great.

jmanJuly 23rd, 2010 at 9:04 am

Hi Corey, what was the cause behind the first rings not being passed through to your phone? Same as Tim Smith’s problem (first comment)?

Thanks for the suggestions, and glad you’re up and running.

AdrianAugust 5th, 2010 at 7:50 pm

Thanks, the first tutorial that worked and was easy to follow. You saved my spa3102 from a flight out the window.

JahydeDecember 13th, 2010 at 7:46 am

Great guide, just thought I’d let you know - your nextgen-gallery plugin is not generating the images correctly ;)

DennisJanuary 9th, 2011 at 12:13 pm

About callee answer detection, some phone companies provide DC reversal when the callee answers. This can be enabled under PSTN Line by setting “Detect Polarity Reversal” to yes. Also, for incoming calls, you want “Off Hook While Calling VoIP” set to no. One other problem thatg arises with some phone companies and when your SPA is behind a PBX is that the line voltage is 24volts instead of 48 volts. If this is the case, the SPA will assume the line is always in use, and not allow outgoing calls. To fix, set the “Line In Use Voltage” to 18 or so instead of 30.

CecilApril 24th, 2011 at 11:25 am

Hey maybe someone can help you I got everything working to the point where I can make outgoing calls but I can’t seem to figure out this DID number business. I have a linksys sap3102 anyone have any input

[...] Uno lo configuré como extensión conectandolo al puerto que dice Phone (FXS), este fue el má sencillo de configurar siguiendo la guía SPA3102 and FreePBX HOWTO. [...]

ParadigmJune 27th, 2012 at 5:50 am

Hi. But what a bout behind the NAT. Anybody has a recommendation?!!!

jmanJune 27th, 2012 at 6:26 am

The SPA behind NAT should work fine.

FreePBX behind NAT will work if your NAT is Linux, you have the SIP conntrack modules installed, and you forward the incoming SIP UDP port.

FreePBX behind other NATs might work, but you’ll have to consult the router documentation. To get it to work, most likely it will be similar to what I said for Linux routers: forward the incoming SIP UDP port to your FreePBX box, and look around in the configs if there are any settings to enable for SIP.

RashidJuly 2nd, 2012 at 1:09 am

Hello,

This guide was great; thank you very much!

I only have one issue in that when I make a call, it takes about 10 seconds before the destination number starts ringing. Is there a setting which controls this?

jmanJuly 2nd, 2012 at 5:12 am

Hi Rashid,

Glad the guide almost worked for you.

Hmm, that doesn’t ring a bell (no pun intended). I would bring up the asterisk console (asterisk -vvvc) and watch what happens as you make your outgoing call. If you watch and read carefully, you should be able to figure out where the delay is happening: from the SPA to Asterisk, or from Asterisk to your VOIP provider.

Good luck, and let me know if you succeed or if you need more help.

PadenAugust 8th, 2012 at 6:19 am

Better than any guide I have ever read about the SPA3102. Very informative and with enough information to give you a broader understanding of what is really going on. I’m more of a linux noob so I used http://www.thestarsoftware.com/syslogdaemonlite.html to log the system files on windows. Worked great :)

jmanAugust 9th, 2012 at 1:41 am

Hi Paden, glad it worked for you! Thanks for the idea to run syslog on Windows. I always promote open source software, so here’s a free/libre open source windows syslog daemon:

http://syslog-win32.sourceforge.net/

Thanks again. I’ll put a pointer in the article with your good idea.

BTW, nice Feynman story on your website. My dad was his student at Caltech long ago, and he and I are inspired by Feynman’s type of genius.

krisJanuary 15th, 2014 at 12:43 am

hello I say first of all a big thank you for this tutorial. I’m tracking but when I launch an outgoing call I hear the circuits are busy now please try again later

Leave a comment

Your comment