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:-
-
I return the following:-+4478xxxxxxx0","","18/09/12,10:37:18+04"
Tufgif77hh -
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