Skip to content

Install Kannel WAP/SMS Gateway on Ubuntu

October 11, 2010

Kannel is a compact and very powerful open source WAP and SMS gateway, used widely across the globe both for serving trillions of short messages (SMS), WAP Push service indications and mobile internet connectivity.
If you intend to play around with SMS’es, build your own SMS application, this tool is perfect for you!!!
Now, for newbies who would wish to use this extraordinary piece of work, you might find yourself stuck trying to install it. The steps are pretty straight forward but not self explanatory in the Kannel user guide (http://kannel.org/download/kannel-userguide-snapshot/userguide.html), which you will definitely need after you have successfully installed it.

This short guide is based on Ubuntu Linux (from 8.04 to 10.04) but should work on other Linux distros (Fedora, CentOS, SUSE, etc)

Pretty much of the work here will be performed via command line, so i would suggest you to fire up your beloved Terminal 🙂

Step 1 : Download Kannel sources (http://kannel.org/download.shtml)
RPM and Debian packages are available but i will recommend to install it from sources.
Download the most stable release 1.4.3
#Go to a specific location (i am using /usr/local/src, but yours could be different, just make sure it exists)
$ cd /usr/local/src
#Download sources
$ wget http://kannel.org/download/1.4.3/gateway-1.4.3.tar.gz
#Extract tarball
$ tar -xzvf gateway-1.4.3.tar.gz
$ cd gateway-1.4.3/

Step 2 : Install required libraries
Kannel requires the following software environment:
– C compiler and libraries for ANSI C, with normal Unix extensions such as BSD sockets and relate tools. (GNU’s GCC tool-chain is recommended)
– The Gnome XML library (known as gnome-xml and libxml), version 2.2.5 or newer.
– GNU Make
– An implementation of POSIX threads
– GNU Bison 1.28
– DocBook processing tools: DocBook style-sheets, jade, jadetex, etc;
– GNU autoconf, if you want to modify the configuration script

You might wonder, “How do i get all this stuff installed??”
Relax, this is how you should proceed :
#C compiler and libraries for ANSI C
$ sudo apt-get install build-essential
#The Gnome XML library
$ sudo apt-get install libxml2 libxml2-dev
#Optional : if you wish to use MySQL with your Kannel installation (details can be found in the user guide)
$ sudo apt-get install libmysqlclient15-dev

Step 3 : Compile Kannel sources
Depending on how you would wish to compile it, refer to the user guide to see other options (Chapter 2 : Installing the Gateway, section : Compiling the gateway)
The default compile is :
$ ./configure
But i recommend :
$ ./configure –prefix=/usr/local/kannel –enable-start-stop-daemon
–prefix defines where your current installation will be located (my current location is /usr/local/kannel but you can use a different one as long as it exists)
–enable-start-stop-daemon compiles a start/stop daemon program to run kannel
If you wish to enable MySQL :
$ ./configure –prefix=/usr/local/kannel –enable-start-stop-daemon –with-mysql

Step 4 : Install compiled sources
$ make
$ sudo make install

That’s it, now real stuff can start!!!

But before that, I would suggest you to read “Chapter 3 : Using the gateway” in the user guide

If you get stuck or need help on how to proceed, email me on mutesach@gmail.com

Happy hacking !!! 🙂

From → Kannel

30 Comments
  1. John permalink

    Thanks for the guide. How can i go ahead and configure kannel to send and receive message from/to mysql database.

    • Hi John,
      The best way to store incoming/outgoing messages into MySQL is to use a back-end application that will perform the task via HTTP (your back-end could be in any language : php,perl,ruby,java,etc…).
      In the sms-service group you need to specify the URI in the get-url attribute. A simple sms-service group would look like this :

      group = sms-service

      keyword = default

      get-url = http://localhost:3000/service_manager/get_incoming_message?smsc=%i&sender=%p&destination=%P&keyword=%k&content=%a

      max-messages = 0

      This means that every incoming sms, regardless of its content, will trigger this particular application by calling a get URL (in the above example : http://localhost:3000/service_manager/get_incoming_message?) and pass the following parameters :
      %i for SMSC (eg FAKE)
      %p for sender
      %a for content, etc… (For more info, check page 78 of the user guide : http://kannel.org/download/kannel-userguide-snapshot/userguide.pdf)

      To send an SMS, use Kannel’s HTTP interface using either a web browser or an HTTP library of your preferred scripting language.
      The format looks like this : http://127.0.0.1:13013/cgi-bin/sendsms?username=foo&password=bar&to=0123456&text=Hello+world
      127.0.0.1 being your host
      “username=foo&password=bar” are set under the sendsms-user group
      “to=0123456” is your destination number and “text=Hello+world” the content of your sms

      Now, if you would like to pull the content of your SMS from MySQL, you’d have to use a back-end application to perform this task in 2 steps :
      1. Get the content from MySQL with a select statement
      2. Push the sms via Kannel’s HTTP Interface (For more info, check page 97 of Kannel user guide)

      Hope this helps, let me know if you need more help.

  2. Adan Canales permalink

    My friend Mutesa, you seem to be the guy of Kannel. I read this article and find it very usefull. The fields in MySql database doesn´t have to do then with Kannel, meaning that Kannel doesn´t give you any specific tables or fields to include, as long as it has the information required in the SMSservice?

    Another question is how to configure the core? What commands to type to edit which file, I´m lost my friend since the Kannel manual doesn´t say it.

    Thanks in advance.

    Adan

    • Adan Canales permalink

      my friend, I have found the way to configure the .conf files, now I wonder if I have to set up both files; wapbox and smsbox.conf files or just one of them and then start the bearerbox with them and after the smsbox and wapbox with the same? Or can I started with the two?

      Regards

      Adan

      • Hi Adan,
        Good to see that you’re making some progress. Well, you can have one single file containing all your settings (bearerbox,smsbox & wapbox) or split them in different files and include them in the main conf file (core) as described on page 15. Depending on what you’ll be using Kannel for (wap,sms or both) you will have to set up the corresponding configuration (wapbox,smsbox or both)

  3. Adan Canales permalink

    Thanks, your guide is so clear, I tested on debian but it doesn´t recognized the mysql support, I don´t know why, because mysql is installed and working.

    I was reading the answer you gave to John, and I wonder if you have a code example on PHP on how to receive variables from a form in html or php and send it to th kannel. I was thinking of creating an html form but it show the user and password, so I though I might create instead a php form and capture the data I want to send to kannel but I don´t know how to do the concatenation of the variables and send it to kannel.

    Thanks in advance.

    Adan

    • To enable MySQL support, install libmysqlclient15-dev (apt-get install libmysqlclient15-dev)

      To send SMS massages, use Kannel HTTP Interface (http://smsbox.host.name:13013/cgi-bin/sendsms?) to send SMS messages (page 97).
      It is a get-url interface that you will have to feed with the parameters received from your form (html or php);
      Am not php expert but i think you can use the http_get function with something similar to this :
      “foo”, “password” => “bar”, “to” => “0123456”, “text” => “Hello”), $info)
      print_r($info);
      ?>
      You will have to replace the default values i mentioned (“foo”,”bar”,”0123456″ and “Hello”) with the ones received from your form.

      Hopefully this should work.

      • Sorry, forgot to tag the code, remember am not a php expert, so it might require some change but might look like this :
        $response = http_get("http://localhost:13013/cgi-bin/sendsms?", array("username" => "foo", "password" => "bar", "to" => "0123456", "text" => "Hello"), $info)
        print_r($info);

  4. Adan Canales permalink

    Thank you so much, I will give it a try and let you kow. I quit on Debian, I will use Ubuntu instead, you make it so easy. Thanks a lot.

  5. Adan Canales permalink

    I have a doubt: pretend I have a few premium SMS and I want to received the SMS in kannel. What are the parameter the SMSC pass to kannel? phone number, short code, keyword(meaning the word for the service like: love, joke, flirt to the 5050) so the user send Joke to the 5050 from the cel number 12345678, do I receive all this information? and do I have to send it back? all of them or just the answer to the cel number with text I want? And how can I control the SMS I have sent…? through the DLR´s?

    Sorry for many questions, I´m new an ignorant in this field.

    Regards

    Adan

    • SMSC sends all parameters, check Table 6-9. Parameters on page 85 for their corresponding values.
      For example %k stands for keyword;
      Now, in your sms-service group, you can specify parameters that you wish to capture with something like this :

      group = sms-service
      keyword = www
      get-url = "http://localhost:8080/cgi-bin/get_message?keyword=%k&content=%a&smsc=%i"

      “localhost” here might be your IP address or whichever domain you’re using, “cgi-bin/get_message” is your php function that will be receiving incoming SMS’es
      It it that function that will capture parameters sent to you Kannel. Now, it is up to your function to get the different parameters sent to you by Kannel.

  6. Adan Canales permalink

    Excellent! I read the section you mention, now I have a better understanding. I can capture what I want to pass to my PHP function and return what I want.

    What is a bit confusing now is how to control o keep a record of all the messages I sent, is this done thru the DLR´s?

    Thanks

    Adan

    • Yes, it is done through DLR’s, read chapter 9 page 118 for a better understanding.
      It was quite confusing for me as well at first, but it’s pretty straight forward.

      What happens is when you call Kannel send sms HTTP Interface, you need to specify dlr-mask which takes a value depending on the delivery report that wish to have :
      • 1: delivery success
      • 2: delivery failure
      • 4: message buffered
      • 8: smsc submit
      • 16: smsc reject
      As described in the chapter, simply add the values together for your preferred dlrs (eg. 1+2+4 => dlr-mask=7),
      then specify dlr-url as well, which will point to your php function that will take care of recording the dlr and the sent SMS if you wish.

      Your function will now look pretty much like this :

      $response = http_get("http://localhost:13013/cgi-bin/sendsms?", array("username" => "foo",
      "password" => "bar", "to" => "0123456", "text" => "Hello",
      "dlr-mask" => "7", "dlr-url" => "http://localhost:80/cgi-bin/record_dlr?type=%d&smsc=%i&destination=%P&message=%a"), $info)
      print_r($info);

      From now on, you could use dlr-url to store sent messages & their dlr.
      You can do this differently by maybe storing first the message before you send it, and update its status when the delivery message come and calls your function.

      Good luck.

  7. Adan Canales permalink

    Mutesa, what id the diference in keep the records of DLR in MySql and usingsqlbox?

    Regards

    Adan

  8. Paula permalink

    i need Mutes’s help with Kannel. how can i start a link?

  9. yulita permalink

    Thank’s mutesa for u’r rich Documents I have followed your procedures and successfully configures kannel,but problem is to send sms. Ican receive msg but Ican’t msg from kannel.

    Can you please put tha advanced configuration on how to send and receive multiple sms

  10. Paul permalink

    i have been trying to install Kannal for the past f… hours
    i keep getting this error
    In function `xmlSchemaDateNormalize’:
    (.text+0x155e): undefined reference to `floor’
    /usr/lib/gcc/i686-linux-gnu/4.6.1/../../../../lib/libxml2.a(xmlschemastypes.o):(.text+0x15a0): more undefined references to `floor’ follow
    collect2: ld returned 1 exit status
    make: *** [wmlscript/wmlsc] Error 1

    am running ubuntu 11.10

    could someone help?

    • Which version of Kannel are you trying to install?
      Add the following dependencies :
      sudo apt-get install build-essential
      sudo apt-get install libxml2 libxml2-dev

  11. dharush permalink

    could someone help?? i am using ubuntu 11.04, i installed the kannel but nw i am bit stuck in configuring files which means settings up gateways… can u pls give me the fundamental procedures to follow and the appropriate commands to send and receive messages, please it would be very helpful if u consider out my problems. thanx dharush…

  12. Paul permalink

    Hey Mutesa
    i’v installed kannel, but i need your help
    what more configurations or applications do i need to install to be able to send texts

  13. thanks for a very useful information., now im sending message via smsc http., how can i store it to database. when i type
    http://122.52.247.156:13013/cgi-bin/sendsms?smsc=http&username=****r&password=****to=+63935*******&text=hello

    output: 0: Accepted for delivery
    but i cant store it in database. please help me. :((

    thanks in advance.

  14. papa bling permalink

    how to configure huawei E160 modem to work as the virtual smccs

    • Try this :

      group = smsc
      smsc = at
      port = 10000
      modemtype = huawei_e160g
      device = /dev/ttyUSB1
      sms-center = “your provider’s sms center”
      my-number = “your number”
      connect-allow-ip = “127.0.0.1”

    • You also need this :

      group = modems
      id = huawei_e160_00
      name = “Huawei E160G”
      detect-string = “huawei”
      init-string = “AT+CNMI=2,1,2,2,0”
      message-storage = sm
      speed = 460800

  15. papa permalink

    i need your help mutesach failed to sent message from the http interface
    i get the following errors:

    3:queued for later delivery
    and the bearer box shows received message but failed to route to box

    this is my conf file

    group = core
    admin-port = 13000
    smsbox-port = 13001
    #wapbox-port = 13002
    admin-password = foo
    status-password = bar
    #admin-deny-ip = “”
    #admin-allow-ip = “”
    #log-file = “/tmp/kannel.log”
    #log-level = 0
    box-allow-ip = “127.0.0.1”

    #——————————–# SMSBOX SETUP#———————————#
    # Smsbox(es) do higher-level SMS handling after they have been received from
    # SMS centers by bearerbox, or before they are given to bearerbox for delivery

    group = smsbox
    smsbox-id = smsbox
    bearerbox-host = localhost
    sendsms-port = 13013
    sendsms-chars = “0123456789 +-”
    #log-file = “/tmp/smsbox.log”
    log-level = 0
    #access-log = “/tmp/access.log”

    #——————————# SEND-SMS USERS#——————————-#
    # These users are used when Kannel smsbox sendsms interface is used to
    # send PUSH sms messages, i.e. calling URL like
    # http://kannel.machine:13013/cgi-bin/sendsms?username=tester&password=foobar

    group = sendsms-user
    username = foo
    password = bar
    user-allow-ip = “*.*.*.*”
    max-messages = 2
    concatenation = true

    #—————————————————————————————————————————————
    # SMSC CONNECTIONS
    #
    # SMSC connections are created in bearerbox and they handle SMSC specific
    # protocol and message relying. You need these to actually receive and send
    # messages to handset, but can use GSM modems as virtual SMSCs

    # This is a fake smsc connection, _only_ used to test the system and services.
    # It really cannot relay messages to actual handsets!

    ###### for the modem########
    group = smsc
    smsc = at
    smsc-id = orange
    modemtype = auto
    device = /dev/sr0
    my-number = 0790123456
    #sms-center = 0790000012
    connect-allow-ip = 127.0.0.1
    #log-level = 0

    group = modems
    id = huawei
    name = “Huawei”
    detect-string = “huawei”
    init-string = “ATZ”
    init-string = “AT+CMEE=1”
    init-string = “AT Q0 V1 E1 S0=0 &C1 &D2 +FCLASS=0”
    init-string = “AT+CNMI=1,2,0,0,0;+CMEE=1”
    #init-string = “AT+CNMI=0,1”
    message-storage = SM

    please save my job!

    thanks

    • 1) Which type of Huawei modem are you using?
      2) Which OS are you running? Check if “device” on your smsc group matches with modem path
      3) Enable your log files to be able to identify errors in your core group (log-file = “/tmp/kannel.log” and log-level = 0)
      4) Restart kannel and check if the modem is being recognized by looking at the core group log file /tmp/kannel.log. Review your modem config if its not or try this

      group = smsc
      smsc = at
      port = 10000
      modemtype = huawei_e156g
      device = /dev/ttyUSB1
      sms-center = ""
      my-number = ""
      connect-allow-ip = "127.0.0.1"

      group = modems
      id = huawei_e220_00
      name = "Huawei E156G"
      detect-string = "huawei"
      init-string = "AT+CNMI=2,1,2,2,0"
      message-storage = sm
      speed = 460800

      Replace huawei_e156g with your Huawei model (when connecting your modem, your can check the model with the following command on linux tail -f /var/log/syslog)

  16. I really Like this Topic. I have been searching on this thread around the world but This Solution is the Best. Thanks Mutesa

  17. Dear @mutesach
    You have some good expertise in kannel. I need your help please.
    I am using kannel sing long time. currently sms are sent via url submission. Now i want to store the send SMS and there STATUS whether they are delivered or not. I configured mysql/sqlbox. If i make entry in send_sms table, then kannel send sms fine and move its entry to sent_sms table. but status field does not update. after search i came to know that it have to do something with the DLR. so from the internet i took example for DLR.PHP but still i dont see any status for the sent sms.

    Can you please provide some example of dlr.php , db / table that will be used to store status/msg and above all how to submit DLR entry via URL/MYSQL

    • Hello Syed,

      I have not been active on this topic for a while now, so accept my apologies for this late response. DLRs could be a headache when you don’t put the proper settings in your kannel config. I am not a PHP developer, so I might not give you the exact sample php file, but what I can advise you is to follow this:

      When you call the Kannel send sms HTTP Interface, you need to specify two specific attributes
      1) dlr-mask: Type of delivery report that wish to have :

      • 1: delivery success
      • 2: delivery failure
      • 4: message buffered
      • 8: smsc submit
      • 16: smsc reject

      As described in the Kannel guide chapter 9 page 118, simply add the values together for your preferred dlrs
      (eg. 1+2+4 => dlr-mask=7)

      2) dlr-url: Your php function (eg. http://syed.com/dlr.php) that kannel will start calling whenever there is a delivery receipt

      And that’s all. The idea is straight forward: When you call Kannel Send SMS interface, tell kannel :
      1) The type of DLR you want (dlr-mask)
      2) The URL it should call when the DLR is ready

      Your Send SMS function will look pretty much like this :

      $response = http_get(“http://localhost:13013/cgi-bin/sendsms?”, array(“username” => “foo”, “password” => “bar”, “to” => “0123456”, “text” => “Hello”, “dlr-mask” => “7”, “dlr-url” => “http://syed.com/dlr.php?type=%d&smsc=%i&destination=%P&message=%a”), $info)
      print_r($info);

      I hope this helps

Leave a comment