HTTP client - Interactive Matter

Hi,

I´m using the HTTP Client form - interactive Matter : http://interactive-matter.eu/how-to/arduino-http-client-library/

And i´m having problems with the simplest thing... I created a Webserver in my PC with iWeb Server, and its serving a txt file.

When i run this client code in my arduino i get the following: The code has nothing special...

void loop(){

  char a = '0';

delay(3000);

  //AQUISITION FILE RETRIEVAL
  /////////////////////////////

  Client client(testip, 80);    

  if ( client.connect() ){

    Serial.println("Entrou no connect");

    HTTPClient client("stuff.com", testip, 80);
    FILE* result = client.getURI("/default.html");

      fgets(streami,100,result);
    
    int returnCode = client.getLastReturnCode();
    if (result!=NULL) {      
      client.closeStream(result);
      Serial.println("Closing stream");
      
      Serial.println(streami);      
    } 
    else {
      Serial.println("Failed to connect");
    }
    if (returnCode==200) {
      Serial.println("Data uploaded");
    } 
    else {
      Serial.print("ERROR: Server returned ");
      Serial.println(returnCode);
    }

  }
  else{
    Serial.println("ERROR: No connect ");
  }

  client.stop();

}

Streami is an 300 character string.

I Get the following response in the Serial window:

Serial port 0 initialized... Ethernet initialized... SD card initialized... Entrou no connect Closing stream "[{\"b_formula\":0,\"address\":0,\"format\":\"sint32\",\"inverted\":true,\"method\":\"ir\",\"uuid\" Data uploaded Entrou no connect Closing stream OK

Data uploaded Entrou no connect Closing stream OK

Data uploaded Entrou no connect Closing stream OK

Data uploaded

I think the problems resides in some memory problem that i´m not detecting. Something related with the use of file streams. Can some someone give ideas about what might be the problem?

Thank you!

I Get the following response in the Serial window:

think the problems resides in some memory problem that i´m not detecting. Something related with the use of file streams. Can some someone give ideas about what might be the problem?

Perhaps you could start with explaining what you expect to have happen that is different from what is happening. Do you expect to get the same file over and over?

Instead of just printing streami, you should have something like:

Serial.print("streami: [");
Serial.print(streami);
Serial.println("]");

to see when streami is an empty string.

Posting information that contains special characters requires the use of the code tags or turning off smileys.

Thank you PaulS,

I was so rapped up in my problem, i didn´t even explained what i was expecting.

Mainly i was expecting to get the same answer over and over again. Basically i only receive the correct answer on the first cycle, after i just get the OK. And i don´t really understand why... I thought the reason could be related with the misuse of the File stream result but i´, not sure.

Can i do more to help on the debug? Just tell me, maybe other prints Throw ideas at me please

Cheers

I don't see where you print OK in your code. I think you need to post ALL of your code.

Hi,

I don´t print OK in my code.

That´s streami is returning from the fgets.

That´s streami is returning from the fgets.

That, I think, is why you need to identify the output you generate better, as I suggested in an earlier reply.

If that is that the client.getURI() function is putting into the stream, I think you need to look at that class to figure out why repeated gets don't return the same data.