Inconsistent response AT command I'm building a vehicle tracker with Arduino shield with Waveshare SIM 808. I am communicating with the Arduino via AT commands, and came across the following problem: The method "leserial ()" returns me the result of the command missing characters

Response
+CGNSINF: 1,1,20161101222934.000,-23.285230,-51.20

Expected response
+CGNSINF: 1,1,20161101223215.000,-23.285222,-51.204778,623.000,0.02,142.3,1,,1.2,2.5,2.2,,8,7,,,38,,

Code:

#include &lt;SoftwareSerial.h&gt;
SoftwareSerial mySerial(2, 3); //RX, TX

String inputString = ""; 
char inChar; 

const int powerkey =  5;
const int statuspin = 6;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);  
  pinMode(powerkey, OUTPUT);
  pinMode(statuspin, INPUT);

  mySerial.println("AT");
  delay(2000);
  leserial();

  //TURN ON GPS
  mySerial.println("AT+ CGNSPWR =1");
  delay(2000);
  leserial();
}

void loop() {
  //GET LOCATION
  mySerial.println("AT+CGNSINF");
  delay(4000);
  leserial();
  delay(5000);
}

void leserial(){
  inputString = "";
  while (mySerial.available()&gt;0){
    inChar = mySerial.read();  
    inputString += inChar;    
  }
  Serial.println(inputString);
}
Basically you're sending a command that gives a response, then waiting 2 seconds for that response to arrive (which is completely the wrong thing to do to start with).

You have to ask yourself: where does that response go when it does arrive, while it's waiting for you to finally get around to reading it?

The answer is: into a small internal buffer that is considerably smaller than the response.

Thus most of the response just gets thrown away because there isn't room for it.

Instead you should most definitely NOT delay for 2 seconds waiting for the response, and instead keep looking to see if there are any characters to read up until you reach the end of the line.

It's all explained here: https://hackingmajenkoblog.wordpress.com/2016/02/01/reading-serial-on-the-arduino/