In my previews post we have learned to link our mobile phone which serves as our GSM modem and used AT commands in the Hyper Terminal to send our SMS. This post will discuss the second function which is to receive SMS using AT commands. The GSM modem can be configured to receive SMS in different ways. It can be Immediate or through a Notification. I will be discussing to you these two modes shortly.
2. Receiving SMS
Immediate - The details of the SMS received from the GSM modem is immediately sent to the computer.
AT+CMGF=1
-formatSMS message as text
AT+CNMI=1,2,0,0,0
-sets the mode of the GSM modem to immediately respond when the SMS is received.
-this command should return something like:
Hello World!
-the mode we have set will continuously monitor the COM port for messages received from the GSM modem and immediately send it to the computer.
Notification - A notification is sent to the computer indicating that the GSM modem received an SMS message. The notification contains the memory location of the message which is accessed using an AT command to be displayed in the computer.
AT+CMGF=1
-formatSMS message as text
AT+CNMI=1,1,0,0,0
-sets the mode of the GSM modem to notify the computer that an SMS is received.
-this command should return something like (SIM Memory):
+CMTI: "SM",3
-the notification means that a message is received and stored in location 3 in SIM memory.
-or something like (Memory Card):
+CMTI: "ME",64
-the notification means that a message is received and stored in location 64 in extended memory.
AT+CMGR=3 <Enter>
-the command to read the received SMS from the GSM modem.
-details of the SMS from memory location 3 is then sent to the computer.
-details of the SMS from memory location 3 is then sent to the computer.
-this command should return something like: |
+CMT : "+63xxxxxxxxxx" , , "06/26/11,23:20:00+40"
Hello World!
That shows you how to receive and read the SMS from your GSM modem. After we receive the message its just right to delete the message from our phone memory or memory card. We don't want our mobile phone to be flooded with SMS right?
AT+CPMS=
AT+CMGD=3 <Enter>
-this AT command delete the SMS received stored in location 3 of the GSM modem.
-this command should return "OK" if the message is deleted successfully or an error if the specified memory location is empty.
Great job! We've just learned using AT commands in sending and receiving SMS message from our computer. If you were not able to get it then post a comment and we will discuss your problem. The next post is about getting the codes doing the job for you. Using the AT command you have now the idea on how to integrate it to your application. You can now use a higher level of programming to execute the commands. Try it out for your self. It is free and would not cost you that much of purchasing an SMS gateway software. Watch out for the next post. I'll be using VB.NET window forms to create a sample SMS application.