openhab-addons
openhab-addons copied to clipboard
[serial] Add TCP and binary protocol support
[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.
-
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.
-
I have added channel parameters "refreshValue" and "refreshInterval". These can be used for protocols that require channel data to be pulled from the device.
-
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 ofSerialDeviceHandler
andTcpDeviceHandler
into a new abstract classCommonDeviceHandler
.
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.