Hi,
I have been trying to connect my GPRS shield to COSM and have been successful in posting data. My problem is with receiving data. I use the .csv format in sending/receiving data. I want to read the last data-point in a stream. But when I use GET, I get a lot of header related information, and there is a buffer overflow since the buffer size is 64. I tried increasing it to 256, (I use a 328P but even with a Mega 2560, I cannot increase the data buffer size beyond 512 for stable operations), but even then the data-buffer cannot hold the complete data I get with a GET command to COSM.
Can anyone provide suggestions on how best to get my data from GET. I am posting the relevant part of my code below:
GPRS_Serial.flush();
GPRS_Serial.print("GET /v2/feeds/51575/datastreams/Sample.csv HTTP/1.1\r\n");
Serial.println("GET /v2/feeds/51575/datastreams/Temp.csv HTTP/1.1 Sent!");
delay(300);
GPRS_Serial.print("Host: api.cosm.com\r\n");
Serial.println("Host: api.cosm.com Sent!");
delay(300);
GPRS_Serial.print("X-ApiKey: X4xpRLopmHhgrTTm4FGHeAGHlQuSAKxUbmd5SXBSekRBaz0g\r\n"); //REPLACE THIS KEY WITH YOUR OWN PACHUBE API KEY
Serial.println("X-ApiKey: X4xpRLopmHhgrTTm4FGHeAGHlQuSAKxUbmd5SXBSekRBaz0g Sent!"); //REPLACE THIS KEY WITH YOUR OWN PACHUBE API KEY
GPRS_Serial.print("\r\n");
GPRS_Serial.write(26);
delay(300);
if(GPRS_Serial_wait_for_bytes(4,55) == 0)
{
Serial.println("Timeout");
goto power_start;
}
else
{
while(GPRS_Serial.available()!=0){
while (GPRS_Serial.read()!='\n');
while (GPRS_Serial.read()!='\n');
while (GPRS_Serial.read()!='\n');
while (GPRS_Serial.read()!='\n');
while (GPRS_Serial.read()!='\n');
while (GPRS_Serial.read()!='\n');
while (GPRS_Serial.read()!='\n');
while (GPRS_Serial.read()!='\n');
while (GPRS_Serial.read()!='\n');
while (GPRS_Serial.read()!='\n');
while (GPRS_Serial.read()!='\n');
while (GPRS_Serial.read()!='\n');
while (GPRS_Serial.read()!='\n');
// while (GPRS_Serial.read()!='\n');
for (coun=0; coun<75; coun++){
c[coun]= (char) GPRS_Serial.read();
}
while(GPRS_Serial.available()!=0)
{
Serial.print((char)GPRS_Serial.read());
}
}
}
/* for (coun=0; coun<500; coun++){
GPRS_Serial.read();
}
*/
Serial.println();
Serial.print(c);
I was playing with the idea that I should ignore the header by ignoring the first couple of lines of data received. (
The part with : while (GPRS_Serial.read()!='\n'); is done to ignore the first couple of header information. ) But this did not work since sometimes, the number of header lines is different and I can miss the relevant data field.
Thanks for your help.
Alfatek