SMS with GSM Modem

Last time I wrote about sending SMS using online tools. The main problem there remains 2 way communication. Luckily, there's a simple solution to receiving problem. Since the start of 3Gmobile internet, GSM modems became quite ubiqitous and reasonably cheap. Just like the SMS software. I used Smstools that proved to be a snap to install and use.
wget http://smstools3.kekekasvi.com/packages/smstools3-3.1.3.tar.gz
tar -xzf smstools3-3.1.3.tar.gz
cd smstools3
sudo ./install.sh
I am using Huawei Mobile Modem E270 and E170 from Starhub. The only change I had to make now is update the config file. Here's my config file /etc/smstools.conf
devices = GSM1
logfile = /var/log/smsd.log
loglevel = 7

[GSM1]
device = /dev/tty.HUAWEIMobile-Modem
incoming = yes
#pin = 1111
init = AT+CNMI=2,0,0,2,1
After that just start/restart the smsd daemon
sudo killall smsd; sudo smsd;
Sending of SMS is now as simple as
sudo sendsms +6584199983 'Your SMS message....'
or just put SMS File to /var/spool/sms/outgoing/
To: 491721234567

Hello, this is the sms.
More info about the structure of the file is here.
As for receiving, all the received messages will be downloaded to /var/spool/sms/incoming/ so all you have to do is create a cronjob to check this folder for new messages and then forward the message to your application.

SMS Integration Without Hardware

When I tried to integrate one of our applications with SMS messages (both incoming and outgoing) several years ago we didn't manage to find not even one SMS gateway provider that would be able to pass our simple criteria. Allow sending (da :-) and receiving of messages with some reasonable notification of received messages (simple webservice / forward to email, anything). The replies should preferably be handled by a local number and sending/forwarding should be within reasonable price range :-) Is it too much to ask?

There is a number of online portals for sending (some support also receiving) SMSes like Clickatel, SMSZilla, SMSCountry. Their pricing per message varies from SGD0.05 - 0.1 which is quite reasonable and some provide nice and easy API for sending (when you think about it how complicated can it get to write a form handler with 3 or 4 fields) - some ask you to pay for API extra. For better or worse they would accomplish the sending but the receiving was either very painful or expensive or both. On top of that sending a hundred messages to and Indian or US number shows on your bill so we had to find something better.

For systems that require only sending we mostly used Singtel Ideas or Starhub Gee. Both are just a little short of and actual webservice, nevertheless worked quite well. Here's an example how to send message using StarHub Gee (12345678 is your phone number)

require 'rubygems'
require 'mechanize'

mech = WWW::Mechanize.new
page = mech.get('http://groupsms.starhubgee.com.sg/VCRLS/login.cgi?cb=http%3A%2F%2Fgroupsms.starhubgee.com.sg%2Fcgi-bin%2Fs.pl')

#login first
form = page.form('loginform')
form.action = "https://login.starhubgee.com.sg/eam/login"
form['cb'] = 'http://groupsms.starhubgee.com.sg/cgi-bin/s.pl'
form['vcid'] = 'groupsms'
form['pudn'] = 'starhubgee'
form['domain'] = 'starhubgee'

form['fake_uid'] = '12345678'
form['uid'] = '12345678@starhubgee'
form['password'] = 'password'

page = mech.submit(form)  

page = mech.get("http://groupsms.starhubgee.com.sg/cgi-bin/s.pl")
form = page.form('compose')
form['to']='comma separated recipients numbers'

form['message']= "Your message...."

page = mech.submit(form)

This would take care of sending with much lower cost as it utilizes bundled SMSes in the package (400 - 1000 messages) with nothing else required. The problem, however, was still receiving. A little glimpse of hope was SMS+ introduced by SingTel last year, which allows you to auto forward your received messages to email address. This would have been ideal - if not for a small glitch - it only works with messages sent from SingTel numbers. OH MY GOOOOOD!!!!!!!! I almost cried when I found out that.

Lately I found a nice and simple Singaporean provider www.gsmexchange.com able to handle 2 way communication. Nothing to say about sending - just send a http request with username, password, phone numbers and message and you will receive message ID that you can use for tracking. Replies are slightly more complicated as I didn't find any API for reading replies - nevertheless - there is a list page that you can parse with mechanize to get the responses. There is an option to forward messages to email but for 5c per message it's a bit too expensive. Actually, also pricing for sending of the messages is on the higher end 10c per message which makes it much less attractive for our customers.

Luckily I managed to find a much cheaper solution - running my own SMS server :-) See the next post...