Go Down

Topic: Cannot Display Character Matched Message (Read 103 times) previous topic - next topic

smbakhtiar

Dear Concern,

I am using Sim900A for messaging . what it will do if i send message then there is defined value in a if condition when it matched it will be shown a message in serial monitor. Here is my code below.

void loop()
{


String buffer = readSIM900A();
String buf;
char charBuf[50];

    if (buffer.startsWith("\r\n+CMT: "))
    {
        Serial.println("*** RECEIVED SMS ***");
       
        // Remove first 51 characters
        buffer.remove(0, 51);
        int len = buffer.length();
        // Remove \r\n from tail
        buffer.remove(len - 2, 2);
       
        Serial.println(buffer);
            buf=buffer;
         
        buf.toCharArray(charBuf, 50) ;

        if (buf == "green")
        {
          Serial.println("Correct");
          }
       
        Serial.println("*** END SMS ***");
    }

    delay(100);

}

Where is my mistake . Please help me.

smbakhtiar

Here I  use

if(buf.indexOf("green") > 0)
 { ... }

for such comparasion. Because strings might contain \r\n or other characters. Exact match might be difficult to find.

My problem is solved.

Go Up