Startup in 7 Days – Day six (SMS gateway)

Start up in 7 days series:

Nothing is particularly hard if you divide it into small jobs – Henry Ford

AutoCarLog was quickly becoming a fully functional system to manage vehicle mileage logbooks online.  Now I needed a way for my customers to update their log books using SMS, and for this I needed an SMS gateway.

What is a gateway?

An SMS gateway is a device that takes an SMS from the mobile phone network and spits it onto the internet.  There are surprisingly quite a few ways to go about this.

The easiest way is to use a third party.  As previously posted, in Australia there are quite a few companies who will manage the gateway and send every incoming SMS to your website.  They can also arrange to charge the mobile user a premium for this privilege (called ‘Premium SMS’).   These services have a start up fee and an ongoing monthly cost, which can be as high as $1,300 a month for six digit premium ‘19’ numbers.

With my $500 budget, I couldn’t afford to go down this path for AutoCarLog so I had to come up with another cheaper way.

Using a mobile phone

The core of a SMS gateway is the GPRS module, an electronic chip which can talk to the mobile phone network and receive SMS of an attached SIM card.  You can find these electronic chips everywhere – as every mobile phone has one.

So I can receive SMS on my mobile, but how do I get them to my website?  Well firstly, you need to get the SMS into a computer.

Most modern mobiles come with the ability to connect to a computer via a serial or USB cable.  The mobile phone companies will then install a suite of software on your computer to manage contacts, read SMS, and update SIM card details.  But what you might not know is, it is possible to send “AT commands” to a connected mobile by hand using a terminal program and read the messages directly.

The good news is, this idea isn’t new.  Here’s a tutorial from the Nokia website on how to connect to their mobiles, and here’s a great source about connecting mobiles to computers.  Look up the AT command set for your mobile, as although it’s common, it isn’t a standard.

SMS Gateway flow diagram

The flow of information from the customer to the server

The program

Sending and receiving messages from your computer by hand is all very well and good, but you’re not going to want to sit at your computer 24/7 and type AT commands every time you check for a new message, no, you need a program to do this for you.

Any programming language that supports serial ports will do.  DotNET, C, C++, Python and the old Visual Basic can all do it.

Your program shouldn’t be too complicated, in essence it will:

  • Check for new messages using AT+CMGL (Nokia),
  • Read a message in using AT+CMGR (Nokia),
  • Parse the message to retrieve the phone number, date and content, then
  • Upload it to a website using a HTTP request.

Fortunately there are heaps of examples online of how to go about this, including completed code. You should be able to get something together with basic programming skills, and it wouldn’t cost much to outsource the development of one.

The hardware way

I didn’t use a mobile for AutoCarLog for two reasons.  Firstly, believe it or not, I didn’t have a spare one lying around!  And secondly, (and the real reason) I can never resist the opportunity to get out the soldering iron and build a piece of hardware.  So instead of using a mobile, I built a stand-alone gateway using an AVR microprocessor and the GPRS module found in SAGEM phones.  You can see my prototype below.

AutoCarLog SMS gateway prototype

AutoCarLog SMS gateway prototype

My device was built by combining modules from previous projects. I already had a system to send twitter updates from a pot plant (“water me please!”) so posting information to AutoCarLog – which is just a different website – should be easy.

Well it wasn’t.  The twitter example used a class built by someone else to talk to the twitter servers and I had to create one from scratch for AutoCarLog.  Also, I spent several hours wondering why my device crashed after 20 seconds, only to find it was because I missed a memory mapping tilde (~) in one line of code.

Eventually I got it to work.  I had a system to check for new messages using the AT commands in one hour, a system to parse the message for phone and content in six hours and a system to send these messages to the AutoCarLog website in seven hours (which would have been four if it wasn’t for the tilde).  I added a small LCD screen to tell me what it was doing and spent another six or so hours refining and testing the modem.  My girlfriend K didn’t see me that day.

Uploading to the server

Uploading to a server is as simple as opening a website.  Open up google in your browser and do a search for something.  See how the URL has now changed from www.google.com to something much bigger? You have just sent google some data (your search in this case) which is contained in the URL.  This is called a GET request.

For AutoCarLog the process would as such:

  • Modem receives SMS message (custom hardware, but could be a standard mobile phone)
  • Modem sends message to a computer (AVR MicroProcessor for me, but this could be a desktop PC)
  • Function resolves phone number and message content
  • Function sends an HTTP request to a website with number and message encoded in URL
  • Website receives URL, decodes the message and sends to database

For example if 0413227564 sends the message “20321 b work planning meeting” to AutoCarLog, the modem would request the following URL:

/upload/?number=0413227564&message=20321%20b%20work%20planning%20meeting containing the two GET value pairs:
number =
0413227564 and
message = 20321 b work planning meeting
(%20 is URL speak for a space).

My page on the server would then decode the message text and in the above example, it would add a business trip with the odometer reading 20,321 and comment “work planning meeting” to the logbook which the number 0413227564 was registered with.

Limitations

It is worth noting that these methods will only work if you’re receiving SMS at a slower rate than you can read them, which is about one per second.  However, if your business is receiving 60 messages a minute you could probably afford to go through a third party or invest in a commercial modem bank!

Final word

Building a modem sounds like a huge task, but when you break it down into smaller steps it becomes manageable.  An SMS gateway is just a modem talking to a computer.  A modem can be a simple mobile phone with a USB cable, or it can be a complex embedded hardware device.  The trick is to tackle the smaller pieces first.

Home made SMS gateway in a box

Home made SMS gateway sitting on my book shelf at home.

Post to Twitter

13 Comments to “Startup in 7 Days – Day six (SMS gateway)”

  1. Devan 24 January 2010 at 10:00 am #

    I’m amazed at how much you have accomplished in such a short space of time Sebastian – you certainly are an inspiration to many.

    I couldn’t help reflecting though, on how much your home made SMS gateway reminds me of ‘Orac’ from the old ‘Blake’s 7′ TV series! :)

  2. seb 24 January 2010 at 10:18 am #

    You’re right – it does! (http://www.terrynation.net/uploads/12.jpg)
    Thanks for the words of encouragement, I do love the response it is having and am looking forward to seeing what others do themselves from this series!

  3. Marfi 24 January 2010 at 10:21 am #

    Keep it up – the inspiration you give to people can be compared only to an Olympic gold medal win run – as good performance on the track brings youngsters to the training rooms – so do your sparking example brings wanna-be enterpreneuers to the fight :)

  4. Walts 24 January 2010 at 12:09 pm #

    Seb, amazing. To see your gateway sitting in a box humbly next to your books makes me want to shake my head! Commercial offerings of similar style services are going to hate you. :o )

  5. ideapod 25 January 2010 at 9:41 am #

    Fantastic work. You probably already know of Hackerspace – they would love your work here.

  6. Manny 25 January 2010 at 11:36 am #

    hey mate,
    two comments:
    1. love the design (graphic) of your site! Truly awesome logo too!
    2. so impressed to see your homemade sms gatway.
    Also found the info you provided VERY useful for my own website, which will need an sms gatway! Thanks for the links you posted!

    Well done!

  7. seb 25 January 2010 at 11:50 am #

    Thanks for all the words of encouragement!

    @Marfi, greatly appreciate it – I love the fact that others are getting inspired by what I’m doing!

    @Walts, That’s motivation in itself!

    @Ideapod, I did not know of Hackerspace, I’ll check them out – thank you for the ref

    @Manny, Thanks! That was the 5th generation of the logo (the first few were pretty bad!) I’m thinking of posting up a ‘timeline’ of each of them to show how it progressed if people are interested? I would love to hear about your website and perhaps blog about it when it’s up! send me an email if interested: seb[at]semi-blog.com

  8. mbmosher 2 April 2010 at 7:22 am #

    Any chance this is open source? I’m just trying to get my Arduino to read and parse SMS on a connected phone and am having a heck of a time with it. Thanks!

  9. seb 3 April 2010 at 8:21 pm #

    I’ve started selling units, so unfortunately not. Feel free to send me a message with your problem and I’ll see what I can do to help!

  10. Bud Green 22 April 2010 at 5:37 am #

    I don’t know whether to be encouraged or discouraged after reading this; probably a mix of both. I applaud the author’s energy and ingenuity, while taking note that his pre-existing skills and experience helped simplify the tasks he set out. This is the burden facing old dogs like me, who can dream up new concepts all day long but lack the basic technological knowledge to execute them. Guess I should have majored in multimedia, except it didn’t exist when I was in college.

  11. seb 23 April 2010 at 11:01 pm #

    Hi Bud! I hope you’re encouraged! There are heaps of opportunities out there for people who have an idea but not the means to execute it themselves – the net has really bought people together to achieve fantastic projects. I’m considering a project myself in the future where I’ll outsource everything – and I’ll blog about it here!

  12. justin bryan 3 July 2010 at 6:30 am #

    But for using sms gateway as commercial purposes, you need shared short code to send sms from web to cell phones. Sending sms through shared short code or own brand short code to customer helps to reach your products to customer. Short code is now used by all popular reality shows, programs, games and election campaigns to send or to populate their message to targeted audiences.

    http://www.txtimpact.com/shared-shortcode.asp
    228 Park Avenue S
    New York

  13. ben 7 August 2010 at 11:06 pm #

    Hello Seb, I just started getting into this sms thing and it is because I want to provide a premium service.
    If you don’t mind, I have a couple of questions on programming and would like you to help.
    Lets email [removed] is my email


Leave a Reply