after substring of a stream no more data

Hello,

i'm trying to get data from my printserver via Api. I'm using an Arduino yun for this and the bridge / httpclint library. The firsttime the code runs everything is fine. When the second turn comes (after 30 Seconds) i get no data at all. Can anybody thell me why?

void getResponceFromRepetier() {
  HttpClient client;
  String response;
  
  client.get("http://192.168.8.8:3344/printer/api/?a=listPrinter&apikey=177a3e07-1307-403a-aca5-fc267ed7bbb0");
  // int tempStartPosition;
  // int tempEndPosition;

  while (client.available()) {
    response = client.readString();

  }

  namePrinter1 = response.substring(37 , 57);
  Serial.println(response);
  display.setTextSize(1);
  display.setCursor(0,20);
  display.print("            ");
  display.setCursor(0,20);
  display.print(namePrinter1);
  display.print(":");
  display.display();

}

namePrinter1 is declared as String, whe i take away the line

namePrinter1 = response.substring(37 , 57);

i get the correct response in the serial console.

What am i doing wrong?

Steve

Please post all your code or a representative example that exhibits the problem. The symptoms of problems might show in the code that you showed but the root cause might be somewhere else.

If you're using an AVR based Arduino, use of the String class is not advisable.

How many characters are in the response? Can you post an example of the response?

Hello,

the code ist aktuell very lang spred over several Taps, I can post ist but it will be a lot

[{"active":true,"job":"none","name":"Ultimaker 2+ Extended","online":1,"pauseState":0,"paused":false,"slug":"Ultimaker_2"}]

This is the respons i get from the server

if you tehll me wich parts you need to see, i can post the, or i needed all the horroful nebee Code :smiley:

Steve

Chaos_Lord:
i'm trying to get data from my printserver via Api. I'm using an Arduino yun for this

If you have Yun wouldn't it be much easier to do this using Python on the Linux side?

...R

got that thing on saturday and theses ar my first steps with it, so i can not tell you if it would be easier :smiley:

But becaus i do not know anything yet about pyhton i would need some hints how to do it…

Sorry, missed the fact that you are using a Yun.

i found my error. I have to convert the serial read to fit in the string

 while (client.available()) {
  response += (char)client.read();
}

After i cahnged this it is working.

I'll look in the phyton thing. sounds interesting.

Thanks everyone