Get http request to a working string

Hi

I have tried to get this string to work, but can't reallly figure out why it won't work, so I really hope you guys in here are able to help me out.

this get string should be converted to a string:

{
"allowed_methods": [
"PUT",
"POST",
"GET"
],
"id": 5,
"label": "",
"value": 0.0
}

This is the full code:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#ifndef STASSID
#define STASSID "wifi"
#define STAPSK "password"
#endif

String door = String ("{"allowed_methods":["PUT","POST","GET"],"id": 5,"label": "","value": 1.0}");

/* I am getting this respone when sending the GET
{
"allowed_methods": [
"PUT",
"POST",
"GET"
],
"id": 5,
"label": "",
"value": 0.0
}

*/

const char* ssid = STASSID;
const char* password = STAPSK;

int httpCode = 0;
void setup()
{

Serial.begin(115200);
WiFi.mode(WIFI_STA);

Serial.println();
Serial.println();
Serial.println();
WiFi.hostname("Test");
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");

}

Serial.println("");
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());

}

void loop() {

WiFiClient client;

HTTPClient http;

http.begin(client, "http://10.243.40.108/api/v2.0.0/registers/5");
http.addHeader("Authorization", "Basic YWRtaW46NDc2HjY5MTFmNjIyMMjM0Y2JlMTE4OWFkNjNkFhOTY2NWE0NzdmNzhhNjUzOWY1Yjk2MWQ1YjcyNjY5Ng==");
http.addHeader("Content-Type", "application/json");
// start connection and send HTTP header and body

int httpCode = http.GET();

String response = http.getString();

delay(1000);

if (response == door)
{
Serial.println("Door open");
}
if (!(response == door))
{
Serial.print("Door closed");
Serial.println(response);
}

delay(2000);

Serial.println("httpCode: ");
Serial.println(httpCode);
Serial.println("Response: ");
Serial.println(response);
delay(5000);

}

I really hope someone are able to help, I have tried googleing but haven't been able to find anything that works.

Best regards
Term

17 posts and you still haven't read the sticky post at the top of the forum about how to properly format your code inside code tags? Time to up your game....

This String

String door = String ("{\"allowed_methods\":[\"PUT\",\"POST\",\"GET\"],\"id\": 5,\"label\": \"\",\"value\": 1.0}");

will never compare to

{
    "allowed_methods": [
        "PUT",
        "POST",
        "GET"
    ],
    "id": 5,
    "label": "",
    "value": 0.0
}

since the later contains multiple newlines and lots of whitespace. Your String has none of those.
It is very unusual to compare a json response as a complete string rather than parsing that json and looking at the values.

Hi blh64

I'm sorry I will remember it the next time.
How can I check only for the values then?

best regards
Term

You parse the returned json response. Typically done by googling for such a library for arduino and then installing it, reading the documentation and looking at the examples.