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