Arduino uno Sim900 buffer overflow

Hi everyone

i have a problem i am using arduino uno with sim900 to read data from the web page but when i receive its out of order and mixed up.I tried searching for help on the internet but i didn't get the clear solution for example most people say "read data to an array before the buffer is full" i created the function to dt that but when i call the the function after "AT+HTTPACTION" or after "AT+HTTPREAD" it doesn't make any difference and i also went to

C:\arduino-1.0.3-windows\arduino-1.0.3\hardware\arduino\cores\arduino\HardwareSerial.cpp and changed SERIAL_BUFFER_SIZE from 64 to 256 but still no difference.

i attached my code,the webpage with the data i want to read and the data as i receive on a serial monitor.as you can see that its no longer the same as it was on a webpage,how can i solve this problem?

i would realy appreciate your help thanks.

here is the code:

#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <String.h>
SoftwareSerial mySerial(7, 8);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 
void setup()
{
  mySerial.begin(9600);               // the GPRS baud rate   
  Serial.begin(19200);   // the GPRS baud rate 
  lcd.begin(16,2);
  delay(500);
}
 
void loop()
{
  mySerial.println("AT+CSQ");
  delay(100);
  ShowSerialData();// this code is to show the data from gprs shield, in order to easily see the process of how the gprs shield submit a http request, and the following is for this purpose too.
 
  mySerial.println("AT+CGATT?");
  delay(100);
  ShowSerialData();
 
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
  delay(1000);
  ShowSerialData();
 
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"CMNET\"");//setting the APN, the second need you fill in your local apn server
  delay(4000);
  ShowSerialData();
 
  mySerial.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to the AT command mamual
  delay(2000);
  ShowSerialData();
 
  mySerial.println("AT+HTTPINIT"); //init the HTTP request
  delay(2000); 
  ShowSerialData();
 
  mySerial.println("AT+HTTPPARA=\"URL\",\"http://www.aczola.comoj.com/fruits.php\"");// setting the httppara, the second parameter is the website you want to access
  delay(1000);
  ShowSerialData();
  Serial.flush();
  mySerial.println("AT+HTTPACTION=0");//submit the request 
  delay(10000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.while(!mySerial.available());
  ShowSerialData();
 
  mySerial.println("AT+HTTPREAD");// read the data from the website you access
  delay(300);
 // getContent();
  ShowSerialData();
 
  mySerial.println("");
  delay(100);
} 

void ShowSerialData()
{
  while(mySerial.available()!=0)
  Serial.write(mySerial.read());
}

void getContent()
{
  String content = "";
  while(mySerial.available() != 0)
  {
    content = content + String(char(mySerial.read()));
    lcd.print(String(char(mySerial.read())));
    delay(500);
    Serial.flush();
  }
}

final.ino (2.12 KB)

response.PNG

  delay(10000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.while(!mySerial.available());

Complete and utter nonsense. Sitting around with your thumb up your ass for 10 seconds, while the device is streaming data back to you makes it an absolute CERTAINTY that you will loose data.

What you need to do is read any and all serial data AS SOON AS IT ARRIVES, until you get the end of packet marker.

You should NOT be pissing away resources on the String class. It can be VERY slow adding new characters, since all the existing data needs to be copied every time a character is added.

If you have memory to create a String that holds all the data, you have memory to create a string that holds all the data. If you don't have memory to create a string that holds all the data, you haven't a hope in hell of creating a String that holds all the data.