Pages: [1]   Go Down
Author Topic: Reading an Internet String  (Read 221 times)
0 Members and 1 Guest are viewing this topic.
Netherlands
Offline Offline
Newbie
*
Karma: 1
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,

I have the following code:

Code:
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.
Logged

Netherlands
Offline Offline
Newbie
*
Karma: 1
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Netherlands
Offline Offline
Newbie
*
Karma: 1
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Serial ouput:

Code:
<0>10</0>
<1>25</1>
<2>0</2>
<3>0</3>
<0></0>
Logged

Pages: [1]   Go Up
Jump to: