General question regarding TCP/UDP Binding/Setup Server and Item config

Hello!

I am desperately trying to get the TCP/UPD Binding to work.
What i want to achieve:
Receive data (in a later use-case maybe send data) from (to) my arduino node mcu wifi board.
I built a small battery powered room sensor for temperature pressure and humidity and now i want to send the values to OH 2.
I created an item as described in the readme to receive the temp for instance:

String WoZi_String_Temperatur "Wohnzimmertemperatur" {tcp="<[127.0.0.1:80:'REGEX((.*))']"}

The first part (127.0.0.1) is the IP Adress of the server created from OH? Is that right? The second part the port?
I also configured the port (80) in the tcp.cfg-file. That was the only thing i wrote into the config file.

I am not getting any data from my arduino client although i am connected to my wifi correctly. Maybe there is an issue with the arduino tcp client. I just want to make sure that OH is configured correctly so i can look for the problems at the right place.

Thank you!

hi jonas,

did you check the docs on this - they’re usually pretty straight-forward:
https://docs.openhab.org/addons/bindings/tcp1/readme.html#item-configuration

tl;dr>
tcp="<direction>[<command>:<ip address>:<port>:<transformationrule>]

so, your item Definition seems to be correct.

  1. what does events.log say?
  2. do you send the packet from arduino side? or do you Need polling?
  3. if the string is already formed as you’d like from your arduino, just type “default” (and temperature should be a Number, if you’d like to work with it
  4. be aware, that items, which are not declared properly won’t show in the UI, you’re missing the label, in your case it would be something like
    String WoZi_String_Temperatur "Wohnzimmertemperatur [%s]" {tcp="<[127.0.0.1:80:default]"}, but if you have an integer already:
    Number WoZi_Integer_Temperatur "Wohnzimmertemperatur [%.1f °C]" {tcp="<[127.0.0.1:80:default]"}

The ip address in the binding paprameters needs to be the tcp server. ie: where the data is published, your arduino. Is your arduino set-up as a tcp server?
There are much easier and more reliable ways to send data from a nodeMCU.

MQTT comes to mind…

use the pubsubclient library for arduino
Install mosquitto on your openHAB computer
Install the mqtt binding in OH

And read the docs, please

oh yes! slipped my mind - localhost (127.0.0.1) won’t work in any case! :wink:

Hello!
Thanks a lot for your replies!
I thought that i can create a TCP server with the OH 2 binding. I did not know that the server has to be the arduino.
I am open minded for every way to get the data transfer working and i will take a deep look at MQTT! Thanks a lot!

MQTT is arguably the best way to get data from arduino to OH

See this thread:

That’s for OH and the mqtt broker installation

On the arduino side, you need to use the pubsubclient library (Other flavours available). It is available in the arduino IDE library downloads and comes with examples

Follows the link above especially the MQTT essentials to understand how MQTT works (Simple really)

Read the docs, read them again and when you have finished read them one more time.

Openhab MQTT binding doc:
https://docs.openhab.org/addons/bindings/mqtt1/readme.html

Good luck

I’ll second MQTT. In the long run you will have far more capability for far less effort compared to trying to roll your own low level protocol using TCP/UDP.

I aready read a lot about it and ill try to implement it this weekend. Thank you!