- Platform information:
- Hardware: Raspberry
- OS: openhabianpi
- openHAB version: 2.4
- Issue of the topic: HTTP 405 , trying to send / set Temperaturvalue with JSON
Hi,
I’am trying to send a Temperaturvalue with JSON and just change the “state” of the item. But I always get a “HTTP error 405 Method not allowed”
Here is the code for the ESP (only the interesting part):
StaticJsonBuffer<200> JSONbuffer;
JsonObject& JSONencoder = JSONbuffer.createObject();
JSONencoder[“state”] = “21”;
char JSONmessageBuffer[200];
JSONencoder.prettyPrintTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
Serial.println(JSONmessageBuffer);
HTTPClient http;
http.begin(“http://Openhabserver:Port/rest/items/Temperatur_1/state”);
http.addHeader(“Content-Type”, “text/plain”);
int httpCode = http.POST(JSONmessageBuffer);
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
Here is the console-output:
22:05:22.065 -> Waiting for connection
22:05:22.065 -> {
22:05:22.065 -> “state”: “21”
22:05:22.065 -> }
22:05:22.112 -> 405
22:05:22.112 -> {“error”:{“message”:“HTTP 405 Method Not Allowed”,“http-code”:405,“exception”:{“class”:“javax.ws.rs.NotAllowedException”,“message”:“HTTP 405 Method Not Allowed”,“localized-message”:“HTTP 405 Method Not Allowed”}}}
From my understanding it’s possible to change value over the REST-API. Is JSON the wrong starting point ?
thanks in advance
regards, Dirk