At work we have a little SMS gateway to send us a warning when a critical event is monitored by the server monitoring system. It’s a Windows XP machine with some old smsgateway software on it and a nokia 3310 connected with a data cable to the com port.
- A critical event is triggered on the monitoring server
- The monitoring server sends an e-mail to the administrators sms mailbox
- The SMS Gateway checks the sms mailboxes of every sms mailbox if there is a mail the smsgateway will send the e-mail as sms to the administrators mobile phone.
This system worked very well until a couple of months ago ….
The old software stopped to check the mailboxes and we had to manually restart the soft to get it working again for some hours when it stopped again. Not a good solution for an alert system.
So we needed a new system …
First of all the hardware. It’s time to replace that old nokia 3310 with a com dataconnection cable with something new preferably USB. For some mobile users we have some Vodafone USB Sticks. I checked it out and it is sms send capable. (For further reference the usb stick is a Huawei K3715)
NOw the Software: since we are living in a time of financial crisis and budget cuts I looked for a opensource solution and found one.
In fact I found multiple but the most common are kannel and SMS Server Tools.
Here is the info from the sites:
Kannel is a compact and very powerful open source WAP and SMS gateway, used widely across the globe both for serving trillions of short messages (SMS), WAP Push service indications and mobile internet connectivity. http://www.kannel.org/
The SMS Server Tools 3 is a SMS Gateway software which can send and receive short messages through GSM modems and mobile phones. http://smstools3.kekekasvi.com
I chose for the SMS Server Tools (or smstools) because for what I wanted to do SM Server Tools 3 seemed much simpler then kannel to set up. I think there are a lot more features and possibilities with Kannel but I didn’t want to get into a hard configuration for a simpel task.
Next I walk you through how I set the sms gateway up.
First of all we need a linux operating system. I chose for a Debian, smstools can run on every linux if you compile it.
I’m not going in to a default installation of debian.
Ok the system is installed let’s be sure that the system and the package list is up to date.
apt-get upgrade apt-get update
smstools itself is easily installed beceause the package is in the debian repository.
To install it just type:
apt-get install smstools
Now that smstools is installed we will need to configure it.
The configuration file for smstools can be found in /etc/smsd.conf
If the file is not here you need to start the sms Deamon
(the deamon will create a default configuration the first time it starts)
invoke-rc.d smstools start
Now that the file is there we need to find some more information about the stick.
Does the system recognize the stick, does it load the driver, where is the device connected to ?
To check it I started a tail on the messages system log file
tail -f /var/log/messages
It’s time to connect the USB stick to the computer and watch the messages:
[ 1755.609974] usb 1-2: new high speed USB device using ehci_hcd and address 3
[ 1756.154721] usb 1-2: New USB device found, idVendor=12d1, idProduct=1001
[ 1756.154724] usb 1-2: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[ 1756.154727] usb 1-2: Product: HUAWEI Mobile
[ 1756.154728] usb 1-2: Manufacturer: HUAWEI Technology
[ 1756.155753] usb 1-2: configuration #1 chosen from 1 choice
[ 1760.892745] Initializing USB Mass Storage driver…
[ 1760.894962] scsi6 : SCSI emulation for USB Mass Storage devices
[ 1760.896913] scsi7 : SCSI emulation for USB Mass Storage devices
[ 1760.897064] usbcore: registered new interface driver usb-storage
[ 1760.897066] USB Mass Storage support registered.
[ 1760.912696] usbcore: registered new interface driver usbserial
[ 1760.912767] USB Serial support registered for generic
[ 1760.912865] usbcore: registered new interface driver usbserial_generic
[ 1760.912866] usbserial: USB Serial Driver core
[ 1760.923068] USB Serial support registered for GSM modem (1-port)
[ 1760.923404] option 1-2:1.0: GSM modem (1-port) converter detected
[ 1760.923564] usb 1-2: GSM modem (1-port) converter now attached to ttyUSB0
[ 1760.923571] option 1-2:1.1: GSM modem (1-port) converter detected
[ 1760.923938] usb 1-2: GSM modem (1-port) converter now attached to ttyUSB1
[ 1760.924146] option 1-2:1.2: GSM modem (1-port) converter detected
[ 1760.924222] usb 1-2: GSM modem (1-port) converter now attached to ttyUSB2
[ 1760.924237] usbcore: registered new interface driver option
[ 1760.924238] option: v0.7.2:USB Driver for GSM modems
[ 1766.270295] scsi 6:0:0:0: CD-ROM HUAWEI Mass Storage 2.31 PQ: 0 ANSI: 2
[ 1766.271401] scsi 7:0:0:0: Direct-Access HUAWEI MMC Storage 2.31 PQ: 0 ANSI: 2
[ 1766.296211] sr1: scsi-1 drive
[ 1766.296366] sr 6:0:0:0: Attached scsi generic sg2 type 5
[ 1766.297135] sd 7:0:0:0: Attached scsi generic sg3 type 0
[ 1766.308267] sd 7:0:0:0: [sdb] Attached SCSI removable disk
As you can see my computer found a couple of devices for the usb stick and connected them.
The one’s I’m intresed in are the GSM modem’s. Those are connected to ttyUSB0, ttyUSB1 and ttyUSB2.
Another way to check that the device is connected is by using the command
This is a utility to get information about the USB buses in the system and the connected devices.
When I run it i see my Huawei stick popping up 🙂
Bus 001 Device 003: ID 12d1:1001 Huawei Technologies Co., Ltd. E169/E620/E800 HSDPA Modem
For more information on the ttyUSB devices you can run the following commands:
udevadm info -q all -n /dev/ttyUSB0 udevadm info -q all -n /dev/ttyUSB1 udevadm info -q all -n /dev/ttyUSB2
Why am I telling you this ? Beceause you might not be as lucky as me to get a working recognized stick.
So these commands will help you to find more information to troubleshoot.
Ok let’s go back to the configuration
Open it with a text editor (I’m using nano comes standard with debian and is easy to use)
There is a lot of information here and samples configuration I’m only going to show you what configuration I used. So if you have the same device as me you can copy and paste this.
# # /etc/smsd.conf # # Description: Main configuration file for the smsd # devices = GSM1 outgoing = /var/spool/sms/outgoing checked = /var/spool/sms/checked incoming = /var/spool/sms/incoming logfile = /var/log/smstools/smsd.log infofile = /var/run/smstools/smsd.working pidfile = /var/run/smstools/smsd.pid outgoing = /var/spool/sms/outgoing checked = /var/spool/sms/checked failed = /var/spool/sms/failed incoming = /var/spool/sms/incoming sent = /var/spool/sms/sent stats = /var/log/smstools/smsd_stats receive_before_send = no autosplit = 3 [GSM1] init = AT+CPMS="ME","ME","ME" device = /dev/ttyUSB1 incoming = yes pin = 1111 baudrate = 19200
You can find more information about the configuratio parameters on the SMS server toools site: http://smstools3.kekekasvi.com/index.php?p=configure
In the file I’m defining in wich directories my messages will come, wich log file needs to be used, that the messages needs to be split etc …
But I’ want to draw you’re attention to The [GSM1] section.
This is where we define wich devices needs to be used and the option.
First of all for the modem I’m using the Huawei we need an initialization command: AT+CPMS=”ME”,”ME”,”ME”
A thank you at the community for this info
The community can be found here: http://smstools3.kekekasvi.com/board.php
Then the device U see know why we needed that information
both /dev/ttyUSB0 and /dev/ttyUSB1 should work but I use /dev/ttyUSB1
Then I simply define my sims pin code and the baudrate to be used.
Save the configuration and restart the sms deamon
invoke-rc.d smstools restart
Check the log file for any errors (/var/log/smstools/smsd.log)
Time to test
Send a text message with you’re mobile phone to the number of the sim that you put in the USB stick.
The message should come in the incoming folder (/var/spool/sms/incoming) If not check the log file to troubleshoot.
Now let’s test sending a message.
Create a file in the /var/spool/sms/outgoing fodler (the name of the file doesn’t matter) and add the following content:
To: <number> This is a text message.
replace <number> with you’re mobile phone number
(ATTENTION: the number must be in the international format)
If you list the directory content of outgoing you will see (if everything goes as it should be) that the file disappears.
If the sms is sent the file will be moved to /var/spool/sms/sent otherwise it will be moved to the directory /var/spool/sms/failed.
If you are lucky you will get a textmessages on you’re mobile phone with the text “this is a text message”
Now you got a basic server that will send sms message from the commandline
In a next post I will show you how to setup “logging to an sql database” and how to send an sms from a incoming mail (mail2sms).