Problem receiving full serial event+SMS I wrote code in Arduino to read SMS. I have a problem with receiving it from serial.

String str;

void setup() {
  Serial.begin(9600);
  Serial.println("AT+CMGF=1");
  delay(1000);
}

void loop() {
  Serial.println("AT+CMGF=1");
  delay(2000);
  Serial.println("AT+CMGR=1");
  delay(5000);
  while (Serial.available()&gt;0) {
    str = char(Serial.read());
    Serial.print(str);
  }
  Serial.println();
}


I have an A6 GSM modem. When I read the serial I just get:

+CMGR: "REC READ


Nothing more!

I should get something like this:

+CMGL: 1,"REC READ","+989207201219",,"2017/08/26,21:54:56+05"
test 20


I changed my code to:

int readline(int readch, char *buffer, int len) {
  static int pos = 0;
  int rpos;
  if (readch &gt; 0) {
    switch (readch) {
      case '\n': // Ignore new-lines
        break;
      case '\r': // Return on CR
        rpos = pos;
        pos = 0;  // Reset position index ready for next time
        return rpos;
      default:
        if (pos &lt; len-1) {
          buffer[pos++] = readch;
          buffer[pos] = 0;
        }
    }
  }
  // No end of line has been found, so return -1.
  return -1;
}

void setup() {
  Serial.begin(9600);
  Serial.println("AT+CMGF=1");
  Serial.println("AT+CPMS=\"SM\",\"SM\",\"SM\"");
}

void loop() {
  Serial.println("AT+CMGF=1");
  Serial.println("AT+CMGR=1");
  static char buffer[80];
  if (readline(Serial.read(), buffer, 80) &gt; 0) {
    Serial.print("You entered: &gt;");
    Serial.print(buffer);
    Serial.println("&lt;");
  }
  delay(3000);
}


But I get nothing.
The arduino is a "small memory" device. So it probably does not have a big serial buffer. On say "linux on a PC" you get a 4096 byte buffer, but on an arduino, probably only say 16. Now as luck will have it "+CMGR: "REC READ" is precisely 16 characters.... 

From the code that I see, you seem to be sending commands to the modem and then reading/echoing them. I would have liked to use two different serial ports or something like that. 

In any case, if it sort of works for those first 16 characters, remove all the delays and put one of them near the end of the loop() function. Remove the initial print to the modem in the setup function.