Hi all, I would need some support to understand how TCP binding works in OpenHab 2.x.
Up to know, I was using OpenHab 1.x with serial binding, so I have some experience on that.
My goal is making OpenHab (OH in the later) communicating with an application (APP in the later) of mine, running on the same Linux PC. I’d like to use this “external” APP to achieve proper level of flexibility within the logics I need to implement. So I am intended to use TcpBinding, with APP acting as a TCP server and OH as TCP client, over 127.0.0.1 (localhost on same PC).
Of course let me know if I have some alternatives to make OH and APP communicating each other,.
Currently I succeeded to TRANSFER data from OH to APP by adding .items
file:
Switch AppliqueSwitch "Applique" <none> (GrFloor, gAppl) {tcp="[ON:192.168.1.2:1234:'myCustomOnString'], >[OFF:192.168.1.2:1234:'myCustomOffString']"}
I can see 2x connections in my APP where I can receive myCustomOnString and myCustomOffString over TCP when sliding the AppliqueSwitch by the GUI; so far so good.
What I am struggling is how to RECEIVE from APP to OH. I browsed a lot but, sadly, I must say there is too poor documentation which do not clarify what-to-do, what is possible to do or not to do.
Anyway, I did some trials:
- I added to
.items
file:
String TcpRx "TcpRx" {tcp="<[192.168.1.2:1234:default]"}
- I sent from APP the string MYSAMPLESTRING to estabilised OH connection
- I can see in OH logs in
/var/log/openhab2/
[WARN ] [ing.tcp.protocol.internal.TCPBinding] - Cannot parse input MYSAMPLESTRING to match command OFF on item AppliqueSwitch
[WARN ] [ing.tcp.protocol.internal.TCPBinding] - Cannot parse input MYSAMPLESTRING to match command ON on item AppliqueSwitch
respectively when I send data from TCP server to first or second connection from OH.
This happens even without configuring the tcp.cfg
file in the field descirbed in https://www.openhab.org/addons/bindings/tcp1/
So it sounds that my custom MYSAMPLESTRING is being received in OH, but I don’t know how to use it. I think I need to create somehow a rule in .rules
file to parse it and perform some logic, but I am getting confused at this point, since it is not clear what should be configured and where, what syntax should be used, which files should be affected.
It would be enough just receiving some string/data from TCP server and move the relevant switch accordingly.
Can you please give me some hints? How can I receive my own data from APP to OH?
Regards,
Enzo