Saturday, March 24, 2012

Kannel–A quick installation and configuration guide

Kannel is free and open source SMS and WAP gateway. It is easy to use, install and configure. This article will describe a quick and easy steps for installing and configuring this gateway for sending and receiving SMS.
Installation
Kannel in based on Linux and can be easily installed from repository. It is available in both aptitude and yum repositories and can be installed right away by giving their respective commands.
apt-get install kannel
or
yum install kannel
If you don’t find it in repository, then you can add more repositories. This link gives guide to add repository to CentOS. You can find for other Linux distribution too.
Configuration
After you install, you will find a file named kannel.conf at /etc/. The configuration file for my modem Nokia30 is shown below.

***********************************************************************************
#
# 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 = bar
admin-deny-ip = "*.*.*.*"
admin-allow-ip = "127.0.0.1;192.168.0.*"
smsbox-port = 13003
wapbox-port = 13004
wdp-interface-name = "*"
log-file = "/var/log/kannel/bearerbox.log"
access-log="/var/log/kannel/access.log"
box-deny-ip = "*.*.*.*"
box-allow-ip = "127.0.0.1;192.168.0.*"
group = wapbox
bearerbox-host = localhost
log-file = "/var/log/kannel/wapbox.log"
# My modem
group = smsc
smsc = at
modemtype = nokia
device = /dev/ttyS0
speed = 0
pin = 2345
# My modem group
group = modems
id = nokia
name = nokiaGsmModem
detect-string = NOKIA
# fake smsc
group = smsc
smsc = fake
port = 10000
connect-allow-ip = 127.0.0.1
#Send SMS
group = smsbox
bearerbox-host = localhost
sendsms-port = 13131
sendsms-chars = "0123456789 "
global-sender = 123456
access-log = "kannel.access"
log-file = "smsbox.log"
log-level = 0
#Receive SMS
group = sms-service
#keyword =
keyword-regex = .*
catch-all = yes
get-url = "http://www.blogger.com/'http://192.168.0.92:8080/KannelSmsReceiver/msgRecvd.htm?sender=
accept-x-kannel-headers = true
max-messages = 0
#Authentication
group = sendsms-user
username = myuser
password = mypassword
******************************************************************************
As this is a quick guide, I won’t be explaining all the keywords used in configuration file. You can find detail in Kannel website. I will only describe few of them.
# My modem
group = smsc [Group of my modem]
smsc = at [The command which my modem responds to. Nokia30 responds to AT commands]
modemtype = nokia [My modem type which is Nokia]
device = /dev/ttyS0 [The port in which my modem is connected. It is connect to serial post ttyS0]
speed = 0 [Auto detect speed of my modem]
pin = 2345 [Pin of my modem]
# My modem group
group = modems [My modem group name]
id = nokia [ID of my modem]
name = nokiaGsmModem [Name of my modem]
detect-string = NOKIA [String to be detected]
#Send SMS
group = smsbox [Group of my SMS box for sending]
bearerbox-host = localhost [Bearerbox host]
sendsms-port = 13131 [Port in which my SMS box will be listening to]
sendsms-chars = "0123456789 "
global-sender = 123456
access-log = "kannel.access"
log-file = "smsbox.log"
log-level = 0 [This log level shows maximum detail]
#Receive SMS
group = sms-service [Group of my SMS box for receiving]
#keyword = abc [You can define a keyword in SMS. If the SMS contains that keyword then the SMS will be redirected to the URL below. I have disabled it as I want to receive all SMS]
keyword-regex = .* [Receive all SMS. Don’t care any keyword regex]
catch-all = yes
get-url = "http://www.blogger.com/'http://192.168.0.92:8080/KannelSmsReceiver/msgRecvd.htm?sender= [My URL]
accept-x-kannel-headers = true
max-messages = 0
#Authentication
group = sendsms-user
username = myuser [My SMS box username to send SMS]
password = mypassword [My SMS box password to send SMS]
Starting Kannel
You can start Kannel by just give command ‘/etc/init.d/kannel start’. But if like to debug and see what is happening in your SMS box then, you have to start bearer box and sms box separately. The commands (for CentOS) are below
/usr/sbin/bearerbox “/etc/kannel.conf”
/usr/sbin/smsbox “/etc/kannel.conf”
First you have start bearerbox and then in another window start smsbox. Please note that /dev/ttyS0 should be given permission before you start bearerbox, otherwise it won’t start.
Sending SMS
SMS can be sent by using URL below. If you are sending via your program then you have to use GET method to send it. In your browser, type the link below.
http://your-kannel-server:13131/cgi-bin/sendsms?username=myuser&password=mypassword&to=0123456789&text=KannelTest
Above you can see, we have used port 13131 where the SMS box is listening, username, password, the receipient mobile number and SMS text to be sent.
Receiving SMS
From the above configuration you can see that when Kannel SMS box receives SMS it redirects the SMS to URL http://192.168.0.92:8080/KannelSmsReceiver/msgRecvd.htm?sender=%p&text=%s-%r
In my case, I have made a simple servlet that is listening at port 8080 and my server address is 192.168.0.92. My servlet receives two parameters – sender and text. Here %p gives the sender mobile number. %s-%r says cut the first word in SMS text and receive the rest. If you want to receive all the SMS text then simply replace %s-%r by %a. This link shows all the parameters (escape codes) you use with get-url.

3 comments: