I would love to get real developers' input regarding the following issue as I've been spinning my head around it for a while now.
WHAT I'D LIKE TO DO
My program receives SMS containing simple instructions. When a SMS is received, the code will run according to the instruction. In the mean time, other SMS can be received by the modem[1].
I would like my program to ignore any instruction received while it was busy doing something, and therefore I'm looking for a way to delete any SMS received before the arduino finished doing what it was doing.
What I'm having trouble with is the sms.flush()
function. This function is available from the GSM.h
library, which is bundled with the Arduino IDE by default.
-
and here comes the first glitch: the flush()function reference page states that it "clears the modem memory of any sent messages once all outgoing characters have been sent". So it seems at first that flush() would only work for outgoing messages...
-
...but in the mean time, the official sketch for SMS reception (ReceiveSMS) does indeed use flush() to delete received SMS.
So for me, flush() really works both for outgoing and received SMS. Am I right?
WHAT I DID
Here is how the program works:
- The arduino receives a SMS and is asked to light a LED
- It does as instructed
- then sends a SMS back saying that the LED is ON.
- The DeleteSMS function is triggered
Here is the code:
void DeleteSMS(){
int MessageQtt = 0;
Serial.print(F("["));
do{
sms.flush();
MessageQtt++;
} while (sms.available() > 0);
Serial.print(MessageQtt);
Serial.print(F(" message(s)"));
Serial.println(F(" have been deleted]\n"));
}
This function is therefore called at the end of the Arduino operations. With it, I wanted to force the Arduino to delete not only the first SMS received as well as the one sent back, but also any SMS received in the mean time.
But it doesn't work and I can't really find out why.
MY DEVICES
- Arduino UNO
- GSM Shield 2
- local (France) provider SIM card
Thanks all in advance for your input...
(by the way: if someone could tell me where to find the GSM.h file, I could mess with it to see how things work...)
[^1]: From what I've learned, any SMS received while the modem is turned off or the Arduino busy doing something else will be stored in the memory buffer, but I can't really retrieve my source on that one.