If statement ignored after changed value .

Hi guys , I successfully can changed data now using GSM module and EEPROM . but after i changed it the “IF Condition” ignored the whole state. This is the scenario , if I text GSM module "STI(password)SET, then the next text is the new password “JJJ” . Then the GSM Module will reply

mySerial.println("Congrats! You've successfully changed the password: " + readkey);

then the while condition will exit and back to void loop right ? I also try to print Serial.println(readkey); in the void loop so i could check it successfully changed the password and back to void loop.

Now when i text “JJJ”" ON" its only printing in serial and the

  if(textMessage.indexOf(readkey + " ON")>=0){
    Serial.println("LED set to ON");  
   textMessage = "";   
 }

ignored it . But when i restart the arduino it works fine but i dont want to restart and restartover again, what is the problem guys ?

this is the whole code in void loop .

void loop()
{

  if(mySerial.available()>0){
  textMessage = mySerial.readString();
  
  delay(10);
  
  if(textMessage.length()>0)
  {
  textMessage=textMessage.substring(textMessage.indexOf("+CMT"));
  textMessage=textMessage.substring(textMessage.indexOf("\n"));
  textMessage.replace("\n","");
  Serial.println(textMessage);
 }
 }


  if(textMessage.indexOf(readkey + " ON")>=0){
    Serial.println("LED set to ON");  
   textMessage = "";   
 }
 
while (textMessage.indexOf(readkey + " SET")>=0){
if (mySerial.available() > 0){
    password = mySerial.readString();
    delay(10);
  
if(password.length()>0){
password = password.substring(password.indexOf("+CMT"));
password = password.substring(password.indexOf("\n"));
password.replace("\n","");
storePw();
reads();

  mySerial.println("AT+CMGF=1");    
  delay(1000);  
  mySerial.println("AT+CMGS=\"+639290584072\"\r"); 
  delay(1000);
  mySerial.println("Congrats! You've successfully changed the password: " + readkey);
  delay(100);
   mySerial.println((char)26);
  delay(1000);

   }

}

}

          
}

Hello jsteer

Where are the setup and the declarations ?

Regards,
bidouilleelec

As I said, after i changed the readkey using text , I’d Searial.println(readkey); in the void loop so that i know if the data is successfully changed .

This is my whole code bro

 #include <SoftwareSerial.h>
 #include <EEPROM.h>

SoftwareSerial mySerial(9, 10);
String password = "STI";
String textMessage;
String readkey="";



void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  delay(5000);
  Serial.println("SIM900 ready...");
  SendMessage();
  reads();

}


void loop()
{

  if(mySerial.available()>0){
  textMessage = mySerial.readString();
  
  delay(10);
  
  if(textMessage.length()>0)
  {
  textMessage=textMessage.substring(textMessage.indexOf("+CMT"));
  textMessage=textMessage.substring(textMessage.indexOf("\n"));
  textMessage.replace("\n","");
  Serial.println(textMessage);
 }
 }


  if(textMessage.indexOf(readkey + " ON")>=0){
    Serial.println("LED set to ON");  
   textMessage = "";   
 }
 
while (textMessage.indexOf(readkey + " SET")>=0){
if (mySerial.available() > 0){
    password = mySerial.readString();
    delay(10);
  
if(password.length()>0){
password = password.substring(password.indexOf("+CMT"));
password = password.substring(password.indexOf("\n"));
password.replace("\n","");
storePw();
reads();

  mySerial.println("AT+CMGF=1");    
  delay(1000);  
  mySerial.println("AT+CMGS=\"+639290584072\"\r"); 
  delay(1000);
  mySerial.println("Congrats! You've successfully changed the password: " + readkey);
  delay(100);
   mySerial.println((char)26);
  delay(1000);

   }

}

}

          
}


 void SendMessage()
{
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+639290584072\"\r"); // Replace x with mobile number
  delay(1000);
  mySerial.println("The system is ready");// The SMS text you want to send
  delay(100);
   mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}

void reads(){
  readkey ="";
  for(int i=0; i<password.length(); i++){
  char a = EEPROM.read(i);
 
  readkey = readkey+a;
}
Serial.println(readkey);
}

void storePw() {
 
for(int i=0; i<password.length(); i++){
  EEPROM.write(i, password[i]);
}
}