I have an arduino that I’d like to use as an alternative to Zwave. However, it’s too far to hook up with any type of serial. But I have network. So I got the ethernet shield, and I’m communicating (I see all my errors in the console! )
IF anyone knows C better than me (I’m very new at arduino) and how OH expects the API call (the CURL example in the docs site doesn’t help me much)… I could use some guidance. I’m just simply trying to push “1” as a test to my item state.
The peice itself is a function I’m passing item and state into. Item being string, state being int (currently anyway).
I get this 23:22:36.966 [WARN ] [thome.io.rest.core.item.ItemResource] - Received HTTP PUT request at 'items/temperature/state' with an invalid status value ''.
I’ve tried modifying how the PUT request actually gets built but to no success.
Thanks for any input! I’m happy to share the rest of the arduino sketch if anyone is interested - But my sketch probably looks like childs play compared to people that know what they’re doing.
The reason why curl exists is that it hides a HUGE amount of specially formatted text that makes up an HTTP request.
Things I notice about the above:
examples I see include a HTTP version as the second field passed on the PUT line
there must be a blank line between Content-Length and the 1
in all the examples I’ve seen online there is always a User-Agent.
Based on the result you are seeing I’d venture to guess the main problem is the missing blank line between the header and the body.
A great way to figure this sort of thing out is to use curl with the --trace file.txt argument which will save to file.txt all of the messages sent and received. So make it work with curl, and once it works, look in file.txt to see what the actual message was that was sent and make sure what you are sending is identical, including newlines and blank lines.
Just an FYI for people checking out the REST API via an Arduino. This code can be used to send a command to the Openhab REST API. It sets the item “Wifi_switch” state to ON.
// if there's a successful connection:
if (client.connect("192.168.1.10", 8080)) {
Serial.println("connecting...");
// send the HTTP POST request:
client.println("POST /rest/items/Wifi_switch HTTP/1.1");
client.println("Host: 192.168.1.10");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.println("Content-Type: text/plain");
client.println("Content-Length: 2");
client.println();
client.println("ON");
client.println();
Serial.println("Message was sent");
} else {
// if you couldn't make a connection:
Serial.println("connection failed");
}