Archive

Archive for the ‘The SMS Gateway Project’ Category

Those wiley Norweigans

March 26th, 2009

In my daily perusal of engadget yesterday, I came across this article.

Reading things like this simultaneously encourages me, and makes me uneasy.  It encourages because it proves that my little crackpot idea has merit and that there are practical implementations of SMS controlled whatevers that I haven’t even considered yet.   It makes me uneasy, because I feel like somebody else is going to beat me to the punch and cash in on this groovy idea.

Not that I had any plans to actually try to build some kind of business or anything…. just saying.

admin The SMS Gateway Project

Building an SMS gateway part 2… The API strikes back.

March 15th, 2009

It’s been a few weeks since I first did my SMS gateway experiment.  Like so many other things in my life, I reached my first plateau of success, then had to shelve the project to focus on other things.  Well, I finally got around to researching what would be necessary to build a PHP based API that would let me actually send messages from a hypothetical web application.

Obviously, the first priority was to actually have the LAMP stack running on the Ubuntu box.  I actually configured everything to do this before I ever got the notion to try the gateway.  I initially built the server to act as a both a local development / testing machine, and also act as my own subversion repository.

Anyway, with Apache, PHP, and MySQL running already, it was simply a matter of figuring out how to get PHP to call the gammu function and send the message.  As with building the gateway itself, the documentation on how to do this was somewhat lacking, so I had to dig through several examples, and read pretty much every article that came up on google when searching for the answer, before I finally pieced it all together.

What it basically boiled down to was the PHP system() command.  So basically:

system(’gammu –sendsms EMS +12223334444 -text “This is the message content”‘);

The trick that wasn’t clearly defined was that the apache level linux user that’s specified in the httpd.conf must have permission to execute anything in the /dev system folder.

Once I figured that out, the rest was just straightforward PHP programming.  I created a MySQL database with two tables.  The first was a “scheduled” table.  This table contained fields for the recipient’s mobile number, the message content, the scheduled timestamp, the sent timestamp, and a status field.  I set up a cron job to run every minute that queries that table to find any messages with a scheduled time that is less than the current time, and a status of “U” for “unsent”.   The results would be looped, and the message would be sent.  The row would then have it’s sent timestamp updated, and status updated to “S” (”sent”).

This method basically allows pre-scheduling of messages, for automated reminders or whatever.  So if I want to tell the thing to send me a reminder at 7:55 PM every Wednesday that “Lost” is about to come on, I can.

The second table was “received”.  Self explanatory… a place to store messages received.  It was the same kind of process.  I appended the cron job to also execute another PHP script  to retrieve messages, parse out the results, and store each message in the database.

Completing the bi-directional capabilities of the API got me thinking though, and I had an idea.  I further appended the retrieval process to not only parse the incoming messages and store the info, but then to also analyze the sender’s mobile number and the message content itself, and then compare it against pre-defined patterns to execute some other process. In other words, I wrote it so that if I text the phrase “change home” from my mobile phone, then a script will run that changes an image on a sample page on the web-server.

This was kind of a big breakthrough, because it represents the basic methodology that other services use when they say “Text ‘laugh’ to 11211 to receive your joke of the day”… that kind of thing.

This also got me thinking that it would be really groovy to wire up a microcontroller to the server that could then be programmed to influence something in the physical world.  For example, I could hypothetically text “turn office lights on” or something from anywhere in the world, and, well, turn my office lights on.  There are already plenty of products on the market for home automation from a web interface, but people aren’t always in front of a computer.

Anyway, I’ll continue my research and keep everyone who’s been reading this nonsense updated on my additional findings.

admin The SMS Gateway Project

Building an SMS gateway. What it is, what it’s for, and how I did it.

February 8th, 2009

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.

admin The SMS Gateway Project