Parsing incomming SMS message guidance

Currently I have code that will read the SMS message using find, as the TEXT is at the end I can get that stored easily enough using:-

void RecieveMessage() {

  mySerial.println("AT+CMGF=1\r");
  mySerial.println("AT+CNMI=2,2,0,0,0\r"); // AT Command to receive a live SMS


  while (1) {
    if (mySerial.find("SMS")) {
      no1 = mySerial.readString();
      mySerial.flush();
     ProcessNumber();
    }
    else {
      if (mySerial.find("SITE")) {
      no1 = mySerial.readString();
        Site();

      }
    }

  } //end while
}//end receive messages function

The SMS TEXT gets processed with :

void ProcessNumber()
{
const int BUFSIZE = 13;
char buf[BUFSIZE];
String myString;
char myStringChar[BUFSIZE];
String strip;
//int i;
  
Serial.println(no1);
no2 =no1;
no2.remove(1);
Serial.println(no2);
Serial.println(no1);
Serial.println(no1.length());

int i = no2.toInt();
i=i-1;
if (i<=4){
     if (no1.length()<14){
      Serial.print("Not enough numbers");
      RecieveMessage();
}else{
   if (no1.length()>14){
      Serial.print("Too many numbers");
      RecieveMessage();
}else{
      Serial.print("Saving variable string to address: ");
      Serial.println(i * 14);
      Serial.println(no1);
      myString = no1;
      myString.toCharArray(myStringChar, BUFSIZE); //convert string to char array
      strcpy(buf, myStringChar);
      eeprom_write_string((i * 14), buf);
      Serial.print("Reading string from address : ");
      Serial.println(i * 14);
      eeprom_read_string((i * 14), buf, BUFSIZE);
      Serial.println(buf);
      RecieveMessage();}}
}else{
Serial.print("Only allowed 5 Numbers");

RecieveMessage();
}}

and similar for other text messages with a prefix that i want.

But what is the best way to extract the incoming SMS number from that arrives in the format:-

+CMT: "+4478xxxxxxx0","","18/09/12,10:18:37+04"
SMS1078xxxxxxx1

so I want to extract +4478xxxxxxx0 and reply with Mobile stored is 078xxxxxxx1

if I start with the find

if (mySerial.find("+CMT: \"")){
      nor =mySerial.readString();
      Serial.println(nor);

I have two issues:-

  1. I return the following:-+4478xxxxxxx0","","18/09/12,10:37:18+04"
    Tufgif77hh

  2. It doesn't extract the number (welldoesnt extract anything) when it finds SMS or SITE, it directly processes these.

so if

+CMT: "+4478xxxxxxx0","","18/09/12,10:18:37+04"
SMS1078xxxxxxx1

the SMS1 gets stored in the eeprom as the 1st mobile number 1078xxxxxxx1

I need to be able to extract the sending number, so I can reply back with confirmation that the message was processed and ensure that the message has indeed been processed.

if you need clarfication please ask, happy to find something that works for now and something smarter for later, just need to know what i need to do/ look at to get this moving.

Thanks

What about :

String SmsReceived= ...read the sms...  // "+4478xxxxxxx0","","18/09/12,10:18:37+04" 
String SmsSendFromNumber=SmsReceived.substring(0, (numberofdigits)) ;

be carefull with automated sms from provider and/or adrertisement. Better you validate received sms from specific callers.

Thanks for that I have now with minimal code extracted a useable number.

still got plenty to work on

Okay think I have this working consistently okay.

void RecieveMessage() {

  mySerial.println("AT+CMGF=1\r");
  mySerial.println("AT+CNMI=2,2,0,0,0\r"); // AT Command to recieve a live SMS
  Serial.println();
Serial.println("listening");

  while (1) {
if (mySerial.find("+CMT: \"")){
nor =mySerial.readString();
nors = nor.substring(0,(13));
Serial.println(nors);
mySerial.println(nor);

if(mySerial.find("SMS")){
  no1 = mySerial.readString();
     ProcessNumber();
    }else {
      mySerial.println(nor);
      if(mySerial.find("SITE")) {
      no1 = mySerial.readString();
        Site();

   }

  }
}
  } //end while
}//end recieve messages function

but will check again later as sometimes we flashing the unit up and running serial monitor I dont get what I expect straight away, so I end up flashing more than once and restarting the serial monitor.

Thanks for all the help, moving along