I'm trying to read a message from GSM (SIM 300). I send a command but the answer is about 150 characters so I get buffer overflow.
Here is what I'm doing:
void loop()
{
Serial1.println("AT+CMGR=1");
delay(100);
while (Serial1.available())
{
Serial.write(Serial1.read());
}
I do get overflow here. If I remove Serial1.println("AT+CMGR=1") and just send data from my laptop and read it then everything is ok.
It should read while Serial1.available() and it should be >0 untill all 150 bytes are received. I also tried to put delay(1000) at the end. All the same.
It should read while Serial1.available() and it should be >0 untill all 150 bytes are received.
No. That is not true. Imagine that you are reading over my shoulder as I type slowly. There are some number of characters that you have not yet read, but, at some point, you will read everything I have typed, even though I haven't finished a paragraph, or even a sentence (or word). If you assume, having read everything I typed slowly, that that was the complete message, you'd be wrong.
If you close your eyes for 100 milliseconds, while I hunt and peck away, I might have typed more than 64 characters while you were napping. Those extra characters are then lost.