Posts Tagged ‘smsc’

SMS Gateway with Kanneland Huawei 3G Modem on Ubuntu

08 Dec

Source: Setting Up an SMS Gateway with Ubuntu 8.04, Kannel and Huawei E220 GSM Modem

I’ve used the link above as a guide to how I did my installation. The one I did was way easier though, as I didn’t have to compile the source anymore. It might have been the version of Kannel that we used that is different. The above guide used 1.4.1 whereas I used 1.4.3 that came with Ubuntu’s packages.

Anyway, the model I used for the GSM Modem is a Huawei E156C HSDPA USB Stick, not a E220 GSM Modem. I used the same identifier as the E220 though, and so far no problems. Should work just fine.

First off, let’s install Kannel.

sudo apt-get install kannel

Next, configure Kannel by editing the configuration file found in /etc/kannel/kannel.conf. My configuration file is shown below

group = core
admin-port = 13000
admin-password = ourkannelpassword
admin-deny-ip = "*.*.*.*"
admin-allow-ip = ""
wapbox-port = 13002
smsbox-port = 13003
wdp-interface-name = "*"
log-file = "/var/log/kannel/bearerbox.log"
box-deny-ip = "*.*.*.*"
box-allow-ip = ""
unified-prefix = "+"

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

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

group = smsc
smsc = at
smsc-id = smsc-smart-bro
port = 10000
modemtype = huawei_e220_00
device = /dev/ttyUSB1
sms-center = "+XXXXXXXXXXXX"
connect-allow-ip = ""
log-file = "/var/log/kannel/smsc.log"

group = smsbox
bearerbox-host = localhost
smsbox-id = smsbox-smart-bro
log-file = "/var/log/kannel/smsbox.log"

group = smsbox-route
smsbox-id = smsbox-smart-bro
smsc-id = smsc-smart-bro

group = sms-service
keyword = default
text = "No service defined"
catch-all = true

There are a bazillion ways to configure Kannel, and since I’m new at this, I just used the barebones minimum for receiving and processing SMS messages. The important part here is how to configure the modem, and the smsc (Defined by the group setting) to work together.

Lucky for us that Ubuntu ships with drivers for this modem. Once you connect the modem on a USB port, you can check it with the following command:


You should see something like this. As you can see, even if I used a E156C model, it detects it as the E220 HSDPA Modem.

Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 006: ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E270 HSDPA/HSUPA Modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

It should also attach a tty onto it. In my case, it attaches to both /dev/ttyUSB0, and /dev/ttyUSB1.

To make sure where that is attached to, run:

udevadm info -q all -n /dev/ttyUSB0
udevadm info -q all -n /dev/ttyUSB1

You should be able to see on which device it is connected to.

Going back to Kannel configuration, we need to find out how to configure the modem in kannel.conf. Basically, it’s just knowing the right parameters to set. For the modem group, the important thing is the init-string. I’m not an expert on it, so I just copied it from the Huawei forums. Basically, it uses AT commands (you can try playing with it in minicom or in HyperTerminal if you are on Windows).

Next is to configure the smsc group. Here, we define the modemtype to use the modem that we just configured. This modem type is the id assigned to the modem. At the same time, we need to tell the smsc to connect to which device, in my case, it’s /dev/ttyUSB1. Check out the source link from above why we used ttyUSB1 instead of ttyUSB0. It has to do with the main loop and event handling where there will be no more delay because ttyUSB1 will fire an event whenever an SMS is received (or something like that).

Once that is done, I setup smsbox-route just to be sure that smsc forwards everything to the smsbox defined, as well as future proofing it if I add more smsbox, and smsc configurations in the future. This would avoid more confusion later.

Next, the tricky part. We restart the kannel service. Now, the kannel service will be starting 2 daemons by default. The bearerbox daemon, as wel as the wapbox daemon. But it only shows ‘Starting WAP gateway’ as the message. I checked my processes, and then there it was, only the bearerbox and wapbox service. No smsbox. If you look into the init script, it will check for a $START_WAPBOX, $START_SMSBOX variable to start the daemons. I didn’t realize this until I dug deeper 2 hours since I started. Apparently, you need to edit /etc/default/kannel to set these environment variables. By default, you will see this:


So to start the smsbox, you just edit that file, uncomment the 2nd line, and then restart the kannel service.

Once you start the service, the SMSC log will report a PERMISSION DENIED, and will not be able to start the service. This is because if you look at the permissions of /dev/ttyUSB1, it is owned by root:dialout. This is easy to fix. We just need to add the user kannel into the dialout group by running the following command:

sudo usermod -G dialout kannel

Then restart the kannel service:

sudo /etc/init.d/kannel restart

That’s it!


Posted in HowTo, Mobile