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)
