Return Message From a Predefined Incoming Number

Hello Everyone,

I am self-learning Arduino programming. Now, I am onto a project using GSM module when called upon to return me some physical value from a sensor. It works pretty well until when I am trying to retrieve caller number from +CMT: because I want the program to filter out all other incoming caller's request except the specified caller number. Well, I did come up with two boolean statements - DetectIncomingCall() and SMSRequestState() - to achieve it at the end but the code is a bit chunky. I am just wondering if there is a way to program my code to parse both caller number and message content together in String. I have tried the below attempt but the code didn't really get into the second if statement. Attached is my entire project code!

/while(SIM900.available()>0)
{
String Message;
Message=SIM900.readStringUntil('\n');
Message.trim();//get rid of newline character
Serial.println(Message);
if(Message.indexOf("+xxxxxxxxxxx")>-1)
{
delay(20);
if (Message.indexOf("STATE")>-1){
Serial.println("...Request Received \n");
return true;
}
}
Message = "";
return false;
}
}
/

GSM Test Code - Return Message When Prededined Number Called On.txt (4.89 KB)