Collecting data from a buch of devices using UDP

Hi guys!
I’m a newbie in openHab. Nevertheless, I have already been able to implement some things successfully. I was wondering if anyone could help me out with the biggest problem. I searched unsuccessfully for a long time.

I’ve got a bunch of raspberry Pi’s that all have multiple sensors. e. g. one has 5 temperature sensors. So far I collect the data via simple scripts. I’m sending the data from all PI’s in the following format via a UDP port to the server:
[device_id: Sensor_id: Sensor_value]

(command: echo “[Datablock]” > /dev/udp/[server ip]/[some port]

Now I was going to try to integrate the sensors into openhab in the same way. There is TCP/UDP binding. But I don’t think this will work with that binding!? The data would have to be distributed to the different things according the device_ID. Is that possible in openhab? All the solutions I have found have a very large data overhad. I want to conserve network resources and processor resources on the server.


I’ve solved this by moving a little higher in the networking stack and use MQTT. You can see my script here and it works fantastically well. Since I’m using MQTT I even can tell when one of my Pis go down with the LWT messages.

I’ve seen a lot of people successfully use the UDB binding and at least as many fail. I can’t say I recommend it except as a last resort. Since you have control over the Pis and are using scripts already to publish I think your time would be better served learning and deploying MQTT than fighting with the TCP/UDP binding.

Having said that…

It should work.

First of all, there are no Things (if you are referring to OH Things) in these bindings because the TCP/UDP binding is a 1.x version binding. However, since all the data is going to the same port, you will probably have to write a Rule that triggers when a message is received on the Item bound to the UDP port and parses out the data an postUpdate the new value to the appropriate Item.

MQTT was developed to work in just such an environment, though you will be giving up some RAM to run the broker on your server in exchange for the reduction in CPU needed to parse out the data.

Wow, Richard. Thank you so much for your extensive answer. That helps me a lot. You brought much light to my darkness. I’ll take a closer look at your solution.

Gabriel :slight_smile:

I meant to post this:

That should help you get started with MQTT, at least from an OH perspective.

Great :slight_smile:

It works really well with MQTT. Thank you for the advice Richard. You were absolutely right.

1 Like