Sunday, February 17, 2013

Python Programming: Sending SMS using AT Commands

Introduction
 
In these project,  will be using Python 2.7 as our programming language. In my opinion, Python is the most elegant programming language (C is my second pick). Its syntax is so concise and readable that it's like writing a pseudo-code that actually runs on a machine. The first programming language that I've learned from school (during my freshmen year) is Java but I was lost because I felt like it's so verbose and complex. I was new to programming back then and OOP was way  out of my league. During the summer, I followed my older sister's advice to study C first before jumping into Java and I was not disappointed. It helps to first understand a procedural language before diving into OOP languages such as Java or C#. C is a good language but I felt like I would need to write dozen lines of code just to accomplish a simple task (like sending SMS). Then I researched about scripting languages that are easy to learn and scalable and Python was always popping out on the list. I was surprised on how easy it is to learn the language and perform so many tasks in only a few lines of code. It doesn't have a steep learning curve unlike Java or C++. Its syntax is so clear that it's like writing an imperative statement rather than programming a code.

AT Commands 
To communicate with the USB Modem, we'll be using AT Commands. Don't worry, it's easy to use these commands and only a few will be needed here. Here's a tutorial to help you.

Materials

USB Modem
For this project, I used my SmartBro broadband, but any USB broadband should work. I've also tested this on a Globe broadband and the results are just the same.



PC or Laptop
The PC/ laptop should have Python 2.7 installed and the PySerial library to enable serial communication.

Cellphone
To test the program, we'll send it to a recipient phone

Determining the COM Port number of the USB Modem

Go to device managers, find modems and you should see your usb modem there. Right click on properties



On the USB Modem Properties, click on the Modem tab, the Port here should be the same as the one written in the program


Here's a sample run



As always, the code is available in my Github page, feel free to build upon it and add new features to it.
I hope this article helped you. In the next post, I'll be combining this capability to my previous project, the Arduino-based Temperature Monitor, so that we'll be able to get the readings through SMS.

6 comments:

  1. Thanks for the nice article. This piece of code worked for me very well. I used Nokia 2690 USB modem #2 (mobile phone) on a Windows 7 machine.
    --
    Rahat

    ReplyDelete
  2. very interesting. I m a vb programmer. Know well about sms programming. But here i saw coding little bit easier..very impressing..
    I would like to know how to send sms in non-english languages..
    thanks in advance...

    ReplyDelete
  3. its not working to me im sending sms but there is no message received to the receipient

    ReplyDelete
  4. Good site! I really love how it is simple on my eyes and the data are well written. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which must do the trick! Have a great day! https://python.engineering/timefield-django-models/

    ReplyDelete