Building an SMS gateway. What it is, what it’s for, and how I did it.
Recently, I posted a status on facebook stating that I was researching building my own SMS gateway. This prompted many of my friends to ask me what the hell I was talking about, so here goes:
What it is
An SMS gateway is basically a server that can send text messages. Go here for more details.
What it’s for
When used as part of a web server, the gateway can send text messages to subscribers for whatever reason is necessary. Specifically, I’ll be using it to send dinner reservation confirmations for a freelance site I’m building. I’ll also use it to send re-union status updates to those who register on the member site and elect to receive the messages.
How I did it
The server itself is an old Gateway 2000 computer running Ubuntu Linux with the Gammu package installed ( http://www.gammu.org/ ). I used my Sierra USBConnect GSM modem to actually send the text messages, since it’s on an unlimited data plan with AT&T. I started by following the steps I found here.
Since I wasn’t using the same phone the guy in that article used, and since my particular GSM device isn’t officially supported, I had to do some research and tweaking to get Gammu to recognize it. Fortunately, the latest build of Ubuntu has a driver for the device, so the system itself recognized the modem. I just had to set the config options like so:
port = /dev/ttyUSB2
connection = at
Once I got that figured out, it was just a matter of learning the command line sequence to actually send a message. It basically looks like this:
echo “The message” | gammu –sendsms TEXT [mobile number of recipient]
I also figured out that the recipient number has to be formatted with the country code plus the 10 digit number. Something like +15551112222.
I got that all working, and then got Apache, PHP and MySQL running on the box as well so I could write an API that would let me execute the command from any other web server. I had to punch a hole in the firewall and set up a routing table to point all HTTP traffic to that particular server as well.
Granted, this isn’t intended to be a long term, production solution, since my IP address here at home isn’t static. I just did it as a proof of concept, so I could put together an actual solution in a robust production environment at some point.
Anyway, it wasn’t remotely as difficult as I thought it would be, and it sure beats having to use a third party gateway to send messages. The Gammu package also supports EMS for sending things like ringtones, and MMS for pictures and such.