Configure gateway on ubuntu

Before configure gateway first install kannel

Configuration of gateway can be divided into two parts.

Bearerbox : bearerbox is a gateway, interface towards the phones. Its work is to keeping an eye on the gateway while it is running and use http interface to control the gateway.

smsbox : It handles sms gateway functionality. It contain sms-services, sendsms-user group which helps sms center to build.

sqlbox : (optional) sqlbox is used for DLR(delivery report) storage. Use to store logs of incoming and outgoing SMS in database.

Purpose of Using kannel : To send and receive sms for your application.

Requirements : GSM phone or modem (link to compatible.shtml)

Attach your phone or modem to the computer through USB cable.

Enter the following command in your terminal.

$ wvdialconf
 Note : run command with sudo user

If it display : No modem was detected.

Then your phone is not compatible with kannel.

If it display : Found an USB modem.

Then your phone is compatible with kannel.

Your connected device configuration written to /etc/wvdial.conf

Open wvdial.conf file in your favourite editor.

$ vim /etc/wvdial.conf

Value of Init1 ,Init2, Modem Type, Modem use in gateway configuration

Lets write configuration file for kannel.

Edit kannel.conf file on your desktop or anywhere you want in your file system.

core group is used for general bearerbox configuration. dlr-storage value is depend on which DBMS is used.

group = core
 admin-port = 13003
 admin-password =
 admin-allow-ip = "127.0.0.1"
 dlr-storage = mysql //where to store the logs of sms
 smsbox-port = 13016
 log-file = "/var/log/kannel/bearerbox.log"
 access-log = "/var/log/kannel/access.log"
 box-allow-ip = "127.0.0.1"
 log-level = 0

smsc group include all variables which used to set SMS center in kannel. smsc-id value is name of device which is connected. modemtype and device change according to Modem value in wvdial.conf file

group = smsc
 smsc-id = Nokia
 smsc = at
 modemtype = USB Modem
 device= /dev/ttyACM0
 my-number = +919888888887
 connect-allow-ip = 127.0.0.1
 sim-buffering = false
 log-level = 0

mysql-connection group is used when mysql database is used to store data values. database,username,password variables values are database name,database username and password respectively.

group = mysql-connection
 id = mydlr
 host = localhost
 username = boot
 password = abc
 database = key
group = dlr-db
 id = mydlr
 table = dlr
 field-smsc = smsc
 field-timestamp = ts
 field-source=source
 field-destination = destination
 field-service = service
 field-url = url
 field-mask = mask
 field-status = status
 field-boxc-id = boxc

Modem group is used to define Modem configuration. init- string variable value change according to Init value in wvdial.conf file

group = modems
 id = Nokia
 name = Nokia
 detect-string = "Nokia"
 init-string = "ATZ"
 init-string = "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
 message-storage = SM
 message-start = 0

smsbox group must define to use SMS Kannel

group = smsbox
 smsbox-id = mysmsbox
 bearerbox-host = localhost //hostname
 bearerbox-port = 13020
 sendsms-port = 13013
 global-sender = +919888888887 //your modem number
 access-log = "/var/log/kannel/smsbox-access.log"
 log-file = "/var/log/kannel/smsbox.log"
 log-level = 0
 mo-recode = true

smsbox route group is develop an interface between smsbox and bearerbox.

group = smsbox-route
 smsbox-id = mysmsbox
 smsc-id = Nokia

sendsms-user group is used to push SMS through browser. Variables username and password are used for authentication purpose.

group = sendsms-user
 username =
 password =
 concatenation= true
 max-messages = 10000

sms-service group is provide services to incoming SMS. Accepted-smsc variable means which SMS center used to accept as incoming SMS.

group = sms-service
 keyword-regex = .*
 catch-all = true
 accepted-smsc = Nokia
 max-messages = 99
 get-url = "http://localhost/api/sms.php?phone=%p&text=%a"

Edit sqlbox.conf file where your kannel.conf file is placed.

sqlbox group used to tell kannel about sms log table and insert table. The sql-insert-table is used to store SMS which we want to send and sql-log-table is show logs of sms which are send through kannel and log of delivery reports.

group = sqlbox
id = sqlbox-db
global-sender = "+919888888887"
bearerbox-host = localhost
bearerbox-port = 13016
smsbox-port = 13020
smsbox-port-ssl = false
sql-log-table = sent_sms
sql-insert-table = send_sms
log-file = "/var/log/kannel/kannel-sqlbox.log"
log-level = 0

mysql-connection group explained before

group = mysql-connection
id = sqlbox-db
host = localhost
username = boot
password = abc
database = key

Lets send SMS through kannel through http(browser) and application. Excited 😉

Start kannel service: Run these commands on seperate Terminals sequentially with sudo user.

$ bearerbox -v 1 kannel.conf
$ sqlbox -v 1 sqlbox.conf
$ smsbox -v 1 kannel.conf

Set verbosity level
0 is ‘debug’.
1 is ‘info.
2 ‘warning’.
3 ‘error’.
4 ‘panic’.

Send SMS through browser : Open your favorite browser and type below given on address bar.

http://localhost:13003/cgi-bin/sendsms?username=&password=&to=0123456&text=Hello+world

13001 is an admin-port number which is defined in core group.
username and password value which is define in sendsms-user group.
to value contain phone number to whom we want to send SMS.
text value contain content of SMS.

Send SMS through application : To send through application is just do one entry in send_sms table of defined database in config files.

Method : Write sql query which insert sender, receive number and message data in send_sms table. kannel automatically check send_sms table and send SMS.

sql code of tables

sent_sms

send_sms

All the Best!

16 thoughts on “Configure gateway on ubuntu”

  1. ubuntu@ubuntu-desktop:~/Desktop$ sudo bearerbox -v 1 kannel.conf
    2012-12-04 16:05:23 [4858] [0] INFO: Debug_lvl = 1, log_file = , log_lvl = 0
    2012-12-04 16:05:23 [4858] [0] ERROR: Group ‘sms-service’ may not contain field ‘field-url’.
    2012-12-04 16:05:23 [4858] [0] ERROR: Error found on line 82 of file `kannel.conf’.
    2012-12-04 16:05:23 [4858] [0] PANIC: Couldn’t read configuration from `kannel.conf’.
    2012-12-04 16:05:23 [4858] [0] PANIC: bearerbox(gw_panic+0xd2) [0x80cb032]
    2012-12-04 16:05:23 [4858] [0] PANIC: bearerbox(main+0xe83) [0x80525f3]
    2012-12-04 16:05:23 [4858] [0] PANIC: /lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x3864d3]
    2012-12-04 16:05:23 [4858] [0] PANIC: bearerbox() [0x80526a1]

  2. group = core
    admin-port = 13015
    admin-password = manish
    #admin-deny-ip = “*.*.*.*”
    admin-allow-ip = “127.0.0.1”
    dlr-storage = mysql
    smsbox-port = 13016
    #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”
    log-level = 0

    #group = wapbox
    #bearerbox-host = localhost
    #log-file = “/var/log/kannel/wapbox.log”

    group = smsc
    smsc-id = Nokia
    smsc = at
    modemtype = auto
    device = /dev/ttyUSB0
    my-number = +919752490483
    connect-allow-ip = 127.0.0.1
    sim-buffering = true
    log-level = 0
    #log-file = “/var/log/kannel/smsc.log”
    # DLR with MySQL support configuration

    group = mysql-connection
    id = mydlr
    host = localhost
    username = root
    password = nicsagar
    database = adbook

    group = dlr-db
    id = mydlr
    table = dlr
    field-smsc = smsc
    field-timestamp = ts
    field-source = source
    field-destination = destination
    field-service = service
    field-url = url
    field-mask = mask
    field-status = status
    field-boxc-id = boxc

    group = modems
    id = auto
    name = “Nokia”
    detect-string = “Nokia”
    init-string = “ATZ”
    #init-string = “AT+CMEE=1”
    #init-string = “AT Q0 V1 E1 S0=0 &C1 &D2 +FCLASS=0”
    init-string = “AT+CNMT=2,1,2,2,0; +CMEE=1”
    message-storage = SM
    #message-start = 0
    #speed = 460800
    #message-start = 0

    group = smsbox
    smsbox-id = mysmsbox
    bearerbox-host = localhost
    bearerbox-port = 13020
    sendsms-port = 13018
    global-sender = +919752490483
    access-log = “/var/log/kannel/smsbox-access.log”
    log-file = “/var/log/kannel/smsbox.log”
    log-level = 0
    mo-recode = true

    group = smsbox-route
    smsbox-id = mysmsbox
    smsc-id = Nokia
    group = sendsms-user
    username = admin
    password = nicsagar
    concatenation = true
    max-messages = 10000

    group = sms-service
    keyword-regex = .*
    #text = “Thanks for sending SMS”
    catch-all = true
    accepted-smsc = Nokia
    max-messages = 99
    get-url = “http://comp.ac.in/sms/kannel/sms_service.php?phone=%p&text=%a”

  3. ubuntu@ubuntu-desktop:~/Desktop$ bearerbox -v kannel.conf
    2012-12-05 15:42:07 [19333] [0] INFO: Debug_lvl = 0, log_file = , log_lvl = 0
    2012-12-05 15:42:07 [19333] [0] PANIC: DLR: storage type ‘mysql’ is not supported!
    2012-12-05 15:42:07 [19333] [0] PANIC: bearerbox(gw_panic+0xd2) [0x80cb032]
    2012-12-05 15:42:07 [19333] [0] PANIC: bearerbox(dlr_init+0x220) [0x805f250]
    2012-12-05 15:42:07 [19333] [0] PANIC: bearerbox(main+0xea) [0x805185a]
    2012-12-05 15:42:07 [19333] [0] PANIC: /lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x1444d3]
    2012-12-05 15:42:07 [19333] [0] PANIC: bearerbox() [0x80526a1]

  4. Are you follow my installation guide
    2012-12-05 13:50:44 [18317] [0] ERROR: Couldn’t open logfile `/var/log/kannel/kannel-sqlbox.log’.

    This error show that you are not install kannel-sqlbox
    Run this command with sudo user.
    $ apt-get install kannel-sqlbox.

  5. now i configure kannel properly with help navdeep.
    thankx navdeep ji.
    your blog is prefect for newcomers.
    my experience on your is very well.
    and i hope in future i also learn some more technologies form your blog.
    and again thank you very much

  6. #
    #My kannel.conf
    # Sample configuration file for Kannel bearerbox on Debian.
    # See the documentation for explanations of fields.
    #
    include = “/etc/kannel/modems.conf”
    #include = “/etc/kannel/sqlbox.conf”
    # HTTP administration is disabled by default. Make sure you set the
    # password if you enable it.

    group = core
    admin-port = 13000
    smsbox-port =13001
    admin-password = bar
    status-password = foo
    log-file = “/var/log/kannel/bearerbox.log”
    log-level = 0
    box-deny-ip = “*.*.*.*”
    box-allow-ip = “127.0.0.1”
    dlr-storage = mysql

    group = smsc
    smsc = at
    modemtype = ericsson
    device = /dev/ttyACM0
    # speed =
    sms-center = “+256700000088”
    my-number = *********
    validityperiod = 167

    group = modems
    id = ericsson
    name = “ST-Ericsson”
    # detect-string = “e160”
    init-string = “AT+CNMI=1,2,0,1,0″
    speed = 115200

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

    group = sendsms-user
    username = kannel
    password = kannel
    concatenation = true
    max-messages = 1000
    default-smsc = SMSC-ID
    user-allow-ip=”*.*.*.*”
    #drl-ulr=”http://localhost/sms.php?keyword=%k&seckeyword=%s&regtime=%t&sender=%p&receiver=%P&text=%a&dlrvalue=%d”

    group = sms-service
    keyword = track
    #get-url = “http://localhost/kannel/receivesms.php?sender=%p&text=%b”
    get-url=”http://localhost/kannel/sms.php?keyword=%k&seckeyword=%s&regtime=%t&sender=%p&receiver=%P&text=%a&dlrvalue=%d”
    accept-x-kannel-headers = true
    max-messages = 3
    concatenation = true
    catch-all = yes

    #
    # DLR with MySQL support configuration
    #
    # Example defining a MySQL database connection resource and
    # the required table and field values.
    #

    group = mysql-connection
    id = mydlr
    host = localhost
    username = username
    password = password
    database = kannel
    # max count of connections that will be opened for dbpool
    # default is 1
    max-connections = 10

    group = dlr-db
    id = mydlr
    table = received
    field-smsc = smsc
    field-timestamp = ts
    field-destination = destination
    field-source = source
    field-service = service
    field-url = url
    field-mask = mask
    field-status = status
    field-boxc-id = boxc

    #my slqbox.conf
    group = sqlbox
    id = sqlbox-db
    smsbox-id = sqlbox
    global-sender = ********
    bearerbox-host = localhost
    bearerbox-port = 13001
    smsbox-port = 13005
    smsbox-port-ssl = false
    sql-log-table = sent_sms
    sql-insert-table = send_sms
    log-file = “/var/log/kannel/kannel-sqlbox.log”
    log-level = 0
    #ssl-client-certkey-file = “”
    #ssl-server-cert-file = “”
    #ssl-server-key-file = “”
    #ssl-trusted-ca-file = “”

    # Database connection examples. Please uncomment as needed

    # Example MYSQL Connection
    group = mysql-connection
    id = sqlbox-db
    host = localhost
    username = username
    password =password
    database = kannel

    # Example ORACLE Connection
    #group = oracle-connection
    #id = sqlbox-db
    #username = myuser
    #password = mypass
    #tnsname = //localhost:1521/XE

    # Example POSTGRESQL Connection
    #group = pgsql-connection
    #id = sqlbox-db
    #id = sqlbox-db
    #username = myuser
    #password = mypass
    #database = kannel
    #host = localhost

    # Example SDB Connection with some database URL examples
    # *** Note: Uncomment only _one_ “url” line ***
    #group = sdb-connection
    #id = sqlbox-db
    #url = mysql:host=localhost:db=kannel:uid=myuser:pwd=mypass
    #url = sqlite:db=/path/to/kannel.db
    #url = sqlite3:db=/path/to/kannel3.db

    # Example SQLITE 2 Connection
    #group = sqlite-connection
    #id = sqlbox-db
    #database = /path/to/kannel.db
    #max-connections = 1

    # Example SQLITE 3 Connection
    #group = sqlite3-connection
    #id = sqlbox-db
    #database = /path/to/kannel.db
    #max-connections = 1

    Could you please tell me what am doing wrong
    i can send and recieve messages but can’t store them in Mysql Database
    your help is highly appreciated

    1. hello Ruyonga
      There are two methods to send SMS through kannel.
      First one is to send sms through browser.
      Second one is to send sms through dbms.
      In case of dbms, two tables are used i.e send_sms and sent_sms whose sql code is provided in last lines of tutorial.
      Run sql query directly or through application to add values in send_sms table.
      When kannel is activated, kannel automatically check send_sms table and send sms, logs were stored in sent_table automatically.

      Thankiew

  7. Hello Navdeep…

    hi the bearerbox, smsbox, sqlbox are all connected… the user name and password i set to ‘kannel’.
    when i try to send through browser i get this error

    Unknown command `/cgi-bin/sendsms’.
    Possible commands are:
    status
    store-status
    log-level
    shutdown
    suspend
    isolate
    resume
    restart
    flush-dlr
    stop-smsc
    start-smsc
    reload-lists

    the url i tried was
    localhost:13003/cgi-bin/sendsms?username=kannel&password=kannel&to=99433*****&text=Hello+world

    thank you

    1. Are you sure you enter correct username and password in sendsms-user group and your admin port is 13003 in kannel.conf file.
      which version of kannel you are using?
      First try URL without username and password of kannel.
      Second install cgi-bin.

Leave a Reply

Your email address will not be published. Required fields are marked *