Bluetooth support for Asterisk

I’ve been looking for a Bluetooth plugin for Asterisk for a while, so my home Asterisk server can pick up incoming calls to my cell phone and route them onto my home phone network. I’m certainly not alone in this–it comes up monthly on the Asterisk-users mailing list.

It looks like the wait is nearly over–Theo Zourzouvillys announced a bluetooth driver for Asterisk this morning. It’s apparently still rough around the edges, and it’s only been tested with a single model of phone, but it works for him now, and the Asterisk community is pretty good at picking up things like this and enhancing them.

I’m going to play with this this weekend and see if I can get it to work with my T616; if so, it’d be a nice addition to my home phone system.

Posted by Scott Laird Wed, 20 Oct 2004 17:21:32 GMT


Asterisk configuration language improvements

While I like Asterisk, and I’ve been very impressed with its abilities, it has a few things that need improvement. One of those is its configuration language. To get a feel for it, here’s a snippet out of my current configuration:

[macro-outsideline]
  exten => s,1,AbsoluteTimeout(7200)
  exten => s,2,SetCDRUserField(Outside (${CHANNEL}))
  exten => s,3,Macro(cidfix)
  exten => s,4,Macro(dbcallforward)
  exten => s,5,Macro(setalertinfo)
  exten => s,6,LookupBlacklist
  exten => s,7,Dial(${PHONES},13,Ttmr)
  exten => s,8,Answer
  exten => s,9,Goto(outside-ivr,s,1)
  exten => s,107,Goto(206)
  exten => s,108,Goto(7)
  exten => s,207,Wait(3600)
  exten => s,208,Hangup

The [something] block starts a new context; any context that starts with macro- can be called as a subroutine from other contexts. Inside of each context, you can have multiple extensions. In this case, all 13 lines refer to the s extension, which acts as a sort of default. The next field after the extension identifier is the priority field, but it’s really just a line number. If you want to insert a new line at the beginning, then you need to manually renumber all of the other lines–look at line 107, and you’ll see a reference to line 206, which doesn’t exist–at some point I manually renumbered this macro but missed that line.

Even worse, error handling is just nasty–look at line 7: it dials some phones. If it succeeds, then it never really returns–when the conversation is over, the user hangs up which terminates the call. If the Dial command times out (no answer), then it goes to line 8. If there’s an error, then it implicitly jumps ahead 101 priorities, to line 108. Now look at line 6: the LookupBlacklist works more or less the same way–if the caller matches the blacklist, then *it* jumps ahead 101 lines as well. What happens when you put LookupBlacklist and Dial right next to each other? Look at lines 107 and 108–you only have a single priority number to use for handling the LookupBlacklist match, because Dial errors will show up on the very next line.

Needless to say, there’s a lot of desire to improve Asterisk’s configuration language. Watching the mailing list, there are a lot of proposals. I’ve seen a couple requests for TCL and a couple serious proposals for XML. While I don’t have anything against XML for storing structured data, it’s a horrid format for programming languages, and that’s really what we’re talking about here.

Anyway, no matter where Asterisk’s configuration language goes in the future, there are already a couple small improvements in the post-1.0 CVS tree–you can now use a priority of n to mean ‘the next number’, s to mean ‘the same number’, plus you can add labels and numeric offsets. Here’s the configuration from above using the new changes:

[macro-outsideline]
  exten => s,1,AbsoluteTimeout(7200)
  exten => s,n,SetCDRUserField(Outside (${CHANNEL}))
  exten => s,n,Macro(cidfix)
  exten => s,n,Macro(dbcallforward)
  exten => s,n,Macro(setalertinfo)
  exten => s,n(blacklist),LookupBlacklist
  exten => s,n(dial),Dial(${PHONES},13,Ttmr)
  exten => s,n(ivr),Answer
  exten => s,n,Goto(outside-ivr,s,1)
  exten => s,blacklist+101,Goto(wait)
  exten => s,dial+101,Goto(ivr)
  exten => s,blacklist+201(wait),Wait(3600)
  exten => s,n,Hangup

It still doesn’t fix the blacklist/dial collision, but it gets rid of all of the other numbering problems. If I wanted to add another line at the top, I wouldn’t have to renumber anything–everything would Just Work. On the other hand, the line numbers are still there, they’re just not quite as obvious. So I suppose we can call this a pragmatic improvement, even if it doesn’t help the aesthetics of the language much.

On the other hand, this leaves us halfway to a decent configuration language–suppose the above syntax changed just a bit:

[macro-outsideline]
  exten(s):
    AbsoluteTimeout(7200)
    SetCDRUserField(Outside (${CHANNEL}))
    Macro(cidfix)
    Macro(dbcallforward)
    Macro(setalertinfo)
   blacklist: LookupBlacklist
   dial: Dial(${PHONES},13,Ttmr)
   ivr: Answer
    Goto(outside-ivr,s,1)
   dial-error: Goto(ivr)
   blacklist-error: Wait(3600)
    Hangup

Personally, I’d find this to be good enough. There’s still a bit of magic with labels and error handling, and there’s probably a better approach out there, but this isn’t too ugly, and it’s only a small step from where we are today.

Posted by Scott Laird Sat, 09 Oct 2004 23:11:31 GMT


Asterisk 1.0

Asterisk 1.0 appears to have been released. I haven’t seen an official announcement on the mailing list, but apparently it was announced in person at this week’s Astricon convention.

If you want to download it, it’d be best to use a mirror.

Most likely, only minor changes have been made since the latest release, 1.0-rc2.

Posted by Scott Laird Thu, 23 Sep 2004 14:35:21 GMT


Linksys PAP2 SIP adapter with Asterisk

As I mentioned before, Linksys is now selling cheap SIP analog telephone adaptors using a design licensed from Sipura. There was a long-standing question about the Linksys PAP2: does it only work with Vonage, or will it work with any SIP provider?

Initial reports were spotty–some people claimed to have their PAP2 working with Asterisk, while others found their PAP2 automatically connecting to Vonage. According to a few posts on the asterisk-users mailing list, the answer is tied to the model number: if you get the PAP2, you might be stuck with Vonage. If you buy the PAP2-NA, then you’ll end up with a provider-agnostic device. They’re both around $50, although the -NA is currently harder to find.

Posted by Scott Laird Mon, 20 Sep 2004 17:39:27 GMT


Modem testing with Asterisk

I had a little problem at work last week: I needed to test a dial-in modem, but I didn’t have a pair of phone lines to use for testing. Our rented office space comes with a PBX, but they’d probably charge us a couple hundred bucks to wire up a pair of analog ports for us, and then take a week or two to do it. Alternately, there’s a bunch of stuff on the market that you can buy for this sort of testing, but considering what it costs, it’s kind of pointless for us.

Instead of doing that, I was able to rig up a testing system using Asterisk and a bit of equipment that we had sitting in the lab: a Cisco 3640 with a 2-port FXS VIC. Going into this, I wasn’t sure how long it’d take–I’d never set up voice services on any Cisco devices before, so I wasn’t sure how big of a pain it’d be. I figured it’d take me most of a day to get it set up and working. As it turned out, the first phase of the project, setting up Asterisk and the Cisco, only took a hour. Installing Asterisk 1.0-RC2 only took a few minutes, and configuring the Cisco to talk to Asterisk was fairly painless. I didn’t have a test phone (or even a modem) handy yet, but I was able to use X-Lite to call Asterisk and watch the phones ring on the Cisco.

The second phase was supposed to be easier: wiring up a serial modem to a test device, and then plugging my laptop and the serial modem into the 3640. And that’s where everything fell down. While I could dial into the Cisco FXS ports without problems, I couldn’t dial out from them. In fact, I couldn’t even get the ports to go off-hook–the Cisco never even noticed that I’d picked up the phone. After reading half of cisco.com, I concluded that the IOS version that we were using must just have been broken and upgraded to a newer release. And that was all it took–everything worked perfectly as soon as the 3640 finished rebooting.

For reference, here are the Cisco config snippets that I needed on the 3640. The two FXS ports are 1/0/0 and 1/0/1. I’m calling them extension 3001 and 3002. Here’s the config:

voice-port 1/0/0
 signal groundStart
 station-id name PORT 1
 station-id number 3001
!     
voice-port 1/0/1
 signal groundStart
 station-id name PORT 2
 station-id number 3002
!     
dial-peer voice 1 voip
 destination-pattern ....
 session protocol sipv2
 session target sip-server
 codec g711ulaw bytes 80
!     
dial-peer voice 2 pots
 destination-pattern 3001
 port 1/0/0
!     
dial-peer voice 3 pots
 destination-pattern 3002
 port 1/0/1
!     
sip-ua
 retry invite 3
 retry cancel 2
 sip-server ipv4:10.0.0.1:5060
!     

Here’s the Cisco part of Asterisk’s sip.conf:

[3001]
type=friend
username=3001
host=10.0.0.2
context=intern
canreinvite=yes
dtmfmode=inband
qualify=1000

[3002]
type=friend
username=3002
host=10.0.0.2
context=intern
canreinvite=yes
dtmfmode=inband
qualify=1000

And finally Asterisk’s extensions.conf:

[intern]
exten => 3001,1,Dial(Sip/3001)
exten => 3002,1,Dial(Sip/3002)
exten => 3003,1,Dial(Sip/3003)
exten => 3004,1,VoiceMail(3004)
exten => 3005,1,VoiceMailMain(s3004)

Posted by Scott Laird Tue, 14 Sep 2004 01:46:48 GMT


NuFone support

I’ve been using NuFone for VoIP connectivity since I first turned up Asterisk at home. I’ve been very happy with their service–in almost 5 months, I’ve never noticed an outage–but their support system has been driving me crazy. It’s been taking me 3 or 4 requests before I get a single response from them. Once I get in touch with them, they’re fast and efficient, but getting them to talk to me in the first place is been like pulling teeth. Reading the asterisk-users mailing list shows that some people have my problem, while others enjoy good support.

I think I figured it out. When I send them mail from my home email account, I don’t even get a reply from their automated tracking system. When I send them mail from my work address, I get a reply back almost immediately. Problem solved: their email system doesn’t want to talk to mine, but it’s okay with work’s. Most likely, they found a spam blocking list that puts me in the middle of ISP space, even though I’m really in a business DSL block.

Hopefully we can get this fixed soon.

Update (9/1/2004): It’s been a week, and I still haven’t heard back from them. However, I seem to have acquired a new 800 number–a call to some number I’d never seen before showed up in my Asterisk logs last week. So, my theory has changed a bit: my mail is reaching them, but theirs isn’t reaching me.

Either that or they’re completely uninterested in talking to me.

So, last night I sent a message directly to a couple staff members there pointing out the weirdness. I asked them to call me back on one of my 800 numbers. Tomorrow, if I don’t hear back, I’ll try IRC, followed by a call to their support number.

And if that fails, I’ll start looking for a new vendor. I may be a piddly little customer, but Google likes me. I’m the fourth site returned when searching for ‘NuFone’.

Update (9/16/2004): They seem to have fixed whatever was broken. I sent them two more requests this morning and they were both answered within minutes. This is a great improvement. At this point, I don’t mind recommending their service to others.

Posted by Scott Laird Tue, 24 Aug 2004 20:51:21 GMT


I want to turn off my POTS line

I want to dump my analog phone line at home. I’m just not sure if I can.

This has been building for a while. I’ve been using Asterisk for over 4 months. At this point, my home POTS line is both the most expensive and least reliable part of the whole system. It’s currently costing me over $33/month, and that’s just for incoming calls and outgoing local calls. I’ve been sending long distance calls to NuFone for over 4 months, and they’ve only charged me $10 for the privilege. That’s less then my average monthly long-distance bill used to be.

According to Asterisk’s logs, I average around 400 minutes of incoming and outgoing local phone service per month. At $0.02/minute, that’s only $8/month. I’m paying that much just for Caller ID on my POTS line. If I could drop the POTS line, then I could save around $25/month. That’d be a nice addition to my DSL speed, or it’d cover cellular data usage with a Treo on most networks.

Besides simple cost, I’m just generally unhappy with telcos. Today’s big point came from Telepocalypse. Plan on phone line charges going up another $4/month in the near future. That, coupled with my Verizon DSL upgrade saga, really makes me want to dump Verizon altogether. See TeleTruth’s “dirty phone bill” for another quick take on what’s hiding in a typical phone bill.

Unfortunately, I just don’t see how I can do it for a reasonable cost. I’m in Comcast cable-modem territory, but they want $50/month for service for non-subscribers, and they don’t offer static addresses with residential service. They might offer them with business services, but those start at $95 and go up. I’d be amazed if I could get a static address (and the ability to run servers) out of them for under $150/month. I don’t seem to have any alternatives for home broadband; it’s either Verizon DSL or Comcast cable modem. Or a T1, but that’s way more then I’m willing to spend.

There does seem to be one way out–I could move the mail and web server out of the house and into a colo server. Several providers advertise dedicated P4 boxes with reasonable amounts of RAM, disk, and network connectivity for around $50/month. I could conceivably drop the DSL and POTS line and move to a $50 server and $50 cable modem, and come out slightly ahead, but I don’t see it being worth the trouble, even if I’d have 4x the bandwidth.

Finally, even ignoring all of the connectivity problems, I’m still left with one problem–how do I dial 911 without a POTS line? 90% of the time, we have a cell phone handy, but they’re never really handy in emergencies. I haven’t seen anyone discuss how to dial 911 is a pure roll-your-own VoIP system. Do you just redirect it to some local phone number? Or do you just leave the POTS line plugged in and trust that they’ll leave it live for 911?

Posted by Scott Laird Wed, 18 Aug 2004 05:01:44 GMT


Database-driven call forwarding with Asterisk

Well, I know that I just said that I was done adding things to Asterisk, but it appears that I lied. I just added database-driven call forwarding to Asterisk, and took under 5 minutes.

The problem that I’m trying to solve here is simple: sometimes specific people call my home phone number when I’d really rather talk to them elsewhere. I have one specific example in mind–I’ve been beta-testing some software, and one of their sales guys calls me from time to time to ask how things are going. I don’t mind talking to him, but he keeps calling my home phone, when he’d be a lot better off calling my office number. I could just send him mail and give him the new contact information, but where’s the fun in that?

Instead, I added another macro:

; Do call forwarding out of a database.  Look up the caller ID number,
; and if it exists in the forward DB, then forward the call to the 
; specified number.
[macro-dbcallforward]
  exten => s,1,DBGet(FORWARDTO=forward/${CALLERIDNUM})
  exten => s,2,Macro(condsetcid)
  exten => s,3,Dial(Local/${FORWARDTO}@inside)

This macro looks in Asterisk’s internal DB for an entry called forward/$PHONENUMBER. If it exists, then the call is forwarded to wherever the DB entry points. I’m using the Local dialing channel, which basically just loops the call back around into the inside context, so it behaves just like I’d dialed it from an internal phone. This let me do things like forward calls to specific extensions, voicemail, conference rooms, or* external phone numbers. Finally, if the call fails, *or if there’s no matching DB entry, then we return to whoever called us.

So, the net result is that one quick DB entry is enough to send calls from some specific caller to wherever I want. Here’s how you set up the DB entries from Asterisk’s CLI:

CLI> database put forward 9199999999 12062629999

To delete them, just do this:

CLI> database delete forward 9199999999

Posted by Scott Laird Mon, 09 Aug 2004 19:33:40 GMT


VoIP: Where to go from here?

To recap, my Asterisk-based home phone system is working nicely. It lets me make cheap long-distance phone calls using VoIP. It sends me copies of incoming voicemail via email. It lets me selectively forward (or even ignore) incoming calls based on Caller ID. Basically, it’s a completely programmable home phone system. It’s completely under my control.

And it’s sort of boring. After all of this, it’s still just a telephone. I have a fantastic amount of computer and network power devoted to emulating a 100-year-old communication tool. It’s an “inside the box” system.

I’d like to change that, but I think I’ve lived inside the telephone box for too long, and I’m having a really hard time seeing out. What should the future’s phone system look like, and what do we need to do to build it? And, while we’re building it, how to we get it to interact with the existing phone network?

All sorts of fun question pop up here:

  • Should phone (and phone numbers) be person-based or location-based?
  • Do we want to stick with phone numbers, or would name-based addressing work better. Do you want to call me at +1-425-488-9014 or sip:scott@sigkill.org?
  • How does presence play into this?
  • How long should call setup take? Is there an advantage to < 1 second call setup, like the cellular push-to-talk people keep pushing?
  • How should we differentiate between “buddy list” calls and calls from complete strangers? When we don’t know the caller, are we better off punting them to voicemail by default?
  • For semi-stable social groups, would we be better off with semi-stable “chat room”-style conference calls rather then two-party phone calls? For instance, I could set up a conference for my extended family. Everyone with the right equipment could keep a “line” open for the call whenever it’s convenient. Then, anyone in the group with something to say simply has to activate their microphone and talk to the group, and everyone can listen in and respond. This is basically just the audio equivalent of IRC; it’s not technically difficult to implement, but it has huge social implications.

I’d like to play with some of this in Asterisk, but I’m lacking a few pieces. None of the fancier things that you can do with smart phone systems really works when all you have to work with are shared home phones, like the Cisco 7940 in our kitchen. I’d really like to find a decent softphone for OS X, but as Boris Mann points out, they’re mostly stuck in the voice-as-application model, when they should be voice-as-utility. I’d love to see a OS X softphone that works just like iChat–its normal mode of operation is just a little toolbar icon. You click on it, and it gives you a couple menu options and then a list of all of your common contacts. Select one, and it dials the number and gives your a little call-management window. Incoming calls are handled via pop-up, just like iChat.

An alternative would be a PDA phone with a decent SIP client. I’ve heard rumors that Vonage will have a SIP client for the next Treo. Frankly, if the “Treo Ace” (or whatever it ends up being called) can run a decent SIP client, and it includes something besides bluetooth for wireless connectivity, then it’ll be almost impossible for me to resist buying one.

Posted by Scott Laird Mon, 09 Aug 2004 18:36:29 GMT


Continued Asterisk progress

Pulling Ethernet cable to replace a bad WiFi link seems to have fixed the audio dropouts that were plaguing our home phone system, but it didn’t do much to help the two other problems on my to-do list. Like many people using Asterisk with POTS lines, the first dozen seconds of some phone calls suffered from a strong far-end echo. Every time we talked, we heard our voices echoing back at full volume around a half-second later. It made it really hard to carry on a conversation. Fortunately, Asterisk’s echo canceling code killed it off eventually, but we had to suffer with it at the beginning of a lot of calls.

I’d heard reports that changes to the echo cancelling code in the latest Asterisk release, 1.0-rc1, had almost completely eliminated echos for a lot of people. So, I rebuilt Asterisk from source again, installed it, added echotraining=800 to zapata.conf, and restarted Asterisk. And, sure enough, the echo seems to be gone. I made a handful of test phone calls without issues, and a 15-minute call to my parents was perfect. No drop-outs, no echo, and the only noise came from their lousy cordless phone.

So, that left only one thing on my to-do list. The Cisco 7940 phones make it easy to use call forwarding–it’s one of the default softkeys on the main screen. Just press the matching button, enter a phone number, and bam, all of your calls are forwarded. Canceling forwarding is even easier. Unfortunately, the way I had Asterisk configured, all forwarded calls would use our caller-ID information. So, when forwarding our home phone to one of our cell phones, every call would look like it was coming from home, not from whoever was actually calling. Fortunately, since NuFone lets your set your own caller-ID information, it’s possible to leave the existing caller-ID info in place for forwarded calls. I just used this macro:

[macro-condsetcid]
  exten => s,1,SubString(cs1=${CALLERIDNUM},0,4)
  exten => s,2,GotoIf($[${cs1} = ${CALLERIDNUM}]?3:4)
  exten => s,3,SetCallerID(4254889999)
  exten => s,4,NoOp

In essence, it checks the current caller ID number. If the number is 4 digits or less, then it assumes that it’s an internal extension number, so it overrides it with our real phone number. Otherwise, it lets it stay as-is.

Then, I went through my extension.conf and replaced every occurance of SetCallerID(4254889999) with Macro(condsetcid). Now call forwarding works perfectly–the caller’s ID is used instead of our home phone number.

At this point, my Asterisk to-do list is essentially empty. There are a few little projects that I can pick up and play with, but there’s nothing left that needs fixed. It’s reached the point where it Just Works.

Posted by Scott Laird Mon, 09 Aug 2004 11:57:40 GMT