if http get request response contains specific response

Hi

Is there anyone in here there is able to help me out with this little code problem.

In my code I'm sending this get request:

WiFiClient client;

HTTPClient http;

http.begin(client, "http://"SERVER_IP"/do_value/slot_0/ch_0");
http.addHeader("Authorization", "Basic cm9vdDowMDAwMDAwMA==");
//http.addHeader("Content-Type", "application/json");
Serial.println("[HTTP] GET...\n");
Serial.println("2......");
// start connection and send HTTP header and body

int httpCode = http.GET();

String response = http.getString();

Serial.print("StatusCode: ");
Serial.println(httpCode);
Serial.print("Response: ");
Serial.println(response);

if (response == {"Ch":0,"Md":0,"Val":1,"Stat":0,"PsCtn":0,"PsStop":0,"PsIV":0})
{
digitalWrite(module,HIGH);
}

I want to set module HIGH if the val=1

I hope someone is able to help me out.

Best regards Term

in the seriel monitor I get this response:

StatusCode: 200
Response: {"Ch":0,"Md":0,"Val":0,"Stat":0,"PsCtn":0,"PsStop":0,"PsIV":0}

and it is the if response that doesn't work

if (response == {"Ch":0,"Md":0,"Val":1,"Stat":0,"PsCtn":0,"PsStop":0,"PsIV":0})

You need to compare the result to a String or string constant

Hi MarkT

Thanks, I have now created:

String restgetstring = String("{"Ch":0,"Md":0,"Val":1,"Stat":0,"PsCtn":0,"PsStop":0,"PsIV":0}");

but now I get this errorcode: restgetstring was not declared in this scope

how do I solve that?

Best regards
Term

I found the problem and it is now working with the full string.
Thanks alot :slight_smile: