Parsing SMS

I need to figure out a way to parse incoming SMS messages with the Arduino. Nothing elaborate, just look through the message for a word. I have looked at sketches for parsing GPS data, but I am having trouble making heads or tails of the commands.

Thanks in advance.

I have been able to reliably send and receive data from the phone using AT commands, so that part is covered. My question is when the Arduino receives this:

+CMGR: "REC READ","+85291234567",,"07/04/20,10:08:02+32",145,4,0,0,"+85290000000",145,49
It is easy to read text messages via AT commands.

How do I parse this to make the Arduino read the "It is easy to read text messages via AT commands." part. (This is the body of the SMS message) Any good tutorials to recommend? I am trying to remotely monitor my beehives.

Cheers!

You need to know what the format of the messages is, from your example it seems like there's maybe a fixed number of comma-separated fields and then the message?

If so, you can possibly scan through the message, counting commas and when you have enough commas, then start reading the message after the space.

But without know how consistent the format is it's hard to give you specifics.

--Phil.

Thanks for the reply. I know vague questions are hard to answer, sorry about that. I guess I am having trouble with syntax of:

(sorry if I am using incorrect terms, please feel free to correct me)

  1. making sure the Arduino reads the incoming data
  2. making a buffer, or a variable to hold this data
    3)making the Arduino read the buffered data
    a)How to define "delimiters"; commas, periods, etc.
    b)how to make sure the Arduino reads "three commas in" or whatever
    4)How to reset the buffer for the next message.

Sorry to ask so much; I am really looking for a tutorial on the subject, something that defines the terms and demonstrates correct usage. Thanks in advance. I appreciate it.

In a SMS message there are seven commas before you hit the body of the message (i.e. what was typed). More importantly, there is a carriage return right before the message.

Thanks!

You won't be able to go strictly based on the carriage return as there are often a couple carriage returns in an AT reply but you could count the correct number of commas (I count 11) and then check for the carriage return. Actually what I do when parsing a reply from a GM862, is to first parse what type of message it is to make sure I'm not looking for SMS data in a network status message, etc.

In my program, when the Arduino (Sanguino or Mega in my case) has received incoming serial data, I read that data into a char array. Then I use two nested for loops to check for a specific series of characters , +CMGR:, to determine what kind of message I got from the GM862. I believe there is a library for doing this but I wrote my own code. If the received serial data is the correct message, then I proceed to run another for type loop to check for the correct number of commas. After counting the 11th comma continue to the character after the carriage return and start copying into a new char array or start comparing to a list of expected characters.

I've left out a lot of the gritty details but that's the general idea.

Thanks again!

Beekeeper - "I have been able to reliably send and receive data from the phone using AT commands, so that part is covered. "

How?!?!?!???

I'm just trying to list the SMSs on my motorola C168i using this code:

#include <NewSoftSerial.h>

NewSoftSerial phone(10, 11);

void setup()
{
Serial.begin(9600);
Serial.println("Goodnight moon!");

// set the data rate for the NewSoftSerial port
phone.begin(4800);
phone.println("AT+++");
delay(500);
phone.println("AT+CMGF=1\r\n");
//phone.println(1);
delay(500);
phone.println("AT+CMGL=ALL\r\n");
//phone.println(1);
delay(500);
for (int i = 0; i < 500; i++) {
// Serial.println("Loop"); // debug
if (phone.available() > 0) {
// Serial.println("If"); //debug
char c = phone.read();
Serial.print(c);
}
}
Serial.println("End"); // debug
}

void loop() // run over and over again
{
}

But this is all I get:

Goodnight moon!
AT+++

ERROR
AT+CMGF=1

OK
AT+CMGL=ALL

ERROR
End

Any ideas on why I'm getting an ERROR?

Thanks so much!