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 ...

Using Azure Active directory as an OAuth2 provider for Django

Azure Active Directory is a great product and is invaluable in the enterprise space. In this article we'll be setting it up to provide tokens for the OAuth2 client credentials grant. This authorization flow is useful when you want to authorize server-to-server communication that might not be on behalf of a user. This diagram, by Microsoft, shows the client credentials grant flow. From Microsoft documentation  The flow goes like this: The client sends a request to Azure AD for a token Azure AD verifies the attached authentication information and issues an access token The client calls the API with the access token. The API server is able to verify the validity of the token and therefore the identity of the client. The API responds to the client Setting up Azure AD as an OAuth2 identity provider The first step is to create applications in your AD for both your API server and the client. You can find step-by-step instructions on how to register the applications o...

"Word of the Day" PHP script (with word list)

I was looking around for a way to generate a word of the day on the web and didn't find anything. So I coded a quick and dirty script to do it. Just in case anybody does a Google search and manages to find my blog: here is my Word of the Day PHP script : Copy this code snippet into a wordoftheday.php file: $file = fopen("interesting_words.txt","r"); $raw_string = fread($file,filesize("interesting_words.txt")); fclose($file); $words_array = explode("|",$raw_string); echo $words_array[array_rand($words_array)]; Of course the real issue I had was finding a list of interesting words in the right format. Here is the list of interesting words that I used: Copy this into a file called interesting_words.txt : ubiquitous : being or seeming to be everywhere at the same time; omnipresent| ecdysiast : a striptease artist| eleemosynary : of, relating to, or dependent on charity| gregious : c...