I know how to send AT command to read SMS but my problem is in getting Modem responces in to a variable.
First of all you have to connect your phone to your PC using HYPER TERMINAL and with the proper AT command obtain the complete string of one sms.
Once the sms is on the screen you have to identify a starter (a number of characters at the begining of the string that never changes) very likely your phone will begin the string with the word "UNREAD", if this is case you can use this as a starter. You have also to identify the portions of the string that you need, count the character position (commencing from the last character of the starter) and the number of characters you will need. (For instance you will need the phone number of the sender and some part of the message. So count how many characters you have to skip from the end of the starter and the begining of the phone number, and from the end of the phone number to the begining of your text. Remember that space is one character)
Once you have these informations, you will know the dimension of your byte arrays to contain the portion of string that you have selected and two numbers "n1" and "n2" which are the characters to skip to reach the portion of string that interest you.
Code:
ArrayNum Var BYTE [15] ' here I assume the the phone number of the sender is 15 characters long. if shorter or longer adjust the array
ArrayTxt Var BYTE [50] ' here I assume that the sms text that interest you is 50 characters long. If your requirement is longer or shorter adjust the array
Now, to fill your array, you send the AT command for reading your sms, and immediatly afterwards
Code:
HSEROUT ["AT^SMGR=1",13]
HSERIN 2000, NoSms,[WAIT("UNREAD"), Skip n1, Str ArrayNum\15, Skip n2,str ArrayTxt\50]
If no sms are present, hserin will timeout to the label NoSms after 2 seconds, so include this label in your code.
If the program doesn't jump to label NoSms then ArryNum will contain the phone number of the sender and ArrayTxt will contain the message.
You can check ArrayNum and see if the answer can be sent or not. A simpler way to avoid to answer to the wrong message is to include a password within the text you send and check only the text. (In this case you don't need ArrayNum)
If you need more help, you better tell me what you want to do.
Al.
Bookmarks