I’m trying to send the data from a co2 sensor to openhab (and show it in openhab),
this works for tago (mqtt) as such:
or waylay (rest):
But i would like to use openhab.
So i guess basically something has to be setup on openhab to listen to the data sent from the iot device,
the easiest seems via REST (as mosquitto is needed otherwise?). the iot device has built-in wifi.
From the documentation:
there is a rest api from openhab : docs/configuration/restdocs.html
i guess i also have to create a ‘thing’ with an ‘http’ binding?
The best implementation over all would be to use MQTT. The device publishes the readings and OH subscribes. This is the more efficient and responsive approach. Yes, you would still need Mosquitto for this.
Correct, with MQTT you’d install the MQTT binding and configure it to subscribe to the messages published by the device. Link that to Items and you use your Items in the rest of OH.
This tells us nothing. It’s the protocol/API that matters.
Use this if you want your device to push data into OH by having it call REST API endpoints on OH.
Use this if you want OH to poll the device by calling a REST API endpoint provided by the device itself.
I understand MQTT is more lightweight and such the preferred option, but as i gather the implementation on the device is also in plaintext (port 1883), while the REST implementation is over https in this case; so i would prefer that one to start with.
As i understand it PUSH based from the device via REST to OH, not pulled based (as the device is on a LAN for example), so i would have to use the REST api from openhab.
In which case the device will have to be able to issue an HTTP PUT or POST command with either basic authentication or an authentication token with the “message” as the body using plain/text as the encoding.
The config screen shot doesn’t appear to let you choose all of that.
Do not mistake OH’s REST API from this device’s REST API. That looks like the part of the URL OH would call (or a browser) in order to poll for and fetch the data. It’s a pull instead of a push.
If this device supports pushing to some other systems REST API, it would allow you to specify the entire URL. This device cannot dictate the API of some other system. It has to conform to that other systems API.
ok, it is a push from the device to OH, but if it doesn’t conform with the REST API of OH, then i can’t use that, tnx. Is there another way (without extra middleware), to receive in OH the pushed REST data? (some kind of listening binding for the post requests coming from the device?)
This is frustrating because you have a fundamental misunderstanding about how REST works and what push/pull means. Given this MQTT is going to be way easier to implement. And it sets you up to support all sorts of stuff because MQTT is the lingua franca of home automation and IoT world.
But if not running Mosquitto is that important that you want to do it the hard way:
Go read up some basic tutorials on how REST APIs work in general. The concepts, data paths, etc. The most important concept you must understand is that it is the client that initiates all the actions.
Decide if OH is going to pull the data from the device or the device is going to push the data to OH. It appears that the device cannot support a push at all so there’s your answer. OH needs to pull the data.
Set up OH to poll the device and pull the data periodically. And as I said above
you will have to configure openHAB with the HTTP binding to send an HTTP GET request to your device periodically and parse the result.