views:

421

answers:

3

I have a GSM modem connected to my computer, i want to receive text messages sent to it using a python program i have written, am just wondering what is the best technique to poll for data.

Should i write a program that has a infinite loop that continuously checks for incoming sms's i.e within the loop the program sends the AT commands and reads the input data. or do modems have a way of signaling an application of an incoming data(sms).

Am trying to imagine a cellphone is just a GSM modem, and when an sms is received, the phone alerts you of the event, or does the phone software have an infinite loop that polls for incoming data.

+2  A: 

I have written something similar before. There is a way using AT commands to tell the modem to signal you each time an SMS is received.

For reference, I was using a Maestro 100 GSM Modem in an embedded application.

First you have to initialize the modem properly. I was using text mode for the SMS, but you might be using something different. Pick from these what you want. AT+CNMI is the most important.

AT&F0 # Restore factory defaults
ATE0  # Disable command echo
AT+CMGF=1 # Set message format to text mode
AT+CNMI=1,1,0,1,0 # Set new message indicator
AT+CPMS="SM","SM","SM" # Set preferred message storage to SIM

You would then wait for a message notification, that will look like this. (Don't match on the index number, that might differ between notifications)

+CMTI: "SM",0 # Message notification with index

When you get that notification, retrieve the unread SMS's:

AT+CMGL="REC UNREAD"  # Retrieve unread messages

I would recommend you also add a poll, maybe every 5 minutes or so, just in case you miss a notification. With serial comms you can never be sure!

Andre Miller
Thanks, can't wait.
gath
Ok, edited. Hope this helps. I used those commands in an embedded application with an external GSM modem.
Andre Miller
Great, let me try it out.
gath
Andre, this never worked for me, i wonder if its my modem or what, i resulted in polling the modem for the messages... any ideas.
gath
Perhaps your modem uses a different AT command to enable the notification. Do you have a link to a reference manual for it?
Andre Miller
A: 

I find I can't remember much of the AT command set related to SMS. Andre Miller's answer seems to ring a few bells. Anyway you should read the documentation very carefully, I'm sure there were a few gotchas.

My recommentation for polling is at least every 5 seconds - this is just for robustness and responsiveness in the face of disconnection.

I used a state machine to navigate between initialisation, reading and deleting messages.

quamrana
A: 

Hi Andre,

Your solution seems to be good. I am working on Telit GM-862 GPS modem and its reference documents tells me to use same AT commands which you told. But I am intending to do more on this. I am writing an Python script to toggle an General Purpose I/O pin (GPIO) with an incoming SMS i.e when an SMS comes into the modem, the GPIO pin should set to '1' (if its initial state was '0') and with another SMS it should again toggle back to '0'

I would really appreciate if someone could guide me on this.

Thanks

Rahul Tripathi