Home > Kannel, Linux > Setup Kannel SMS Gateway on Ubuntu

Setup Kannel SMS Gateway on Ubuntu

This are the required steps to setup Kannel as an SMS Gateway on Ubuntu. Here we use a simple GSM modem attached to USB port 0, using Enfora modem. You can use other standard AT command modems actually.

Enable the SMS Box

Edit file /etc/default/kannel , uncomment the START_SMSBOX line to enable the SMS Box

sudo vi /etc/default/kannel

START_WAPBOX=1
START_SMSBOX=1

 

Add kannel user to dialout group

This will enable kannel user (user who run kannel process as) to use the /dev/ttyUSB0 device that is necessary when we are using USB GMS modems.

sudo vi /etc/group

dialout:x:20:daniel,kannel

 

Configure Kannel

Edit /etc/kannel/kannel.conf file to configure the smsbox-port, smsbox group, smsc group, and modems group. These lines on bold below is the additional lines compared to the default Kannel Ubuntu setup.

sudo vi /etc/kannel/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 = bar
admin-deny-ip = "*.*.*.*"
admin-allow-ip = ""
wapbox-port = 13002
wdp-interface-name = "*"
log-file = "/var/log/kannel/bearerbox.log"
box-deny-ip = "*.*.*.*"
box-allow-ip = "127.0.0.1"
smsbox-port = 13003

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

####### SMS box setup
group = smsbox
bearerbox-host = localhost
log-file = "/var/log/kannel/smsbox.log"

####### SMSC / GSM modem setup, using enfora modem defined below
group = smsc
smsc = at
modemtype = enfora
device = /dev/ttyUSB0

####### enfora modem definition
group = modems
id = enfora
name = "Enfora"
detect-string = "Enfora"
init-string = "AT+CNMI=1,2,0,1,0"
speed = 115200

####### SMS services definition, what to do when an SMS is recieved
group = sms-service
keyword = smsemail
get-url = "http://localhost/SMSServlet/SMSServlet?sender=%p&message=%a"
max-messages = 1

group = sms-service
keyword = default
text = default reply
max-messages = 0

 

Run Kannel

Run kannel SMS Gateway using this command:

sudo /etc/init.d/kannel restart

Then see the the bearerbox.log file to inspect if there’s something wrong:

sudo tail –f /var/log/kannel/bearerbox.log

2010-05-05 16:25:02 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– OK
2010-05-05 16:25:02 [5121] [6] INFO: AT2[/dev/ttyUSB0]: closing device
2010-05-05 16:25:02 [5121] [6] INFO: AT2[/dev/ttyUSB0]: speed is 115200
2010-05-05 16:25:02 [5121] [6] INFO: AT2[/dev/ttyUSB0]: opening device
2010-05-05 16:25:02 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: device opened
2010-05-05 16:25:02 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: device opened
2010-05-05 16:25:02 [5121] [6] INFO: AT2[/dev/ttyUSB0]: init device
2010-05-05 16:25:02 [5121] [6] INFO: AT2[/dev/ttyUSB0]: speed set to 115200
2010-05-05 16:25:02 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: –> ATZ^M
2010-05-05 16:25:02 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– OK
2010-05-05 16:25:02 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: –> AT^M
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– OK
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: –> AT&F^M
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– OK
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: –> ATE0^M
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– OK
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: –> AT+IFC=2,2^M
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– OK
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: –> AT+CPIN?^M
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– +CPIN: READY
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– OK
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: –> AT+CMGF=0^M
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– OK
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: –> AT+CSMS=?^M
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– +CSMS: (0,1)
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– OK
2010-05-05 16:25:03 [5121] [6] INFO: AT2[/dev/ttyUSB0]: Phase 2+ is supported
2010-05-05 16:25:03 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: –> AT+CSMS=1^M
2010-05-05 16:25:04 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– +CSMS: 1,1,1
2010-05-05 16:25:04 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– OK
2010-05-05 16:25:04 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: –> AT+CNMI=1,2,0,1,0^M
2010-05-05 16:25:04 [5121] [6] DEBUG: AT2[/dev/ttyUSB0]: <– OK
2010-05-05 16:25:04 [5121] [6] INFO: AT2[/dev/ttyUSB0]: AT SMSC successfully opened.

 

The info line "AT SMSC successfully opened" indicates that the SMSC modem is working well.

Test the SMS Service

Now try to send an SMS from your mobile phone to the number attached to the GSM modem. In this example we send "SMSEMAIL ON" message to be processed by the process.php file located on http://localhost.

Look at the smsbox.log file:

sudo tail -f /var/log/kannel/smsbox.log

When an SMS is received, the log will shows similar to this:

……

2010-05-05 16:30:23 [5236] [4] INFO: Starting to service <Smsemail on> from <+6281320379277> to <1234>
2010-05-05 16:30:23 [5236] [8] DEBUG: Thread 8 (gwlib/fdset.c:poller) maps to pid 5236.
2010-05-05 16:30:23 [5236] [4] DEBUG: Started thread 8 (gwlib/fdset.c:poller)
2010-05-05 16:30:23 [5236] [9] DEBUG: Thread 9 (gwlib/http.c:write_request_thread) maps to pid 5236.
2010-05-05 16:30:23 [5236] [9] DEBUG: Parsing URL `http://localhost/SMSServlet/SMSServlet?sender=%2B6281320379277&message=Smsemail+on’:
2010-05-05 16:30:23 [5236] [9] DEBUG:   Scheme: http://
2010-05-05 16:30:23 [5236] [9] DEBUG:   Host: localhost
2010-05-05 16:30:23 [5236] [9] DEBUG:   Port: 80
2010-05-05 16:30:23 [5236] [9] DEBUG:   Username: (null)
2010-05-05 16:30:23 [5236] [9] DEBUG:   Password: (null)
2010-05-05 16:30:23 [5236] [9] DEBUG:   Path: /SMSServlet/SMSServlet
2010-05-05 16:30:23 [5236] [9] DEBUG:   Query: sender=%2B6281320379277&message=Smsemail+on
2010-05-05 16:30:23 [5236] [9] DEBUG:   Fragment: (null)
2010-05-05 16:30:23 [5236] [9] DEBUG: HTTP: Opening connection to `localhost:80′ (fd=27).
2010-05-05 16:30:23 [5236] [9] DEBUG: Socket connecting
2010-05-05 16:30:23 [5236] [4] DEBUG: Started thread 9 (gwlib/http.c:write_request_thread)
2010-05-05 16:40:53 [5309] [8] DEBUG: Get info about connecting socket
2010-05-05 16:40:53 [5309] [8] DEBUG: HTTP: Sending request:
2010-05-05 16:40:53 [5309] [8] DEBUG: Octet string at 0×8155a70:
2010-05-05 16:40:53 [5309] [8] DEBUG:   len:  134
2010-05-05 16:40:53 [5309] [8] DEBUG:   size: 1024
2010-05-05 16:40:53 [5309] [8] DEBUG:   immutable: 0
2010-05-05 16:40:53 [5309] [8] DEBUG:   data: 47 45 54 20 2f 53 4d 53 53 65 72 76 6c 65 74 2f   GET /SMSServlet/
2010-05-05 16:40:53 [5309] [8] DEBUG:   data: 53 4d 53 53 65 72 76 6c 65 74 3f 73 65 6e 64 65   SMSServlet?sende
2010-05-05 16:40:53 [5309] [8] DEBUG:   data: 72 3d 25 32 42 36 32 38 31 33 32 30 33 37 39 32   r=%2B62813203792
2010-05-05 16:40:53 [5309] [8] DEBUG:   data: 37 37 26 6d 65 73 73 61 67 65 3d 53 6d 73 65 6d   77&message=Smsem
2010-05-05 16:40:53 [5309] [8] DEBUG:   data: 61 69 6c 2b 6f 6e 20 48 54 54 50 2f 31 2e 31 0d   ail+on HTTP/1.1.
2010-05-05 16:40:53 [5309] [8] DEBUG:   data: 0a 48 6f 73 74 3a 20 39 34 2e 32 32 39 2e 31 37   .Host: 127.0.0
2010-05-05 16:40:53 [5309] [8] DEBUG:   data: 31 2e 37 3a 38 30 38 30 0d 0a 55 73 65 72 2d 41   .1:80..User-A
2010-05-05 16:40:53 [5309] [8] DEBUG:   data: 67 65 6e 74 3a 20 4b 61 6e 6e 65 6c 2f 31 2e 34   gent: Kannel/1.4
2010-05-05 16:40:53 [5309] [8] DEBUG:   data: 2e 31 0d 0a 0d 0a                                 .1….
2010-05-05 16:40:53 [5309] [8] DEBUG: Octet string dump ends.
2010-05-05 16:40:54 [5309] [8] DEBUG: HTTP: Status line: <HTTP/1.1 200 OK>
2010-05-05 16:40:54 [5309] [8] DEBUG: HTTP: Received response:
2010-05-05 16:40:54 [5309] [8] DEBUG: Octet string at 0×8157090:
2010-05-05 16:40:54 [5309] [8] DEBUG:   len:  131
2010-05-05 16:40:54 [5309] [8] DEBUG:   size: 1024
2010-05-05 16:40:54 [5309] [8] DEBUG:   immutable: 0
2010-05-05 16:40:54 [5309] [8] DEBUG:   data: 53 65 72 76 65 72 3a 20 41 70 61 63 68 65 2d 43   Server: Apache-C
2010-05-05 16:40:54 [5309] [8] DEBUG:   data: 6f 79 6f 74 65 2f 31 2e 31 0d 0a 43 6f 6e 74 65   oyote/1.1..Conte
2010-05-05 16:40:54 [5309] [8] DEBUG:   data: 6e 74 2d 54 79 70 65 3a 20 74 65 78 74 2f 68 74   nt-Type: text/ht
2010-05-05 16:40:54 [5309] [8] DEBUG:   data: 6d 6c 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67   ml..Content-Leng
2010-05-05 16:40:54 [5309] [8] DEBUG:   data: 74 68 3a 20 32 30 0d 0a 44 61 74 65 3a 20 57 65   th: 20..Date: We
2010-05-05 16:40:54 [5309] [8] DEBUG:   data: 64 2c 20 30 35 20 4d 61 79 20 32 30 31 30 20 30   d, 05 May 2010 0
2010-05-05 16:40:54 [5309] [8] DEBUG:   data: 39 3a 34 31 3a 34 34 20 47 4d 54 0d 0a 0d 0a 55   9:41:44 GMT….U
2010-05-05 16:40:54 [5309] [8] DEBUG:   data: 70 64 61 74 65 20 53 75 63 63 65 73 73 66 75 6c   pdate Successful
2010-05-05 16:40:54 [5309] [8] DEBUG:   data: 6c 0d 0a                                          l..
2010-05-05 16:40:54 [5309] [8] DEBUG: Octet string dump ends.
2010-05-05 16:40:54 [5309] [5] DEBUG: message length 18, sending 1 messages
2010-05-05 16:40:54 [5309] [0] DEBUG: Got ACK (0) of 27e7a8ed-6611-40fc-8d54-53f8d70cec3d
2010-05-05 16:40:54 [5309] [0] DEBUG: No client – multi-send or ACK to pull-reply
2010-05-05 16:41:14 [5309] [8] DEBUG: HTTP: Server closed connection, destroying it <localhost:80><0×8155fa8><fd:27>.

In a short time, you will receive the reply from SMS Gateway number containing Update Successfull message (the reply got from http://localhost/SMSServlet/SMSServlet  ).

  • Share/Bookmark
  1. André
    June 15th, 2010 at 01:03 | #1

    how many modems the kannel supports and how can I make this setting ?
    my English is not the best.

    Tank you!

  2. July 14th, 2010 at 04:08 | #2

    one modem for each USB ports, so if you have 4 USB ports, then kannel can support 4 modems

  3. September 8th, 2010 at 10:24 | #3

    Thanks for the tutorial :) Very useful.

  1. No trackbacks yet.

Ikutilah Seminar GPS! "MEMBONGKAR RAHASIA BISNIS GPS TRACKING" - Pembicara : Ir. Akhmad Daniel Sembiring (CEO Vitraining.com & GpsTrackingIndonesia.com) - Bandung, Sabtu 25 September 2010 - Hotel Arion Swiss - Belhotel, Jl. Otto Iskandardinata No. 16 Bandung - Biaya Pendaftaran : 2 Jt (sebelum 18 September 2010 HANYA 1 Jt) - Register ONLINE : seminar-gps.vitraining.com - More Info e-mail to : info@gpstrackingindonesia.com

This site uses a Hackadelic PlugIn, Hackadelic SEO Table Of Contents 1.6.0.