Not Quite Done With That Kannel Yet

It was fun installing Kannel, and naturally I cannot leave it at that. While it is perfectly possible to send all your messages by hitting the characters in the correct order in your browser’s address bar, it’s slightly impractical in the long run. So I thought I’d look into making it more user friendly.

Actually first off, lets do a few more things related to your Kannel config.

Your SMSC will probably set a default number the messages give the impression of being sent from. Any good SMSC will let you decide what the “from”-field says. Usually it can be either a number or characters. It can be set on a pr message basis, but if you always want it to be the same you can add the following line to your kannel conf (below the send-sms config section):
Default sender = MobilityDojo.net

There may be a limit to how many characters you can use though, and I can’t actually use my entire domain name since this is above the threshold…

We just fired up the bearerbox and the smsbox last time. But if you want to send wap messages, and do provisioning you might want to fire up the wapbox service as well. This needs some extra lines of config:

Append this to your kannel.conf:

# WAPBOX SETUP
group = wapbox
bearerbox-host = localhost

Add one line in your existing bearerbox setup (the last one):

# BEARERBOX SETUP
group = core

wapbox-port = 13003

I also made a reference to running the the “boxes” as Windows services, instead of starting the files manually from the command line. I can’t take credit here, as the always helpful Mr. David Creedy sent the necessary batch files to me, saving me some work. You’ll want to run the following batch file (assuming Kannel is installed in C:\Program Files\Kannel, and that you have subfolders called bin and log.)

"C:\Program Files\kannel\bin\cygrunsrv" -I bearerbox
-p "C:\Program Files\kannel\bin\bearerbox.exe"
-a "'C:\Program Files\kannel\bin\kannel.conf'"
-1 "C:\Program Files\kannel\log\bearerbox2.log"
-2 "C:\Program Files\kannel\log\bearerbox.log"
"C:\Program Files\kannel\bin\cygrunsrv" -I smsbox
-p "C:\Program Files\kannel\bin\smsbox.exe"
-a "'C:\Program Files\kannel\bin\kannel.conf'"
-1 "C:\Program Files\kannel\log\smsbox2.log"
-2 "C:\Program Files\kannel\log\smsbox.log"
-y bearerbox
"C:\Program Files\kannel\bin\cygrunsrv" -I wapbox
-p "C:\Program Files\kannel\bin\wapbox.exe"
-a "'C:\Program Files\kannel\bin\kannel.conf'"
-1 "C:\Program Files\kannel\log\wapbox2.log"
-2 "C:\Program Files\kannel\log\wapbox.log"
-y bearerbox

Mind you; I have split the lines for readability reasons, it should be just three lines when saved as xyz.bat.

You should end up with three Windows Services:

Srv_Bearerbox

I experienced a strange issue where my SMSC was giving me an error saying there was something wrong with the username/password supplied (and I had double-checked), but this turned out to be an issue of whether I included the + sign before the “to” number or not. I have to specify both country id, and phone number, but the + should not be necessary. It even seems it is stripped off by Kannel before reaching the SMSC, but apparently it jinxed the urlencode or something. Don’t know if anyone else experienced this, but in case you are wondering the urlencoding of + is %2B so just include that in front of the phone number that is to be the receiver.

Still taking things along nice and slow I created a small app that is basically just one step above “Hello World”, but we like to start off simple :) Doing away with the friendliness of interfacing directly with the Kannel smsbox it will do the HTTP GET for you based on your inputs. Looks like this, and should be self-explanatory:

CinnamonSMS_Config

CinnamonSMS_Send

I created this as a WPF app testing out the Visual Studio 2010 Beta and .NET 4.0, but it’s easy to implement in other ways as well. Here’s a snippet of the C# code that does the work for you:

private void btnSend_Click(object sender, RoutedEventArgs e)    

{
   string smsPost = kannelServer + ":" + kannelPort + smsPath 

   + "?user=" + userName + "&pass=" + passWord + "&from=" 

   + fromAddress + "&to=%2B" + toAddress + "&text=" + msgContent;
   string kannelRes = sendSMS(smsPost);

}

string sendSMS(string uri)
{
   WebRequest webRequest = WebRequest.Create(uri);
   webRequest.ContentType = "x-www-form-urlencoded";
   webRequest.Method = "GET";

   try
      {
      WebResponse webResponse = webRequest.GetResponse();
      if (webResponse == null)
      {
         return null;
      }
      StreamReader sr = 

         new StreamReader(webResponse.GetResponseStream());
      return sr.ReadToEnd().Trim();
      }
      catch (WebException ex)
      {
         return ex.ToString();
      }

}

We’re still only doing basic stuff like sending plain old SMS, and next time perhaps I’ll have a go at adding abilities to send wap/xml/binary messages.

There are no responses yet

Leave a Reply

*
RSS for Posts RSS for Comments