Skip to main content

Setting up a Kannel SMS centre on a Raspberry Pi with a K3565-Z modem

Our office (who wants me to mention how awesome they are) had a need for a means to send/receive automated sms messages relating to online banking. We decided to give a Raspberry Pi the job and so I have had the fun of setting it all up.

First off I installed Rasbian ( http://www.raspbian.org/ ) which is a Debian fork and is sufficiently easy to do following the guide on eLinux ( here ) which is linked to from the Raspberry Pi project website downloads page.

Next came a standard LAMP stack install.  I needed to have a web-server running because we will be running a management package on the box to track messages etc.

Next came Kannel.  I used the default package available from the Rasbian repositories so there was no need for fiddling.

My kannel.conf file was the next hurdle.  For the most part this is pretty easy to set up from the examples given on Kannel's site and elsewhere on the web.  I want to just mention the modem part, which was perhaps the most challenging part of this endeavour:

 #---------------------------------------------                
 ## GSM MODEM SMSC  
 ##---------------------------------------------   
 group = smsc  
 smsc = at  
 smsc-id = ztemodem-smsc-group  
 device = /dev/gsmmodem  
 log-level = 0  
 connect-allow-ip = "127.0.0.1; localhost; 192.168.3.*"  
 modemtype = auto  
 speed = 9600  
 my-number =   
 sms-center = +27831000113  
 #validityperiod = 167  
 alt-charset = "ASCII"  
 #---------------------------------------------                
 ## MODEM DEFINITION  
 ##---------------------------------------------   
 group = modems  
 id = vodafone  
 name = "vodafone"  
 detect-string = "ZTE INCORPORATED"  
 message-storage = sm  
 init-string = "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"  

Note that I've set an init string explicitly. This is because I was getting the "got +CMT but pdu_extract failed" error consistently when I sent a message. I obtained that init string by using wvdialconf, so if you have a modem other than the K3565-Z you might be able to use it to get your init string. Apparently it's not required for all modems though.

Ah, but I'm missing the best part... how do you actually get the modem to be a modem? The K3565-Z is a "zerocd" modem. When you plug it into a Windows box it mounts as a CD-ROM, installs drivers, which then flip it into being a modem.

To illustrate here is the output of lsusb on the Raspberry with the modem as it is on powerup:

 Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.  
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub  
 Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.  
 Bus 001 Device 004: ID 19d2:2000 ZTE WCDMA Technologies MSM MF627/MF628/MF628+/MF636+ HSDPA/HSUPA  

And here is the output after using usb_modeswitch -c /etc/usb_modeswitch.conf to flip it into a modem:

 Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.  
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub  
 Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.  
 Bus 001 Device 006: ID 19d2:0063 ZTE WCDMA Technologies MSM K3565-Z HSDPA  

Note that the device product has changed, as well as the description. I am not sure why but the stick was never mounted as a cdrom for me, so I could not eject it to flip its state. So I had to use usb_modeswitch to do it.

 sudo usb_modeswitch -c /etc/usb_modeswitch.conf  

I found the correct settings for this on a forum (here ) which also gives some useful information on how to accomplish the flip. You need to append the following snippet to your /etc/usb_modeswitch.conf file.

 #######################################################  
 # ZTE-K3565 , VODAFONE BITE GSM  
 # Gediminas Simanskis  
 # www.edevices.lt  
 DefaultVendor= 0x19D2  
 DefaultProduct= 0x2000  
 TargetVendor= 0x19D2  
 TargetProduct= 0x0052  
 MessageEndpoint=0x01  
 MessageContent="5553424308E0CC852400000080000C85000000240000000000000000000000"  

You will need to experiment on finding the best way to execute the flipping, but this is really the only complication in the setup.

Comments

  1. im also trying to install sms gw on a Raspberry Pi . I have used 2014-01-07-wheezy-raspbian. but my compilation failed as bellow, could you pls guide me to achieve this.

    gcc -std=gnu99 -D_REENTRANT=1 -I. -Igw -g -O2 -D_XOPEN_SOURCE=600
    -D_BSD_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES= -I/usr/include/libxml2
    -I/usr/include/mysql -o gwlib/log.o -c gwlib/log.c
    gwlib/log.c: In function ?kannel_syslog?:
    gwlib/log.c:434:11: error: invalid operands to binary == (have ?va_list?
    and ?void *?)
    make: *** [gwlib/log.o] Error 1
    root@sms-box:/home/pi/gw/gateway-1.4.3#

    ReplyDelete
  2. Have you tried using the default Kannel package from the repositories? I see there are some (old) bugs to do with building Kannel on ARM

    ReplyDelete

Post a Comment

Popular posts from this blog

Separating business logic from persistence layer in Laravel

There are several reasons to separate business logic from your persistence layer.  Perhaps the biggest advantage is that the parts of your application which are unique are not coupled to how data are persisted.  This makes the code easier to port and maintain. I'm going to use Doctrine to replace the Eloquent ORM in Laravel.  A thorough comparison of the patterns is available  here . By using Doctrine I am also hoping to mitigate the risk of a major version upgrade on the underlying framework.  It can be expected for the ORM to change between major versions of a framework and upgrading to a new release can be quite costly. Another advantage to this approach is to limit the access that objects have to the database.  Unless a developer is aware of the business rules in place on an Eloquent model there is a chance they will mistakenly ignore them by calling the ActiveRecord save method directly. I'm not implementing the repository pattern in all its glory in this demo.  

Fixing puppet "Exiting; no certificate found and waitforcert is disabled" error

While debugging and setting up Puppet I am still running the agent and master from CLI in --no-daemonize mode.  I kept getting an error on my agent - ""Exiting; no certificate found and waitforcert is disabled". The fix was quite simple and a little embarrassing.  Firstly I forgot to run my puppet master with root privileges which meant that it was unable to write incoming certificate requests to disk.  That's the embarrassing part and after I looked at my shell prompt and noticed this issue fixing it was quite simple. Firstly I got the puppet ssl path by running the command   puppet agent --configprint ssldir Then I removed that directory so that my agent no longer had any certificates or requests. On my master side I cleaned the old certificate by running  puppet cert clean --all  (this would remove all my agent certificates but for now I have just the one so its quicker than tagging it). I started my agent up with the command  puppet agent --test   whi

Redirecting non-www urls to www and http to https in Nginx web server

Image: Pixabay Although I'm currently playing with Elixir and its HTTP servers like Cowboy at the moment Nginx is still my go-to server for production PHP. If you haven't already swapped your web-server from Apache then you really should consider installing Nginx on a test server and running some stress tests on it.  I wrote about stress testing in my book on scaling PHP . Redirecting non-www traffic to www in nginx is best accomplished by using the "return" verb.  You could use a rewrite but the Nginx manual suggests that a return is better in the section on " Taxing Rewrites ". Server blocks are cheap in Nginx and I find it's simplest to have two redirects for the person who arrives on the non-secure non-canonical form of my link.  I wouldn't expect many people to reach this link because obviously every link that I create will be properly formatted so being redirected twice will only affect a small minority of people. Anyway, here's