Do You Want Some Kannel on Top of That

(Disclaimer: Title might not make sense to everyone depending on your spoken language, but you should be able to consume the contents nonetheless :) )

From time to time you’ve probably felt the need to reach out to your devices via SMS. Either for providing info to the user, or more nefarious purposes like wiping, etc. I’ve also mentioned previously that some MDM use SMS as their primary vehicle for managing devices – and if you’re using one of those solutions you may be happy with what you’ve got. If you are using an MDM platform which does not rely on SMS you may still want to leverage SMS from time to time. Hey, maybe you’re not running any MDM at all, and just want to send SMS from your computer.

There are a multitude of different solutions out there that will ley you do this. If you cradle your Windows Mobile device Jeyo Mobile Extender will help you out. My mobile operator provides a plug-in for Outlook, and so do many other operators. But if you want to send a larger amount of SMS messages, send binary messages, and do so on a server level the de facto standard is an open-source solution called Kannel. This will let you run your own SMS and/or WAP gateway, and send the messages either through dedicated SMS modems, mobile phones, or commercial SMS gateways. (Many of the gateway providers will let you interface to them in a number of ways, but Kannel acts as a layer of abstraction so you can switch gateway provider, and not have to hard code the interfaces in your code.) You also get functionality like queuing, load balancing, receiving, etc. So running with that idea I’ll start off installing Kannel on a box of my own.

Kannel is an open-source effort aimed primarily at *nix boxes, but it will happily run on Windows as well. If you compile the source code yourself that is. Thankfully it’s not as hard as you might think :)

Kannel will work on both Windows XP/Vista and Windows Server. I’ve done it on a virtual XP machine primarily because it’s lightweight and got Visual Studio installed (for dev stuff later on). If you will be using it in a server setting you should probably run it on a server level OS. I’ve tested it on 32-bit, but see no reason it shouldn’t work on 64-bit. If you are running 2K8 R2 RC 64-bit that might be a few too many unknowns currently, so 2K3 may be a safer bet for the moment being :) It doesn’t require installation after the compile and config is done so you can just copy the files from one box to another for that matter (maybe not between x86 and x64 mind you).

You’ll need two things to start with:
Download Kannel from www.kannel.org (download the zip source).
Download Cygwin from www.cygwin.org. This is the tool you need to compile the source to something that works under Windows.

Unzip the Kannel source in a directory of your choosing.

Run the setup.exe you downloaded from Cygwin. It’s pretty much next, next, next. Just make sure you check some additional developer packages:
Gcc-core
Gcc-g++
Gdb
Libxml2
Libxml2-devel
Make

See below:
Cygwin_install

After installing Cygwin you can fire up a bash cmd line. Change to the directory where your Kannel source is located, in my case the command is “cd /cygdrive/c/install/Kannel/gateway”. (You remember the MS-DOS days, right?)

Run “./configure”.
Kannel_Compile_1 

Run “make”.
Kannel_Compile_2

Done.
Kannel_Compile_3

Now you can return to Windows. The Kannel dir contains a lot of files – you don’t need them all.
Kannel_Dir

Create a new directory, and copy the following files:
Bearerbox.exe
Smsbox.exe
Wapbox.exe

In addition you need some dlls from the cygwin/bin dir:
cygwin1.dll
cygz.dll
cygiconv-2.dll
cygxml2-2.dll

And you’ll end up with something like this:
Kannel_Dir_2

Kannel comes “unconfigured” out of the box (there are after all a lot of different setups out there), Fire up your Notepad and create a file called “kannel.conf”. I’ve provided a minimum config below (obviously with some “faked” fields mind you):

# SEND-SMS USER
group = sendsms-user
username = dummy
password = passw0rd
max-messages = 100
concatenation = true
default-sender = 12345678

# BEARERBOX SETUP
group = core
admin-port = 13001
smsbox-port = 13002
admin-password = yadayada
box-deny-ip = "*.*.*.*"
box-allow-ip = "127.0.0.1"

# SMSBOX SETUP
group = smsbox
bearerbox-host = localhost
sendsms-port = 13000

# Generic modem description
group = modems
id = generic
name = "generic"
init-string = "AT"

# SMPP SMSC
group = smsc
smsc-id = mySMSC
preferred-smsc-id = mySMSC
smsc = smpp
host = 192.168.0.1
port = 30002
receive-port = 30002
smsc-username = dummy
smsc-password = passw0rd
system-type = "gw0"
address-range = ""
source-addr =

For a closer explanation of these configuration options you should check out the Kannel documentation online.

I have an account with a gateway provider, and I’ll be using an SMPP interface for the communication. You’ll obviously need to find out what suit your needs the best, and configure accordingly :) Finding out all the details can be a challenge, but if you are using a commercial provider they might be able to help you out with the necessary details.

After saving the conf-file fire up two command prompts. Change to the Kannel dir, and run “bearerbox” in the first, and “smsbox” in the second. In that order. Yes, I know – you’ll either want to run them as services, or create a batch file. But for an initial test this is a quicker approach.

By default you can use HTTP posts to send SMS messages. So since we’re stil in a test mode, start up your browser and enter the following url in the address bar (changing the to field to an actual phone number, and depending on how/where you pass the messages through include the country prefix as necessary):

http://localhost:13000/cgi-bin/sendsms?user=dummy&pass=passw0rd&to=12345678&text=Hello+World

You’ll hopefully get a “0: Accepted for delivery” feedback. If not – you are due for some troubleshooting. (Look for clues in the command prompt windows.) I had some fun getting the details right for the smsc. Tip: passwords may not be longer than 8 characters with SMPP.

Now this doesn’t seem too impressive I’ll grant you that. I’ve just spent a whole lot of time on something I could have achieved in seconds on my device, or a matter of minutes installing a small app on my computer. But it lays the groundwork for doing more “fancy” stuff later. Which I will be covering another day :)

11 Responses to “Do You Want Some Kannel on Top of That”

  1. Andreas, you are off the chart in the mobility world. Awesome post. I’m sure NowSMS are really pleased with your post. NOT. I’m now waiting for the post “How to build your own SMPP gateway.

    Cheers Wayne
    Airloom

  2. Andreas, you are off-the-chart in the mobility world. Awesome post. I am sure NowSMS are really pleased with your solution. NOT. I’m now waiting for your next post “How to build your own SMPP gateway.

    Cheers Wayne
    Airloom

  3. Thank you Wayne. I believe there is an add-on module for Kannel – smppbox so you can run your own gateway. Not sure if it costs money or it’s also free. But obviously it would still require some work getting “direct access” to the mobile operators network for sending the stuff through :) (So might have to wait a little while for this post to surface.)
    But I will be exploring some scenarios, and will probably post more articles as to what can be done with this Kannel box :)

  4. Pirate

    Your post is awesome. I spend a couple of days searching how to do this freaky thing.

    thanks.

  5. sheedx

    i try to run bearerbox and smsbox, but after a few minutes, there’s an error [panic] mutex error blablabla, and then smsbox shut down…

    i’ve tried this procedure several times, and those error always occured, can u help me, whats the problem here… Thanks Before

  6. Yup, there is a bug in Kannel.

    Hopefully this fix would apply to your installation as well:
    You need to edit a file – gateway-1.4.1\gwlib\thread.c
    Comment out the following lines:

    if (mutex->owner == gwthread_self())
    panic(0, “%s:%ld: %s: Managed to lock the mutex twice! (Called from %s:%ld:%s.)”, \
    __FILE__, (long) __LINE__, __func__, file, (long) line, func);

    And you’ll have to re-compile too. I’ve only seen this on Windows XP, not on Windows Server so it might be something related to the OS as well.

  7. Richard Crawshaw

    Hi,

    It’s probably worth mentioning that Cygwin is unfortunately not stable enough under load to allow Kannel under Cygwin to be production stable.

    I’ve done quite a bit of work with Kannel running under Cygwin on Windows (both W7 and Server 2003) in recent weeks. When subjecting Kannel to 30,000 messages Cygwin will just crash. Both the Bearer Box and the SMS Box services have to be restarted.

    The Kannel user-group have confirmed that Cygwin’s p-threads are the issue.

    But as a test environment Kannel under Cygwin is great.

  8. 30.000 messages is certainly a slightly more demanding environment than my test setup :)

    I have customers running Cygwin-based Kannel on both Windows Server 2003 and Windows Server 2008 R2, but it’s nowhere near that amount of messages (it’s in MDM deployments, where sending SMS is just a support function), and while there are some random crashes it works quite nicely all in all for those setups.

    Of course – it’s great that there are people testing the more demanding scenarios as well :) I would assume that setting up a dedicated Kannel box on something *nix-based would scale better for a load like that.

  9. Akash

    i have entered ./configure and again make . I have done everything.but i cannot find out kannel.conf file.

  10. Not sure I get what your issue is Akash.
    The kannel.conf is not created by compile & make. You have to create it manually.
    I have created a sample above, but you will need some details from your SMS provider to get the config correct for your environment. If you have access to a SMPP SMSC the config should work (of course providing a proper username, IP address, etc). If you’re not using SMPP you will need a different config, and it might be a little tricky to get working.
    Many SMS providers are familiar with Kannel though, so they might be able to help you out with the settings needed.

  1. Tweets that mention Do You Want Some Kannel on Top of That | MobilityDojo.net -- Topsy.com
Leave a Reply

*
RSS for Posts RSS for Comments