Cloud Based DID With a POTS Based Asterisk System

A while back I wrote about my experience setting up a business phone system with Asterisk, Polycom, and POTS. This system has been working fine over the last year, I’ve only had to dive in once or twice to fix a couple issues (which I’ll detail in a future post).

However, recently someone using the phone system needed a Direct Inward Dial (DID) to their phone. I couldn’t find any concise walkthrough about how to set this up, so I’ve written down my processing in figuring this out.

I knew Asterisk supported DID, and I found a guide that walked you through setting one up.

If you using POTS for your calls and not a SIP trunk, DID gets tricky really fast. Some information mentioned voltage, analog signaling, and other trickshaving to work with your telephone provider; and PRI, number pulsing, and reversing polarity on analog lines. Both solutions seemed very messy and time consuming to me (working with my telephone company – Verizon – has only been painful). My hunch was that the lines coming into our building weren’t clean and we would have issues with the connections (the contractor who set up the lines mentioned something about the lines being dirty and not being able to fix them). I’m not a VOIP professional – nor do I want to be – line voltage and electrical signaling is the last thing I want to deal with.

Another possibility would of been to dedicate a physical line to the specific phone off the PBX and take that number off the hunt group. I could create an inbound route in Asterisk linking the dedicated line to the extension off the PBX. If I used this method, I would of had to take the line off the hunt group because depending on the number of people calling in the line might be picked up and then anyone using the DID will get a busy signal.

However, this would require buying more hardware and ordering another POTS line, something I didn’t want to do (mainly because of the time involved).

At this point I started to regret going with POTS over SIP trunks for our phone provider. However, POTS offered significant savings for us. Our lines through Verizon are relatively cheap (somewhere around ~$25/line) and came with unlimited minutes. When I looked at cloud phone providers they were charging $0.02 – 0.03 a minute. With our call volume this would of ended up costing us a good chunk more per month. Taking a look at cloud phone providers now it looks like the landscape has changed and cloud and land line providers seem to be much closer to price parity.

I figured it must be possible to forward a call over the PSTN to a SIP. Twilio definitely doesn’t allow connection to SIP endpoints right now (although, they have a service in beta). With Tropo it seemed like it was possible, but I couldn’t test an outbound phone connection without going through a verification process. Additionally, outbound calls ran $0.03/minute which seemed high.

After some googling I found DID Logic which on their front page mentioned call forwarding to a SIP URI – great. The company seems a bit  shady (“bought a theme + plugged in some standard marketing copy” sort of site), but since I could test things out for a couple bucks I went ahead and tried it out – it works great.

I grabbed a number off of DID Logic for ~$1/month + $0.007/minute and forwarded it to my PBX.

However, the Asterisk box was not setup to pick up anonymous SIP calls and my SonicWall firewall was not setup to expose SIP ports to the PBX.

Setting up Asterisk to Support SIP Call Forwarding From DID Logic

Make sure “Allow Anonymous InBound SIP Calls?” is enabled in the General Settings on your FreePBX admin (a SIP call from DID Logic will be anonymous).

Then add an InBound DID number in the extension’s control panel. With this DID assigned you can now call your phone using the SIP URI “220@yourdomain.com”. Most likely your PBX is behind a firewall, you’ll have to configure your firewall + NAT settings to forward SIP traffic to the PBX.

Sonic Wall SIP Traffic Forwarding Setup

You need to have both a firewall rule and a NAT routing policy for SIP traffic to work on a Sonic Wall device. Check out this comment for information about UDP timeout settings and some other general information about SonicWall Config.

Your Firewall rule should look something like:

  • WAN –> LAN
  • Source: Any
  • Destination: Any
  • Service: VOIP
  • Allow

Your Firewall rule should nothandle the routing to a specific IP address even though there is an option for it. The routing is handled via your NAT rule (General > Nat Policies) and should look like:

  • Original Source: Any
  • Translated Source: Original
  • Original Destination: Any
  • Translated Destination: PBX
  • Original Service: VOIP
  • Translated Service: Original

The PBX destination won’t exist by default. To create that destination, go to Firewall > Address Objects and add one referencing your PBX on your LAN.

Also, ensure that “Enable consistent NAT” is enabled under VOIP > Settings. Do not enable any of the transform options.

Billings Pro Touch Server & Client Syncing Issues

Quick tip for anyone having issues with getting their iPhone’s Billings Pro app to sync with a local Billings Pro server:

I recently grabbed a Asus RT-N16 and flashed it with DD-WRT. It was working great until I was fiddling with some of the wireless settings and accidentally reset the router.

After reconfiguring the router, my iPhone with Billings Pro Touch would not sync with the local Billings Pro Server. For some reason it seemed that the network tab on the server admin GUI wasn’t picking up my lastest public IP and/or reporting it to the switchboard service correctly. To fix your reported public IP: log out of the switchboard, click advanced, manually set your public IP, and login to switchboard again.

However, my phone would still not connect to my local server. It seemed like it cached the old public IP and wouldn’t update its connection details. The iPhone UI is sparse and doesn’t include any way to manually update connection details. However if you navigate to Settings –> Server, click on your switchboard account, and navigate to password field the “done” button will appear in the iPhone UI. If you click done it seems to pull the updated switchboard login details and it should sync without a problem.

Not sure if this made a difference, but I manually setup port forwarding for 60525-60527 and 7113-7118.

MacRuby 0.12, RVM, and Gem Installation Problems

I recently jumped back into a MacRuby project that I haven’t touched in a while. I upgraded to the latest MacRuby 0.12, installed the necessary gems via macgem install, and was presented with this error:

Segmentation fault: 11

Since I started this project my ruby setup had drastically changed: RVM, custom irbrc, and lots of other tools that I’ve found essential for productive rails development had been installed. I noticed that macgem list --local returned the list of gems needed for my rails project.

Running env from the command line revealed that GEM_HOME and GEM_PATH were set explicitly in my bash env, a result of having RVM installed and a non-system ruby set as default. These two environment variables were causing macgem to look for and install gems in the rvm gem directory. To fix the issue run these two commands in your shell and then run your necessary macgem install commands:

unset GEM_PATH
unset GEM_HOME

Cocoa User Interface Buttons: Previous and Next

I created these years ago, but forgot to post them until now: back forward icons for a Cocoa / Objective-C application. PSD + TIFF files included. They were designed during the snow leopard (possibly the leopard) era, but they still look decent. Should be a good starting point for anyone looking to design a custom previous and next button set for their Mac application.

Download Cocoa UI Previous and Next Images

Social Norms vs Market Valuation

I’m reading Predictably Irrational a really fascinating book, especially for those who have any interest in economics. One of the chapters that I’ve just finished discusses the ‘two worlds’ of valuation and exchange: one which is ruled by ‘social norms’ and the other by cold rational market analysis.

The interesting psychological element to these two ‘worlds’ is that once you cross the threshold into the world of market analysis, you can’t go back. The author cites an example of a day care center which created a new rule which attached a monetary file to arriving late to pick up your child. Once the fine was implemented, more parents arrived later to pick up their children. The social cost of picking up their child late was not easily quantified and thus, most likely, it was greater than the fine attached. The most interesting part of the experiment is that they removed the fine, but parent’s behavior did not positively improve – late pickups did not return to the previous levels. Since parents knew what the cost was, even if it wasn’t charged anymore, it didn’t have a social cost associated with the action.

I’d be interested to see the average tip percentage in restaurants who include a base gratuity on the bill and those who do not. My guess would be those who include a gratuity lose out. Additionally, I wonder if the world of social costs exists in online commerce. Since we never really encounter any people-in-the-flesh online, it is easier to ignore social norms because there really isn’t any community to which establish them (although there are ‘ruled’ written and unwritten in many online communities, I’m not sure if these could be categorized as social norms or costs). For instance I’ve talked to many friends who use NoiseTrade who uncomfortably admit (in a face-to-face conversation) that they have never ‘tipped’ an artist on NoiseTrade.

Great book so far – excited to read the remainder of it.

Convert MS SQL Database to CSV or MySQL

This is more of a thorny issue that you would at first expect – Microsoft does not provide an easy way out of their database if you are on a different platform.

The open source (or paid!) tools available for interacting with Microsoft SQL databases on OS X are very limited. There are not any native GUIs available (to my knowledge), I’ve found that getting TDS up and running is a pain, and it seems impossible to import a .bak or ms sql insert dump. Additionally, I’ve had weird encoding + CSV formatting issues when given a CSV exported from a dump given to me.

I’ve discovered a workaround to the issue that has worked reliable for very large data sets (30,000+ rows). Oracle’s SQL Developer application can connect to a ms sql database. Once you have a connection established you can export to a bunch of different formats. However, I’ve had encoding issues when exporting as a CSV or other plain text format. However, exporting the ms sql from Oracle SQL developer as a XLS is very reliable (text with quotes, commas, and other characters are perfectly preserved).

Google has released a great tool for handling large CSVs. The great thing about Google Refine is that it can import data from a variety of formats – one being XLS. If you import the XLS file into Google Refine and then export as an CSV you’ll have a data format which works great with libraries such as Ruby’s CSV class or CSV import functionality on software such as Sequel Pro. A multi-step process, but it has worked reliably.

If you are looking to convert a mdb (a Microsoft Access database) to SQL there is a great tool for converting a mdb to sqlite which you can then easily export a MySQL compatible SQL dump or a plain CSV file either using a tool like Base or the command line.