Go Down

Topic: Reading an Internet String (Read 277 times) previous topic - next topic

DieterKoblenz

Hi guys,

I have the following code:

Code: [Select]
void antwoord()
{


  for (int t=0; t <= 4; t++){

    String user = String(t);
    String ein = "<";
    String zwei = user;
    String drei = ">";
    String xxx = "/";
    String response = ein + zwei + drei;
    String endresponse = ein + xxx + zwei  + drei;
   
    Serial.print(response);
    Serial.println(endresponse);
    Serial.println(http_response);

    if((http_response.indexOf(response) > -1 )&&(http_response.indexOf(endresponse) > -1 )){
      // We check if the <arduino></arduino> are there.
      response_start = http_response.indexOf(response)+3;
      // Where it begins, the 9 is the length of ' <arduino> ',
      // since we dont want it to appear in the response.
      response_end = http_response.indexOf(endresponse);
      // Where it ends
      http_response = http_response.substring(response_start,response_end);
      // We keep only the response of the website
      Serial.println("Website response : ");
      Serial.println(http_response);
      Serial.println();
      delay(100);

      int Plus = http_response.toInt();
      int Saldo = EEPROM.read(t);
      int NewSaldo = Saldo + Plus;
      Serial.println("New Saldo: ");
      Serial.println(NewSaldo);
      Plus = 0;
      Saldo = 0;
      NewSaldo = 0;
      http_response = 0;

    }
    else {
      Serial.println("No response detected...");
      Serial.println();
    }

  }


It is supposed to take the value's between <t> and </t> and use it to add its content to the integer Saldo. This works for the first run (t=0) but after that t=1,2,3 give me no response detected.

Not sure how this happens.

DieterKoblenz

Never mind, I read over the obvious mistake. http_response is ofcourse the parsed version of the orginal so calling it again will detect nothing.

PaulS

You get Serial output? You don't want to share that? You want us to guess what is happening? Pass.

DieterKoblenz

Serial ouput:

Code: [Select]
<0>10</0>
<1>25</1>
<2>0</2>
<3>0</3>
<0></0>

Go Up