Logo Background

Building your own SMS Gateway

  • Written by WannaBeGeekWannaBeGeek No Comments Comments
    Last Updated: August 9, 2010

    Every once in a while I am asked about the easiest way to create an SMS Gateway. The solutions, of course, largely vary depending on the intended purpose. Most PRSP’s, atleast in Kenya, charge an arm and a leg to facilitate such with short code charges and all that bull that’s not at all necessary if you’re just testing out an idea.
    The simple one I’m going to illustrate here is one that can run offline/online and uses simple-to-configure/free tools available online. As usual I’ll take a *nix system as example since most config’s on windows are mostly automated. So if you’re on M$ you can go figure but in general they work the same.

    What you need for a basic implementation is a *nix machine, a gsm modem/phone (prefeably Huawei modem) and the following FOSS Tools.

    1. X/W/LAMP Environment. For Windowers the XAMPP Framework takes care of all of this. For *nix users apt-get should sort each one out. Remember not all of these are really necessary, however, further development of your SMS Application may require all.

    2. Gnokii – Gnokii is a free and open source Application Programming Interface that provides tools and a user space driver for use with GSM mobile phones and/or GSM modems under various operating systems.
    Gnokii provides source code written in C and employs the use of AT Commands. Once installed and configured, Gnokii is used to set up polling between the computer and the GSM modem. The computer is said to ‘listen’ for requests from the modem and send requests via the AT Command Set.

    Gnokii can be used to send, receive and store SMS messages automagically using a MySQL database with little to no coding experience required.
    To install the full suite of libraries required go to terminal and type in the command

    apt-get install gnokii gnokii-smsd gnokii-smsd-mysql

    Create a file called .gnokiirc in your home directory with the following:

    [global]
    model = AT
    # connection = bluetooth
    # port = xx:xx:xx:xx:xx:xx
    connection = serial
    port = /dev/ttyUSB0

    To check whether the modem has been recognized you can run “gnokii –identify” in terminal and it should output the modem specification.

    Note: These are the settings I used to connect using my cracked Safaricom Huawei E220. These should mostly work with all huawei modems. I will get to the my preference for a cracked one later in the post ;)

    3. Before starting smsd for the first time, we should create the database needed for smsd. The beauty of this solution is that it creates for you a whole database with the correct tables and commands for initiating SMS Tasks e.g. polling. Using phpmyadmin (or whichever dBase Manager you prefer), go to privileges, add a new user, and on the same page, choose the option to create a database with the same name as the user. Next, use the import tab to import the file “/usr/share/doc/gnokii-smsd-mysql/sms.tables.mysql.sql”.

    Also before starting smsd, please note that all SMS messages in the inbox of your phone are automatically transferred to the database and deleted from your phone, so you should take precautions if you want to keep messages on your phone.

    Start smsd like this:

    smsd –module mysql -u user -p password -d databasename

    smsd is basically a daemon to begin polling of SMS’s and there are quite afew extensions to the above command for more functionality. If youd prefer to run single commands for each actions, a few gnokii commands to get you started are listed below. For a complete listing simply type in gnokii at the command prompt with no options.

    gnokii –getnetworkinfo
    gnokii –identify
    gnokii –getdisplaystatus
    gnokii –sendsms destination [--smsc message_center_number |
    --smscno message_center_index] [-r] [-C n] [-v n][--long n] [-i]
    gnokii –netmonitor {reset|off|field|devel|next|nr}

    Once you’re up and running can check out Gnokii’s Documentation pages for more commands and there’s also a GUI X-Gnokii may be simpler.

    There are quite a few interesting implementations I have tried and they’d be great to implement for practise;
    -M-Pesa Transaction Logging and Shopping Cart i.e. using Gnokii and phpWebcommerce
    -Posting to Twitter from Command Line NB: You’ll have to set up smsd and then automat posting the SMS to twitter using a tool such as Crontab or MySQL Triggers.
    -[SMS] - [PHP] – [GMAIL] – Send email using PHP with Gmail from SMS. NB: Same as above

    PSSSST: I almost forgot. The reason I prefered a cracked modem was so that you can use the Mobile Network you prefer. I used a YU Simcard on a Safaricom Modem since YU are not serious about data although they have great SMS Bundles. There should still be the 75/- for 750 SMS’s offer. This is ofcourse assuming you are sending an SMS from your YU phone to your YU modem connected to your webserver. Terms and Conditions apply(in Kenya).

    Bookmark and Share

Advertisement

Leave a Comment