GSM shield 2 - Fully erase memory buffer

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.

therefore I'm looking for a way to delete any SMS received before the arduino finished doing what it was doing.

Why? Why not just process that SMS after processing the current one?

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...

Where did you install the IDE? In that path, there is a libraries folder, containing a folder called GSM which contains a folder called src that contains GSM.h. At least on my computer, there is.

PaulS:
Why? Why not just process that SMS after processing the current one?

Well, because most of the time the program will crash. I can't pinpoint why though.
If, let's say five different instructions are sent to the arduino, but with enough time between each one of them so that the arduino has the time to launch the operation corresponding to one instruction, then reply back and lastly to erase the SMS received, and then to go to the following instruction, well no crash.

But if I send all these instructions successively, without delay, the program starts to deal with each one of them one by one, which is cool with me, but at some point it will crash.

I won't be able to interact with the arduino anymore, I'll need to unplug it from my USB port.

I just tried again, and it crashed at the 4th instruction. The program turned the LED on, sent me a text, and then stopped...

So to avoid these crashes, I really wanted to find out how to completely erase the modem memory.

So to avoid these crashed, I really wanted to find out how to completely erase the modem memory.

I think it would be more beneficial to figure out why you are not processing an SMS without crashing. The Arduino should not even know that the external hardware has received an SMS until it is done with processing the current SMS.

Since we can't see your code, your on your own fixing it.

PaulS:
I think it would be more beneficial to figure out why you are not processing an SMS without crashing. The Arduino should not even know that the external hardware has received an SMS until it is done with processing the current SMS.

Well I just didn't want to flood that post with my code... There you go:

	SMS_LED, SMS_PreviousLED,
	Potentiometre,
	Button_Status,
	Button_StatusPrevious,
	LED_Status,
	MillisActual,
	MillisInterval,
	SMS_WrongNumber,
	SMS_WrongInstruction
	= 0;

This is a horrid abuse of the comma operator. All these variables have already been initialized anyway.

		if(Sender_Number[i] == Admin_Number[i]);
		else{

There is a != operator...

void LED_On_Off(){
	digitalWrite(LED, LED_Status); 
	Button_StatusPrevious = Button_Status;
}

Why does turning the LED on or off cause the assignment of Button_Status to Button_StatusPrevious?

Other than these, I don't see anything wrong with the code. What do your Serial.print() tell you is/has happened when the Arduino crashes?

PaulS:
This is a horrid abuse of the comma operator. All these variables have already been initialized anyway.

Well sorry for that, it's just that when I started learning arduino code, I've been instructed to initialize variables in setup() as otherwise, it could sometimes trigger hard-to-identify bugs. But maybe it's just important to do it with variables involved with analogRead actions?

PaulS:
There is a != operator...

Mmmhh... not sure what you meant.
Here, the code says basically: "if the numbers are the same, proceed to the next step, but if there are not, then send me a warning message and turn the SMS_WrongNumber variable true", which is basically what I'm looking for.
Isn't what that code does? :frowning: :confused:

PaulS:
Why does turning the LED on or off cause the assignment of Button_Status to Button_StatusPrevious?

To remember what was the previous status of the button (has it been pressed or not?) and use this in void InstructionButton()

PaulS:
Other than these, I don't see anything wrong with the code. What do your Serial.print() tell you is/has happened when the Arduino crashes?

I actually removed all the Serial.print() lines that I've been using so far when I shared my code with you to lighten it, but, so far, I haven't been able to identify the source of the crash. This is why I tried my best to make sure the Arduino would erase any waiting message, because my only theory was that at some point, processing a serie of instructions received by SMS made it crash.

The one bug that did happen more than the others has been occurring during the last step (sms.endSMS) of the void SendSMS() function.

Here is the same function with all my Serial.print() debug lines:

void SendSMS(char Title[], char Message1[], char Message2[]){
	/*DEBUG*/ Serial.print(F("** beginSMS + "));
	sms.beginSMS(Admin_Number);
	/*DEBUG*/ Serial.println(F("SystemID : "));
	sms.print(SystemeID);
	/*DEBUG*/ Serial.print(F("** Title + "));
	sms.print(Title);
	/*DEBUG*/ Serial.print(F("Message1 + "));
	sms.print(Message1);
	/*DEBUG*/ Serial.println(F("Message2"));
	sms.print(Message2);

	/*DEBUG*/ Serial.println(F("** endSMS"));
	sms.endSMS();
	Serial.println(F("...end of message!]"));
}

So, on my Serial monitor, the program would then often be stuck at the ** endSMS point and wouldn't never get to the ...end of message!] part. I would sometimes actually receive the SMS, but some other times I would get nothing.

And in both cases, no further interaction would be possible with the program or the Arduino push button without a hardware reset.