stanleyhuangyc / Freematics

Official source code repository for Freematics
https://freematics.com
430 stars 349 forks source link

How to Get phone number from a received SMS? (Arduino + SIM800c) #107

Open AnushkaVJ opened 4 years ago

AnushkaVJ commented 4 years ago

Below is the function which validating sms


void ValidateSMS(String SMS) { String number = "+CMT:"; int index1 = SMS.indexOf(number); if (index1 == -1) { Serial.println("An Error Occured Durring reading sms"); } else { Serial.println("it is a sms"); int index2 = SMS.indexOf(number);

int index3 = SMS.indexOf("001");
if (index3 == -1)
{
  Serial.println("message not valide");
} else
{
  SendSMS();
}
//}

} }

Below is the function which sending sms.


void SendSMS() { String sendto = "AT+CMGS=\"+96*****\"\r";

GSMSerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode delay(1000); // Delay of 1000 milli seconds or 1 second GSMSerial.println(sendto); delay(1000); GSMSerial.println(link);// The SMS text you want to send delay(100); GSMSerial.println((char)26);// ASCII code of CTRL+Z delay(1000); Serial.println("SMS is Sended"); }


here I need to send SMS, to the SMS received phone number instead of mentioning it within the code level. (+9**).

If anyone can, please help me on resolving this. Thank you!