Esp8266 Arduino uno project strange string behavior

Hey guys a have strange problem. I have an esp8266 connected to arduino uno with softwareserial. I am trying to update and read data from thingspeak but when i read the data to a string u can print out the response but u can’t do anything with it can’t copy it can’t send it to another function can’t use substring etc… I am going to chew my keybord please some body help. I am writing down the function and attaching the whole program…thanks

void ReadThingSpeakChannel(int _results,String _channelid){
ThingspeakClient.print(“GET /channels/”);
ThingspeakClient.print(_channelid);
ThingspeakClient.print("/feeds.json?api_key=");
ThingspeakClient.print(read_api_key);
ThingspeakClient.print("&results=");
ThingspeakClient.print(String(_results));
ThingspeakClient.println(" HTTP/1.0");
ThingspeakClient.println();
delay(500);
int x = 0;
while (ThingspeakClient.available()) // wait till something comes in; you may want to add a timeout here
String AnswerOfRequest = ThingspeakClient.readString();
ThingspeakClient.stop(); // close socket

Serial.println(“Printing AnswerOfRequest…”);
Serial.println(AnswerOfRequest);
//Serial.println(“Starting index: " + String(AnswerOfRequest.indexOf(”{“channel”:")));
//int Start = AnswerOfRequest.indexOf("{“channel”:");
//int End = AnswerOfRequest.indexOf(“3,CLOSED”);

//Serial.println("start " + String(Start) + "end " + String(End));
//Serial.println(AnswerOfRequest.substring(208));

//ParseJson(AnswerOfRequest);
}

ArduinoUnoEsp8266HomeAutomation.ino (6.19 KB)

Are you defining the String within the function and it goes out of scope when you exit the function?

String AnswerOfRequest = ThingspeakClient.readString();

You shouldn't use the String class on AVR Arduinos as it fragments the memory very fast and sooner than you think you run out of memory. My guess is that exactly this happens in your sketch.

BTW, your code doesn't compile because this line

 while (ThingspeakClient.available())                        // wait till something comes in; you may want to add a timeout here

is missing a semicolon.

So what am i going to use instead?

C strings, i.e. null terminated arrays of char.