openhab-addons icon indicating copy to clipboard operation
openhab-addons copied to clipboard

[serial] Add TCP and binary protocol support

Open Cybso opened this issue 1 year ago • 7 comments

[serial] Added TCP and binary protocol support to serial binding

I have added some features to org.openhab.binding.serial which might be interesting to be included in the main branch.

  1. I have added a special "charset=HEX" which allows to handle binary protocols. Each incoming data is converted into hexadecimal strings separated by space, for example "test" becomes "74 65 73 74". When using charset=HEX you have also to define a regular expression to recognize "line endings" in "eolPattern", for example "\bFF" for 0xFF or "\b0A" for newlines.

  2. I have added channel parameters "refreshValue" and "refreshInterval". These can be used for protocols that require channel data to be pulled from the device.

  3. I have added TCP as an alternative bridge thing to this binding (TcpDeviceHandler). Since there is nothing like a SerialPortEvent for TCP Sockets, this mode will schedule a background thread instead that looks for available data every 250ms. To avoid the maintenance of duplicate code I have extracted the common parts of SerialDeviceHandler and TcpDeviceHandler into a new abstract class CommonDeviceHandler.

This pull request should fix the following requests:

https://github.com/openhab/openhab-addons/issues/10428

https://community.openhab.org/t/openhab-3-tcp-binding/111896

https://community.openhab.org/t/help-with-binary-data-serial-binding-3-1/126859

and maybe others.

Cybso avatar Jan 04 '24 16:01 Cybso