Need help about receiving a SMS from SIM900 module and doing something with it

Hello everyone,
I'm currently working on a weather station project, precisely on the communication part.
It means that i'm working with a SIM900 module to send alert SMS and GPS coordinates if the user send a SMS with a sort of password (like in ads : send LOVE to 66900).
And it's for the gps coordinates part that i ask help here, for the moment this is what i did

//Num module : +33768265074 // ! // Maxime : +33786284633 // ! // 44.7260358,5.021091 //
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7,8);    // RX, TX
char mdp[] = "Test"; // we compare this to the content of incoming SMS
boolean sms;

void setup()
{      
  SIM900.begin(9600); // Init module (SIM900)
  Serial.begin(9600); // Init serial communication
  delay(500);
  Serial.println("Waiting for SMS");
  sms = true; 
}

void loop()
{ 
  if(sms == true)
  {
    receivesms();
    sms = false;
  }
    if(SIM900.available()) 
    {
      Serial.write(SIM900.read()); // Write in the serial monitor the messages 
    }
    /*
      if(SIM900.read() == mdp) // So this is this if that makes trouble, this line should be supposed to check if the user entered the right "password" 
      {
        Serial.println("ok"); // A little confirmation
      }
      */
     
}

void receivesms()
{
  SIM900.println("AT+CMGF=1\r");   // SMS mode
  SIM900.println("AT+CMGL=\"ALL\"\r"); // Display all messages
  delay(1000);
}

And here's a screen of what it does :

Simple it just displays in the serial monitor the incoming messages.

In this first program you can see that i commented the "if(SIM900.read() == mdp) and what's in inside too"; because this is what makes me an error, and if i uncomment like this :

//Num module : nothing // ! // Maxime : +youwillnothavehisnumber:p // ! // 44.7260358,5.021091 //
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7,8);    // RX, TX
char mdp[] = "Test"; // we compare this to the content of incoming SMS
boolean sms;

void setup()
{      
  SIM900.begin(9600); // Init module (SIM900)
  Serial.begin(9600); // Init serial communication
  delay(500);
  Serial.println("Waiting for SMS");
  sms = true; 
}

void loop()
{ 
  if(sms == true)
  {
    receivesms();
    sms = false;
  }
    if(SIM900.available()) 
    {
      Serial.write(SIM900.read()); // Write in the serial monitor the messages 
    }
    
      if(SIM900.read() == mdp) // So this is this if that makes trouble, this line should be supposed to check if the user entered the right "password" 
      {
        Serial.println("ok"); // A little confirmation
      }
      
     
}

void receivesms()
{
  SIM900.println("AT+CMGF=1\r");   // SMS mode
  SIM900.println("AT+CMGL=\"ALL\"\r"); // Display all messages
  delay(1000);
}


It is like there is a transmission problem because it displays weird caracters ( baud rate is ok though).
I don't know if it comes from the "mdp" variable or the "SIM900.read()".

So I think I described well my problem, feel free to ask things it can only be helpful :slight_smile:

Link for gsm module if you are interested : GPRS Shield V1.0 | Seeed Studio Wiki (i haven't been paid by the brand for this link)

In this first program you can see that i commented the "if(SIM900.read() == mdp) and what's in inside too"; because this is what makes me an error, and if i uncomment like this

SIM900.read() returns ONE character. One character will never equal a string.

Do you understand what read() does with respect to the incoming serial buffer?

You need to look at Robin2's tutorial on serial data processing.
http://forum.arduino.cc/index.php?topic=396450.0
Your code should have EXACTLY one call to SIM900.read() in it, NOT two like it has now.

Thanks i'll read the guide. But is there a way to modify

Serial.write(SIM900.read());

To manage that there's only one call of SIM900.read() like you said.

But is there a way to modify ... To manage that there's only one call of SIM900.read() like you said.

  char c = SIM900.read();

  Serial.print(c);

  if(c == 'b')

One read; two uses of the same character.

Simple but it had to be thought