Remote output_communication between sim900-->mega

Hi, im working on my project. I need remote relay(leds) using sim900 and arduino mega. I tried Seriel.find() but when i send sms i can turn on relay(led) but turn off is problem. Sometimes i turn off it but not always.
My question is: How can I evaluate sms message for correct work?

Well,for a start you code post your code.

How can I evaluate sms message for correct work?

How are you storing the message, so that you CAN evaluate it?

#define SIM900 Serial1

void setup() {
pinMode(50,OUTPUT);
Serial.begin(19200); // PC
SIM900.begin(19200); // SIM900

Serial1.println("AT+IPR=19200");
delay(1000);
Serial1.println("AT+CMGF=1");
delay(1000);
Serial1.println("AT+CNMI=2,2,0,0,0");
delay(1000);

}

void loop() {
while(SIM900.available())
{
if(SIM900.find("LED_ON"))
{
digitalWrite(50,HIGH);
}
if(SIM900.find("LED_OFF"))
{
digitalWrite(50,LOW);
}
}
}

find consumes what it reads, doesn't it?
If you don't find "ON", you can never find "OFF".

Re-read what PaulS write, and see if that offers any inspiration.

Do you know how find() works?

Suppose that the device receives a text message containing "Turn the LED_OFF".

The while loop executes, because there is data to read. The first if statement is evaluated, which causes find() to be called.

It reads, and discards data until it finds the first letter in the argument. The 'T' is not an 'L', so it is discarded, and the buffer contains "urn the LED_OFF". Similarly, the 'u', 'r', 'n', etc. are discarded, until the 'L' IS found. Then, the buffer contains "ED_OFF". Now, find is looking for the next letter to be 'E'. It reads the next letter, which is an 'E', so now it expects the next letter to be 'D'. It reads the next letter, which is an 'D', so now it expects the next letter to be '_'. It is, so the process is repeated, for 'O' and 'N'. After the 'O' is found, find() is looking for the next character to be an 'N'. The buffer still contains "FF". The 'F' is read, and is not an 'N'. So, find() starts over looking for "LED_ON" in the buffer, which now contains "F".

After it reads the 'F', the buffer is empty, and is not 'L'. So, find() hangs around waiting for more data, until it gets bored and returns.

find() didn't find what it was looking for, so the if evaluates to false, and the body is skipped. The next statement is another if statement, with another call to find().

That call finds that there is no data in the buffer, so it hangs around waiting for more data, until it gets bored and returns.

find() didn't find what it was looking for, so the if evaluates to false, and the body is skipped.

So, even though you were sent a text message that contains an expected string, that should cause some action, the action is not performed.

You can NOT use that crutch. I mean the find() method.

You MUST read all the data, store it, and THEN see if the stored data contains "LED_ON" or "LED_OFF". How you do that depends on how you store the data.

Strings are NOT recommended. NULL terminated char arrays and string functions, like strstr() ARE.

will it work? i mean compering two strings.

#define SIM900 Serial1

void setup() {
Serial.begin(19200);
SIM900.begin(19200);
SIM900.println("AT+IPR=19200");
delay(1000);
SIM900.println("AT+CMGF=1");
delay(1000);
SIM900.println("AT+CNMI=2,2,0,0,0");
delay(1000);
}
String readSIM900()
{
String buffer;

while(SIM900.available())
{
char c = SIM900.read();
buffer.concat(c);
delay(10);
}
return buffer;
}

void loop() {
String buffer = readSIM900();

if(buffer.startsWith("\r\n+CMT: "))
{
Serial.println("*** RECAIVED A SMS ***");
buffer.remove(0,51);
int len = buffer.length();

buffer.remove(len - 2,2);

Serial.println(buffer);
Serial.println("*** END SMS ***");
}
delay(100);
if(buffer=="LED1_ON")
{
digitalWrite(49,LOW);
}

if(buffer=="LED1_OFF")
{
digitalWrite(49,HIGH);
}

}

will it work?

The code will do something. You need to tell us what it does. If what it does is not what you want, you need to tell us how what it does is different from what you expect.

i have problem with compering sms and my text for correct turn off or on led (last part of code).
I mean, there are some errors.

I mean, there are some errors

If you want more than just sympathy, you're going to have to tell us more than that

Ok, so I want do something like smarthome but lights and outlets will be controll using arduino mega and sim900 during sms. I posted my code higher. When a send message to arduino(sim900) nothing happens. I want compare text from sms with my text and when is requirement correct led will shine .

No, I meant that you need to tell us what the problems are, and show us the errors.

When a send message to arduino(sim900) nothing happens.

Nonsense. Something happens. At least it does if you are sending the correct AT commands to the device. FORGET ABOUT USING THE CONTENTS OF THE TEXT MESSAGE FOR NOW.

Do NOTHING more than print the contents of the text messages as they are received. If you are not getting text messages, no amount of code to read, store, parse, and act on the contents of the text message will be worth a dang thing.

I print my message only for my info. You can see in my code, that i compare buffer with text and after comparing program turn on led.
Sorry when i don understood your post but my english is poor.

What i must do for correct functionality?

What did you change from the original?

You must delete the text message after you read it.

Delete message from sim900? For example :

if(buffer=="LED1_ON")
{
digitalWrite(49,LOW);
SIM900.println("AT+CMGD=1,4");
delay(500);
}

if(buffer=="LED1_OFF")
{
digitalWrite(49,HIGH);
SIM900.println("AT+CMGD=1,4"); //delete message from SIM900
delay(500);
}

I take from code something like this

*** RECEIVED SMS ***
Hello there, this is test message.
*** END SMS ***
*** RECEIVED SMS ***
Hello there, this is another test message.
*** END SMS ***

Only text Hello there,... is in variation buffer
I compare buffer with my text and no results.
Sorry if i have stupids report.