Can't do several actions when receive sms on gsm module

Hello I am trying to make a tracking device using a7 gsm gps gprs module and arduino uno R3.
I want my device to send me sms when it receives sms with the word “Location” but I can’t make this happen…
When i use serial monitor and communicate through AT command I see the new messages and i attached a photo of the serial monitor.

my code is this. Focus in the RecvMsg function as all the rest works fine.
(I had to remove the displayInfo function because the post was too long).

/*Project: Ai Thinker A7 GSM GPRS GPS module
The module GND pin is connected to Arduino GND pin
The module U_RXD pin is connected to Arduino pin 9
The module U_TXD pin is connected to Arduino pin 8
The module VCC pin is connected to Arduino 5V pin*/
//*************************************************************
#include <TinyGPS++.h>//include the library code
//#include <SoftwareSerial.h>//include the library code
#include <AltSoftSerial.h>
#include <GSM.h>// include the GSM library
//*************************************************************
void SendMsg();
void RecvMsg();
void displayInfo();
//*************************************************************
#define PINNUMBER ""// PIN Number for the SIM
TinyGPSPlus gps;// The TinyGPS++ object
GSM gsmAccess;// initialize the library instances
GSM_SMS sms;
//SoftwareSerial ss(3, 4);// The serial connection to the GPS device
AltSoftSerial ss;// The serial connection to the GPS device
int i,sec,min,hour,day,month,year;
float lat,lng,latplus,lngplus,latminus,lngminus;
char PhoneNumber[20]="+3069******";
boolean notConnected = true;
boolean waitingSMS = true;
char c;
String yourPassword = "Location"; // Put the password here between the ""
String password; // Temporary variable used for comparison of passwords
//*************************************************************
void setup()
{ 
  Serial.begin(115200);
  ss.begin(115200);
  delay(200);
  ss.println("AT+IPR=9600");
  delay(800);
  Serial.begin(9600);
  ss.begin(9600);
  delay(200);
  Serial.println("Welcome to my Arduino project");
  delay(200);
  ss.println("AT+CMGF=0");
  delay(500);
  ss.println("AT+CPMS=SM,SM,SM");
  delay(500);
  ss.println("AT+CNMI=1,2,0,0,0");
  delay(500);
  for(i=0;i<=35;i++){
    ss.print("AT+CMGD=");
    ss.println(i);
    delay(100);
  }
  ss.println("AT+GPS=1");
  Serial.println("Initializing");  
  delay(1000);
  Serial.println(".");
  delay(1000);
  Serial.println(".");
  ss.println("AT+GPSRD=1");
  delay(1000);
  Serial.println(".");
  delay(1600);
  if (millis() > 12000 && gps.charsProcessed() < 10) ///if check wiring change to 10000
  {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
  }
  Serial.println("Operation started SUCCESSFULLY");
  delay(400);
  Serial.println("GSM initialized");
  do{
    while (ss.available() > 0)
      if (gps.encode(ss.read()))
        displayInfo();
  }while (lat == 0 || lng == 0 || day == 0 || month == 0 || year == 0 || hour == 0 || min == 0 || sec == 0);
  latplus = lat + 0.003;
  latminus = lat - 0.003;
  lngplus = lng + 0.003;
  lngminus = lng - 0.003;
  delay(200);
  Serial.println("Waiting for messages");
  ss.println("AT+GPSRD=0");
  delay(1000);
}
//*************************************************************
void loop()
{
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0)
    if (gps.encode(ss.read()))
      RecvMsg;
  waitingSMS = true;     
}
//*************************************************************
void RecvMsg()
{ ss.println("AT+GPSRD=0");
  delay(1000);
  ss.println("AT+CMGF=1");
  delay(1000);
  /*while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }*/
  //while(waitingSMS || (lat < latplus && lat > latminus) || (lng < lngplus && lng > lngminus))
  //{    
    while (ss.available() > 0) //while there is stuff in the buffer
    if (gps.encode(ss.read())) //if it can successfully decode it, do it. Else try again when more charachters are in the buffer
    if (sms.available()) // if a text has been recieved
    {
      Serial.println("Message received from:"); // print to the computer
      sms.remoteNumber(PhoneNumber, 20); // assign the sender number to the "senderNumber" variable
      Serial.println(PhoneNumber); // print the sender number to the computer
      password = ""; // flush the temporary variable
      char c;
      while(c=sms.read()){
      password += c;}
      Serial.println(password); // print the contents of the sms
      Serial.println("End of message"); // print to the computer
      sms.flush(); // delete message from modem buffer
      Serial.println("Message deleted"); // print to the computer
      if (password == yourPassword) // if the sms contains the correct password
      {
        Serial.println("Valid code");
        delay(200);
        Serial.println("Extracting Coordinates");
        do{
          while (ss.available() > 0)
          if (gps.encode(ss.read()))
          displayInfo();
        }while (lat == 0 || lng == 0 || day == 0 || month == 0 || year == 0 || hour == 0 || min == 0 || sec == 0);
        SendMsg;
        waitingSMS = false;
      }
      else 
      {
        Serial.println("Discarded SMS");
        sms.flush();//Message disposal
      }
      if (lat > latplus || lat < latminus || lng > lngplus || lng < lngminus)
      {
        do{
          while (ss.available() > 0)
          if (gps.encode(ss.read()))
          displayInfo();
        }while (lat == 0 || lng == 0 || day == 0 || month == 0 || year == 0 || hour == 0 || min == 0 || sec == 0);
        SendMsg();
        ss.print("ATD"); //doulepse me at commands altsoftserial kai u_tx sto pin 8 kai u_rx sto pin 9 kai douleue to microfono 
        ss.println(PhoneNumber); //gia na pareis esu til prepei "AT+CNUM" kai molis kalei "ata". "ATS0=1" gia automati apantisi klisis
        /*ss.print("ATD+"); 
        ss.print(PhoneNumber);
        ss.println(";");*/
      }
    }
  //}
}
//*************************************************************
void SendMsg()
{
  delay(1000);  // Delay of 1 second
  ss.print("AT+CMGS="); // Mobile number you want to text to
  ss.println(PhoneNumber);
  delay(1000);
  ss.println("Location");
  ss.print(lat,6);
  ss.print(",");
  ss.println(lng,6);
  ss.print("Date ");
  if (day < 10){
    ss.print(0);
    ss.print(day);
  }else{
    ss.print(day);
  }
  ss.print("/");
  if (month < 10){
    ss.print(0);
    ss.print(month);
  }else{
    ss.print(month);
  }
  ss.print("/");
  ss.println(year);
  ss.print("Time ");
  if (hour < 10){
    ss.print(0);
    ss.print(hour);
  }else{
    ss.print(hour);
  }
  ss.print(":");
  if (min < 10){
    ss.print(0);
    ss.print(min);
  }else{
    ss.print(min);
  }
  ss.print(":");
  if (sec < 10){
    ss.print(0);
    ss.println(sec);
  }else{
    ss.println(sec);
  }
  ss.println("http://www.earthpoint.us/Convert.aspx");  
  delay(100);
  ss.println((char)26);// ASCII code of CTRL+Z for saying the end of sms to  the module 
  delay(1000);
  ss.println("AT+CMGF=0");    //Sets the GSM Module in GPS Mode
  delay(1000);  // Delay of 1 second
}
//*************************************************************

I am not an expert and don't know how to guide you. But, curious to know the suggestions what others would say.

I’m not an expert my self as well but i tried a lot of different stuff and different codes but nothing could work.

I attached my exact gsm just to be sure.

maybe it is a module configuration problem and not the code it self ?
I really dont know

–UPDATE–
I found this code and it works for my situation
it is pretty big but you can change the void parseSMSContent() based on ur actions you wanna do when the module receives a message .
In order for this to work though u need to use the AT command “AT+CNMI=0,1,0,0,0
to setup the module to respond with +CMTI .

If someone can tell me though why my first code doesnt work i would gladdly take it.

#include <AltSoftSerial.h>
AltSoftSerial GPRS(7, 8); // RX, TX

enum _parseState {
  PS_DETECT_MSG_TYPE,

  PS_IGNORING_COMMAND_ECHO,

  PS_READ_CMTI_STORAGE_TYPE,
  PS_READ_CMTI_ID,

  PS_READ_CMGR_STATUS,
  PS_READ_CMGR_NUMBER,
  PS_READ_CMGR_SOMETHING,
  PS_READ_CMGR_DATE,
  PS_READ_CMGR_CONTENT
};

byte state = PS_DETECT_MSG_TYPE;

char buffer[80];
byte pos = 0;

int lastReceivedSMSId = 0;
boolean validSender = false;

void resetBuffer() {
  memset(buffer, 0, sizeof(buffer));
  pos = 0;
}

void setup()
{
  GPRS.begin(9600);
  Serial.begin(9600);

  // Set as appropriate for your case
  /*pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  digitalWrite(2, HIGH);
  digitalWrite(4, HIGH);*/

  for (int i = 1; i <= 15; i++) {
    GPRS.print("AT+CMGD=");
    GPRS.println(i);
    delay(200);

    // Not really necessary but prevents the serial monitor from dropping any input
    while(GPRS.available()) 
      Serial.write(GPRS.read());
  }
}

void loop()
{
  while(GPRS.available()) {
    parseATText(GPRS.read());
  }
}

void parseATText(byte b) {

  buffer[pos++] = b;

  if ( pos >= sizeof(buffer) )
    resetBuffer(); // just to be safe

  /*
   // Detailed debugging
   Serial.println();
   Serial.print("state = ");
   Serial.println(state);
   Serial.print("b = ");
   Serial.println(b);
   Serial.print("pos = ");
   Serial.println(pos);
   Serial.print("buffer = ");
   Serial.println(buffer);*/

  switch (state) {
  case PS_DETECT_MSG_TYPE: 
    {
      if ( b == '\n' )
        resetBuffer();
      else {        
        if ( pos == 3 && strcmp(buffer, "AT+") == 0 ) {
          state = PS_IGNORING_COMMAND_ECHO;
        }
        else if ( pos == 6 ) {
          //Serial.print("Checking message type: ");
          //Serial.println(buffer);

          if ( strcmp(buffer, "+CMTI:") == 0 ) {
            Serial.println("Received CMTI");
            state = PS_READ_CMTI_STORAGE_TYPE;
          }
          else if ( strcmp(buffer, "+CMGR:") == 0 ) {
            Serial.println("Received CMGR");            
            state = PS_READ_CMGR_STATUS;
          }
          resetBuffer();
        }
      }
    }
    break;

  case PS_IGNORING_COMMAND_ECHO:
    {
      if ( b == '\n' ) {
        //Serial.print("Ignoring echo: ");
        //Serial.println(buffer);
        state = PS_DETECT_MSG_TYPE;
        resetBuffer();
      }
    }
    break;

  case PS_READ_CMTI_STORAGE_TYPE:
    {
      if ( b == ',' ) {
        Serial.print("SMS storage is ");
        Serial.println(buffer);
        state = PS_READ_CMTI_ID;
        resetBuffer();
      }
    }
    break;

  case PS_READ_CMTI_ID:
    {
      if ( b == '\n' ) {
        lastReceivedSMSId = atoi(buffer);
        Serial.print("SMS id is ");
        Serial.println(lastReceivedSMSId);

        GPRS.print("AT+CMGR=");
        GPRS.println(lastReceivedSMSId);
        //delay(500); don't do this!

        state = PS_DETECT_MSG_TYPE;
        resetBuffer();
      }
    }
    break;

  case PS_READ_CMGR_STATUS:
    {
      if ( b == ',' ) {
        Serial.print("CMGR status: ");
        Serial.println(buffer);
        state = PS_READ_CMGR_NUMBER;
        resetBuffer();
      }
    }
    break;

  case PS_READ_CMGR_NUMBER:
    {
      if ( b == ',' ) {
        Serial.print("CMGR number: ");
        Serial.println(buffer);

        // Uncomment these two lines to check the sender's cell number
        //validSender = false;
        //if ( strcmp(buffer, "\"+0123456789\",") == 0 )
        validSender = true;

        state = PS_READ_CMGR_SOMETHING;
        resetBuffer();
      }
    }
    break;

  case PS_READ_CMGR_SOMETHING:
    {
      if ( b == ',' ) {
        Serial.print("CMGR something: ");
        Serial.println(buffer);
        state = PS_READ_CMGR_DATE;
        resetBuffer();
      }
    }
    break;

  case PS_READ_CMGR_DATE:
    {
      if ( b == '\n' ) {
        Serial.print("CMGR date: ");
        Serial.println(buffer);
        state = PS_READ_CMGR_CONTENT;
        resetBuffer();
      }
    }
    break;

  case PS_READ_CMGR_CONTENT:
    {
      if ( b == '\n' ) {
        Serial.print("CMGR content: ");
        Serial.print(buffer);

        parseSMSContent();

        GPRS.print("AT+CMGD=");
        GPRS.println(lastReceivedSMSId);
        //delay(500); don't do this!

        state = PS_DETECT_MSG_TYPE;
        resetBuffer();
      }
    }
    break;
  }
}

void parseSMSContent() {

  char* ptr = buffer;

  while ( strlen(ptr) >= 2 ) {

    if ( ptr[0] == 'r' ) {
      if ( ptr[1] == '1' )
        Serial.println("command 1");
      else
        Serial.println("command 2");
    }

    if ( ptr[0] == 'y' ) {
      if ( ptr[1] == '1' )
        Serial.println("command 4");
      else
        Serial.println("command 5");
    }

    ptr += 2;
  }
}

there is a video on youtube about all this code:

Controlling Arduino via SMS messages

I want my device to send me sms when it receives sms with the word "Location" but I can't make this happen...

 if (password == yourPassword) // if the sms contains the correct password

Does this ever return true ? What do you see when you print password ?

if (password == yourPassword) // if the sms contains the correct password

Does this ever return true ?
What do you see when you print password ?

the last message i see in serial monitor is this :

Serial.println("Waiting for messages");

which is at the end of void setup.
i sent sms with the word Location which is the keyword but nothing happens.
Even the official GSM example ReceiveSMS doesnt work for me.

/*
 SMS receiver
 This sketch, for the Arduino GSM shield, waits for a SMS message
 and displays it through the Serial port.

 Circuit:
 * GSM shield attached to and Arduino
 * SIM card that can receive SMS messages

 created 25 Feb 2012
 by Javier Zorzano / TD

 This example is in the public domain.

 http://www.arduino.cc/en/Tutorial/GSMExamplesReceiveSMS

*/

// include the GSM library
#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER ""

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// Array to hold the number a SMS is retreived from
char senderNumber[20];

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("SMS Messages Receiver");

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while (notConnected) {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
      notConnected = false;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}

void loop() {
  char c;

  // If there are any SMSs available()
  if (sms.available()) {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal
    // Any messages starting with # should be discarded
    if (sms.peek() == '#') {
      Serial.println("Discarded SMS");
      sms.flush();
    }

    // Read message bytes and print them
    while (c = sms.read()) {
      Serial.print(c);
    }

    Serial.println("\nEND OF MESSAGE");

    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  delay(1000);

}

this example stops at

if (gsmAccess.begin(PINNUMBER) == GSM_READY)

i disable the pin in this sim.
even if i delete this whole access with pin number procedure , it stacks at :

if (sms.available()) {

so the whole gsm library doesn’t work with this module ?