I am using a GSM sim 900A modem along with Uno. I am able to receive the sms and display on the serial monitor. I want to read the sms message and if it has a particular input message then take action.
How shall I do it? I searched a lot in the internet but unable to understand. Please help me out as I am a beginner in programming.
Have a look at Serial.find.
For example:
if (Serial1.find("looking for this string")) Serial.print("Match found!");
Thanks. But should I store the message in the form of string?
You could use Serial.find instead of storing the sms. Serial.find reads the serial buffer and returns a TRUE if a match was found, so unless you need to store the sms string for use later on, just use the Serial.find function.
Got it thanks.
If I have to store sms how should I do it?
Use Serial.find to wait for the first part of the message, then store the remaining part of the message. Try something like this:
String smsString;
if (Serial1.find("first part of message")){
smsString = "first part of message";
while(Serial1.available()){
smsString += (char)Serial1.read();
}
}
Thanks
Why not just use a strcmp() function
Something like this:
if (strcmp(incommingSMS,myString)== 0)
{
Serial.println("Ok I will take action");
}
If the content is the same in both strings there will be no difference between then (that's why you compare then to 0)
Simple and clean.
You should avoid use Strings objects.Use char arrays instead!
If I need to store the incoming message and then later on remove this message when I receive next message what should I do?
If I need to store the incoming message and then later on remove this message when I receive next message what should I do?
Overwrite the last content, writing the new message at the same array of characters
Can you please let me know the code
Can't I use
if (Serial.find("looking for this string"))
{
Serial.print("Match 1 found!");
}
else if(Serial.find("looking for this string"))
{
Serial.print("Match 2 found!");
}
if I use this it wont check second part. Please help me out If I need to check 2 incoming message