Go Down

Topic: GPRS shield COSM need help with GET command (Read 371 times) previous topic - next topic

alfatek

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:

Code: [Select]
 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

PaulS

Quote
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.

It also doesn't work because GPRS_Serial.read() is not a blocking function. If there is nothing to read, the function returns a -1, which is not a \n, so the while loop ends.

At least, I assume that is the case. Your snippet does not define what GPRS_Serial is.

alfatek

Thanks for your reply Paul. Let me try with a '-1' as well in my blocking function. Also, GPRS_Serial is a Software Serial literal.
Thanks,
Alfatek

PaulS

Quote
Let me try with a '-1' as well in my blocking function.

A call to GPRS_Serial.available() would be a better idea. Keep twiddling your thumbs until it returns a value greater than 0 (that is, there is something to read).

Go Up