Sunday, January 11, 2009

SMS gateway with kannel and your mobile phone (Ubuntu intrepid)

Kannel is a gateway for connecting WAP (Wireless Application Protocol) phones to the Internet. It also works as an SMS gateway, for providing SMS based services for GSM phones. Bellow is my configuration of kannel as a SMS-gateway

1) apt-get install kannel
2)copy /usr/share/doc/kannel/examples/modems.conf to /etc/kannel/ to include in kannel.conf
3)Backup /etc/kannel/kannel.conf ( mv /etc/kannel/kannel.conf /etc/kannel/kannel.conf.bak) and create a new file /etc/kannel/kannel.conf with following configuration:

group = core
admin-port = 13000
smsbox-port = 13001
admin-password = bar
log-file = "/var/log/kannel/kannel.log"
log-level = 0
box-deny-ip = "*.*.*.*"
box-allow-ip = "127.0.0.1"


group = smsc
smsc = at
modemtype = auto
device=/dev/ttyUSB1
my-number =
connect-allow-ip = 127.0.0.1
log-level = 0


group = smsbox
bearerbox-host = 127.0.0.1
sendsms-port = 13013
global-sender =
log-level = 0


group = sendsms-user
username = kan
password = abc
concatenation= true
max-messages = 10


group = sms-service
keyword =
keyword-regex = .*
catch-all = yes
max-messages = 0
get-url = http://localhost/sms/inc/getsms.php?user=john&passwd=1234&mobile=%p&text=%a

include = "/etc/kannel/modems.conf"


4) in above configuration put your phone number in the place of and change the password and username under group = sendsms-user
5) Change device=/dev/ttyUSB1 to your device (eg: /dev/ttyS0, /dev/ttyACM0 ). I'm using huawei E220 in my case and using /dev/ttyUSB1 for sms-gateway and to access Internet I use /dev/ttyUSB0.
6) Now configuration is almost done... now you can test your configuration with starting the gateway with following commands. It will return the errors to the terminal.
bearerbox -v 0 smskannel.conf &
smsbox -v 0 smskannel.conf &

7) I you have problem with opening your device (eg: /dev/ttyUSB1) try changing the permissions for that device with chmod a+rw /dev/ttyUSB1
8) By default kannel will start at the boot time, so it is better you have plugged your device while booting otherwise kannel will try to probe the device continuously until you plug the device or stop kannel (to stop use '/etc/init.d/kannel stop' ).
9) kannel is configured to start as WAPBOX by default... to make it start as a SMSBOX (sms-gateway), edit /etc/default/kannel and put 'START_SMSBOX=1' instead of 'START_WAPBOX=1'
10) To send sms using terminal use following command:
lynx -dump "http://127.0.0.1:13013/cgi-bin/sendsms?username=kan&password=abc&to=[recipient no]&text=[text]"
* It is easy to write an application with php like serverside language and provide a web-gui for kannel. You can find a simple web front end for kannel here.

following link will provide brief descriptions for kannel.conf settings;
http://swik.net/User:marc/Chipmunk+Ninja+Technical+Articles/Setting+up,+Configuring,+and+Using+Kannel+to+send%2Freceive+SMS+messages/3e0s

Usefull links:
http://www.kannel.org/

http://kannel.jizz.gr/

User's guid






19 comments:

  1. hello Laxaman,
    I tried your steps to setup kannel,but I am unable to open the link using lynx
    is there a way i can check is the smsbox or bearerbox is running?
    rupin

    ReplyDelete
  2. hell sir,
    I tried setting up kannel with what you said in the steps but I cannot send sms with more than one word ( example: Hello there how are you?) using curl_init(). But if the sms has only one word(example: Hello) it works fine.
    djbahati@yahoo.co.uk

    ReplyDelete
  3. Following is working properly,

    curl_init("http://$gw_host:$gw_port/cgi-bin/sendsms?username=$gw_user&password=$gw_pass&to=$to&text=$message");

    check for any mistakes in yours

    ReplyDelete
  4. Thanx for your information, but i tried to use:

    curl_init("http://$gw_host:$gw_port/cgi-bin/sendsms?username=$gw_user&password=$gw_pass&to=$to&text=$message");

    It also failed,it displays nothing on the browser and no any error in bearerbox.log file.
    What exactly is the problem.
    Please try to use the code sample at http://kannel.jizz.gr/ and let me know what wrong with my configuration. here is the kannel.conf:


    #
    # Sample configuration file for Kannel bearerbox on Debian.
    # See the documentation for explanations of fields.
    #

    # HTTP administration is disabled by default. Make sure you set the
    # password if you enable it.
    group = core
    admin-port = 13000
    admin-password = manyasi
    status-password = manyasi
    admin-deny-ip = "*.*.*.*"
    admin-allow-ip = "127.0.0.1"
    wapbox-port = 13002
    smsbox-port = 13001
    wdp-interface-name = "*"
    #log-file = "/var/log/kannel/bearerbox.log"
    box-deny-ip = "*.*.*.*"
    box-allow-ip = "127.0.0.1"

    group = wapbox
    bearerbox-host = localhost
    log-file = "/var/log/kannel/wapbox.log"

    group = smsc
    smsc = at
    modemtype = auto
    device=/dev/ttyACM0
    my-number = "+255713482671"
    connect-allow-ip = "127.0.0.1"
    log-level = 0

    group = smsbox
    bearerbox-host = localhost
    sendsms-port = 13013
    sendsms-chars = "0123456789+"
    global-sender = "+255713482671"
    log-file = "/var/log/kannel/smsbox.log"
    log-level = 0
    access-log = "/var/log/kannel/access.log"

    group = sendsms-user
    username = manyasi
    password = manyasi
    concatenation= true
    max-messages = 10

    group = sms-service
    keyword = default
    keyword-regex = .*
    catch-all = yes
    max-messages = 10
    get-url = "http://localhost/dosing/sms.php?n=%p&m=%a"

    include = "/etc/kannel/modems.conf"


    and here is my modems.conf:

    group = modems
    id = "sonyericsson_K750"
    name = "Sony Ericsson_K750"
    detect-string = "Sony Ericsson K750"
    detect-string2 = "K750"
    init-string = "AT+CNMI=2,3,0,0,0"
    reset-string = "ATZ"
    broken = true

    May be is due to my configurations. Please check my configuration and use the sample application from http://kannel.jizz.gr/ and let me know how it works by sending sms with one word example "Hello" and with more than one word example "Hello there how are you?"

    ReplyDelete
  5. Hi,
    Im Tharindu. Can you pls tell me how did u install Huawei e220 on Linux. Did you use USB port? Do we need a specific driver? Also what sim did you used?
    Also I want to know whether is it possible to use Sony Ericsson phones for this? And do we need linux drivers for those phones??

    ReplyDelete
  6. Tharindy,

    You do not have to install any software related to e220. If your system identified the modem it will create tow ports /dev/ttyUSB0 and /dev/ttyUSB1. Both will be work with kannel. It will not depend on the sim card but if you have bought the modem from dialog it may be locked for the sim and cannot use other sims. for the phones sometimes the device will be /dev/ttyACM0 . check whether the devices mentioned above is available and set it in kannel.conf and start kannel it should work.

    ReplyDelete
  7. Thnaks for helping me..
    Now I'm little bit confused how to configure the modem in Modems.conf file..
    Can you pls help me with this..

    group = modems
    id = huawei
    name = "Huawei E220"
    detect-string = "huawei"
    init-string =

    I dont know what should be the init-string..
    Can you pls help me with this configuration...

    ReplyDelete
  8. If you are using Huawei E220 modem and Ubuntu or Debian as OS, the configuration steps given above should work without any change. Just copy the configuration file given above to your /etc/kannel.conf. Then copy /usr/share/doc/kannel/examples/modems.conf to /etc/kannel/ and restart kennal using:

    /etc/init.d/kannel restart

    Then send me the log messages in :
    /var/log/kannel/kannel.log

    ReplyDelete
  9. Thank for helping me.. Your article helped me a lot to overcome many problems. Thanx for sharing it with others..
    I decided to use a sony ericsson k770i. Actually i couldnt find a huawei e220.
    After struggling a lot finally I got it working..
    So Im posting my configuration file hoping it will help someone..

    group = modems
    id = sonyericsson_k770
    name = "Sony Ericsson K770"
    detect-string = "Sony Ericsson"
    detect-string2 = "K770"
    init-string = "AT+CNMI=2,3,2,0,0;+CMGF=0"

    ReplyDelete
  10. Hi laxaman when i try to send a sms i get the message Unable to connect to remote host. what colud be the reason?
    lilantha@lilantha-desktop:~$ lynx -dump "http://127.0.0.1:13013/cgi-bin/sendsms?username=kan&password=abc&to=0776995106&text=te"

    Looking up 127.0.0.1:13013
    Making HTTP connection to 127.0.0.1:13013
    Alert!: Unable to connect to remote host.

    lynx: Can't access startfile http://127.0.0.1:13013/cgi-bin/sendsms?username=kan&password=abc&to=0776995106&text=te

    ReplyDelete
  11. your can use
    bearerbox -v 0 /etc/kannel/kannel.conf &
    smsbox -v 0 /etc/kannel/kannel.conf &

    to check the errors...


    or check /var/log/kennel.log or the kannel log file

    ReplyDelete
  12. Encounter CMS 500 error.

    010-03-04 21:58:25 [6353] [15] DEBUG: boxc_receiver: sms received
    2010-03-04 21:58:25 [6353] [15] DEBUG: send_msg: sending msg to box: <127.0.0.1>
    2010-03-04 21:58:27 [6353] [6] DEBUG: AT2[/dev/ttyUSB1]: TP-Validity-Period: 24.0 hours
    2010-03-04 21:58:27 [6353] [6] DEBUG: AT2[/dev/ttyUSB1]: --> AT+CMGS=16^M
    2010-03-04 21:58:27 [6353] [6] DEBUG: AT2[/dev/ttyUSB1]: <-- >
    2010-03-04 21:58:27 [6353] [6] DEBUG: AT2[/dev/ttyUSB1]: send command status: 1
    2010-03-04 21:58:27 [6353] [6] DEBUG: AT2[/dev/ttyUSB1]: --> 0011000A9156198783820000A70331D90C
    2010-03-04 21:58:27 [6353] [6] DEBUG: AT2[/dev/ttyUSB1]: --> ^Z
    2010-03-04 21:58:27 [6353] [6] DEBUG: AT2[/dev/ttyUSB1]: <-- >
    2010-03-04 21:58:28 [6353] [6] DEBUG: AT2[/dev/ttyUSB1]: <-- +CMS ERROR: 500
    2010-03-04 21:58:28 [6353] [6] ERROR: AT2[/dev/ttyUSB1]: CMS ERROR: +CMS ERROR: 500
    2010-03-04 21:58:28 [6353] [6] ERROR: AT2[/dev/ttyUSB1]: CMS ERROR: Unknown error. -> maybe Sim storage is full? I'll have a look at it. (500)
    2010-03-04 21:58:28 [6353] [6] DEBUG: AT2[/dev/ttyUSB1]: send command status: 1
    2010-03-04 21:58:28 [6353] [7] DEBUG: sms_router: handling message (0x82b6ae8 vs 0

    ReplyDelete
  13. How to configure kannel wapbox for an android emulator???

    ReplyDelete
  14. Hi,
    Thanks for the helpful blogpost. I am in process of setting my Motorokr E6 with kannel, no luck yet, I am stuck with initialization of device, although hoping to get it soon.

    I want to enquire how much time it takes in your setup to send an smsc ? I want to send in bulk and very fast. Will gsm modem with kannel work ?

    ReplyDelete

Intel Corporation XMM7360 LTE Advanced Modem in ArchLinux

The required packages are available in ArchLinux User Repository (AUR) so it will be easier if you can use an AUR helper package like yay . ...