SMS Notification using Gammu on Linux

.send-sms-using-linux So I got a call from the big boss, a client needs an SMS notification service. I said I will be needing a GSM Modem, a loaded SIM Card and a Linux Server. I was given the task and the equipment and now I will share how I set up the project up and working :).

I did this in Ubuntu on a PC and not a virtual machine. It's not that this is the only solution, but this one worked for me and I hope it will work for you too. SMS Gateway using Windows 7 is also possible. 

Please note that when I started this research, I had no specific help what-so-ever and I was completely new to GAMMU and the SMS Service stuff. Please bear with the primitive approach. :)

 

Getting Started:

What I had on my desk
  • Ubuntu 12.X
  • Huawei E560 USB GSM Modem with SIM card prepaid/postpaid with credit balance
Any GSM modem will do, actually.
 Update:
  • This will work great on a linux Raspberry Pi. For it it is low cost on electricity so it can run 24/7. The possibilities are endless. Be creative.

What is GAMMU?

 "Gammu is the name of the project as well as name of command line utility, which you can use to control your phone. It is written in C and built on top of libGammu." - Wammu website
 
They update their stuff regularly. The tool is so versatile and also open source.

Kudos to the guys behind Gammu.



Anyway...

INSTALL GAMMU:

Run these commands using Shell:
  • sudo apt-get install gammu 
  • sudo apt-get install gammu-smsd

 STARTING THE SMS GATEWAY

After installing GAMMU:
  1. Plugin the GSM Modem.
  2. Open Terminal
  3. Type "lsusb" to make sure that it is detected. You should see the model/manufacturer of the GSM Modem on the terminal.
  4. Type "gammu-detect" and take note of the ttyUSB where the GSM Modem is connected.
  5. Type "gammu-config"
  6. Set the port to the /dev/ttyUSB number that you saw then Save. (I use “at19200” in connection too)
  7. Type "sudo gammu --identify" you should see the device's information.
  8. Type "vi /etc/gammu-smsdrc" and change port to the /dev/ttyUSB number from earlier.
  9. Create the files or folders for the inbox, outbox, sent, error, and log file.
  10. Type "sudo gammu-smsd -c /etc/gammu-smsdrc". This starts the background SMS Daemon.
Now, the gammu SMSD is listening. I leave the terminal window open after this. Just to make sure that the gammu-smsd is always running.

SAMPLE WORKING GAMMU-SMSDRC


[gammu]
port = /dev/ttyUSB1
connection = at19200
 
[smsd]
service = files
debuglevel = 1
inboxpath = /var/www/sms/gammu/inbox/
outboxpath = /var/www/sms/gammu/outbox/
sentsmspath = /var/www/sms/gammu/sent/
errorsmspath = /var/www/sms/gammu/error/
logfile = /var/www/sms/gammu/log/pansitlog.log
commtimeout = 10
sendtimeout = 20
deliveryreport = log
phoneid = mdsms
inboxformat = standard
transmitformat = auto

TESTING THE SMS FUNCTION

Now that we are done with the base requirements, it's time for a break. Send yourself a message!
  1. Open a new terminal window.
  2. Type "echo "Hey there sexy." | sudo gammu --sendsms TEXT [putnumberhere]"
  3. Sample: "echo "Hey there sexy." | sudo gammu --sendsms TEXT 1234567890"
  4. You should see something like this in the terminal:
    If you want break, press Ctrl+C...
    Sending SMS 1/1....waiting for network answer
    
  5. If you experience “error 500, message reference=-1 Unknown Error” most likely the SIM has no balance or has no signal.
There it is, I had an SMSD listener that waits my command. Today, this listener has been integrated to a PHP based website and very recyclable.

Comments

Unknown said…
Do you have idea how to integrate it to website hosted on vps and the rasp pi is on-premise(inside a company)?. Great article by the way
Loch said…
This is an overly outdated reply, but for the people seeking the same answer:

If your company can obtain a static IP from your ISP, then there is a smooth solution. Make an API in your Raspi and let your website send a request to your static IP (where your gsm is connected), then let raspi send the SMS.

If you have no static IP, you can create an API in your website that shows the sms data needed by your sms system, then you can program your raspi to poll the API every minute. Then use the call back of gammu to send a request to your API again saying that all sms were sent, and that api will then refresh the data in your vps.

Hope this still helps somebody someday. :D

Popular posts from this blog

Terraform: Merge a List ofObjects into One