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

Add new Serial Transport based on jSerialComm

Open mvalla opened this issue 1 year ago • 20 comments

Add a new OH Serial Transport bundle org.openhab.core.io.transport.serial.jserialcomm based on https://fazecast.github.io/jSerialComm/.

From website: jSerialComm is a Java library designed to provide a platform-independent way to access standard serial ports without requiring external libraries, native code, or any other tools. It is meant as an alternative to RxTx and the (deprecated) Java Communications API, with increased ease-of-use, an enhanced support for timeouts, and the ability to open multiple ports simultaneously.

The library seems actively maintained, it supports Apple Silicon, has no dependecies, and also supports LISTENING_EVENT_PORT_DISCONNECTED events (supported by NRJavaSerial and not by Pure Java Comm), useful nowdays that Serial ports devices are via USB and therefore can be unplugged. The library has also support for USB specific info (productID/serialNumber/vendorID/product description) when available. It's double licensed LGPL 3.0 and Apache 2.0.

There is already another OH binding using jSerialComm: ProteusEcoMeter (not using OH Serial Transport).

Before starting implementation on a new PR, I would like to have opinion of @openhab/core-maintainers on this issue.

See also https://github.com/mvalla/openwebnet4j/issues/34#issuecomment-1819091617

mvalla avatar Dec 30 '23 09:12 mvalla

I think it is useful to have alternative implementations besides nrjavaserial to also support platforms that aren't supported or don't work well with nrjavaserial.

jSerialComm seems to have been considered earlier but because it used LGPL the Kura serial implementation was added to Eclipse SmartHome. Which is still there but probably unused.

If jSerialComm has better features, works well and is more maintained it may also be preferred to #3632.

wborn avatar Dec 30 '23 10:12 wborn

jSerialComm seems to have been considered https://github.com/openhab/openhab-addons/pull/2246#issuecomment-333211911 but because it used LGPL

It seems now jSerialComm it's double licensed LGPL 3.0 and Apache 2.0.

mvalla avatar Dec 30 '23 11:12 mvalla

@mvalla how does this work with, for example, the Zigbee Binding? I have a Sonoff Zigbee Dongle I'd like to use with openHAB on OpenBSD. RXTX is unsupported on OpenBSD so I'd love to swap this in and give it a test.

realPyR3X avatar Mar 13 '24 02:03 realPyR3X

Which Sonoff Zigbee Dongle you have exactly? Is it supported by openHAB in general? Link to product ?

mvalla avatar Mar 14 '24 03:03 mvalla

SONOFF Zigbee 3.0 USB Dongle Plus V2 (ZBDongle-E) Serial Interface Protocol: EmberZNet (EZSP) Supported in openHAB

OpenBSD dmesg:

umodem0 at uhub2 port 3 configuration 1 interface 0 "ITEAD SONOFF Zigbee 3.0 USB Dongle Plus V2" rev 1.10/4.42 addr 2 umodem0: data interface 1, has no CM over data, has no break

https://sonoff.tech/product/gateway-and-sensors/sonoff-zigbee-3-0-usb-dongle-plus-p/

realPyR3X avatar Mar 14 '24 11:03 realPyR3X

@mvalla any thoughts? I'd love to test this

realPyR3X avatar Apr 16 '24 18:04 realPyR3X

Feel free to try it: support of serial communication using jSerialComm is not 100% complete but maybe what is missing can be added thanks to some testing

mvalla avatar Apr 17 '24 11:04 mvalla

Is there a packaged jar or kar I can deploy to test?

realPyR3X avatar Apr 17 '24 12:04 realPyR3X

here you are:

you should remove .TXT from the file names, copy the jars to the addons folder of OH and from the OH Karaf console you now should be able to see these budles as Active:

  178|Active     |    1|openHAB Core :: Bundles :: Serial Transport (4.2.0.202404150308)|4.2.0.202404150308
  179|Active     |    1|openHAB Core :: Bundles :: Serial Transport for RXTX (4.2.0.202404150309)|4.2.0.202404150309
...
  183|Active     |    1|jSerialComm (2.11.0)|2.11.0
  184|Active     |    1|openHAB Core :: Bundles :: Serial Transport for jSerialComm (4.2.0.202404182122)|4.2.0.202404182122

then to make sure only the new bundle is used, again from Karaf you should de-activate this bundle: bundle:stop 179 (where 179 in my case is the bundle id for "Serial Transport for RXTX" bundle, the default one)

From now on any use of the serial port in OH should use the new library.

Let me know!

mvalla avatar Apr 18 '24 21:04 mvalla

@realPyR3X did you have time to test it?

mvalla avatar May 10 '24 19:05 mvalla

@mvalla I somehow missed this response from you 3 weeks ago. I was able to get "purejavacomm" working in the interim. by doing the same approach with stopping rxtx. I will swap that out for this and give it a test.

realPyR3X avatar May 10 '24 19:05 realPyR3X

@mvalla org.openhab.core.io.transport.serial.jserialcomm-4.2.0-SNAPSHOT.jar is not deploying from addons. The jSerialComm deploys but obviously doesn't start because it's missing the imports from the transport package:

    org.openhab.core.io.transport.serial;
            version="[4.2,5)",
    org.openhab.core.io.transport.serial.jserialcomm

realPyR3X avatar May 10 '24 20:05 realPyR3X

The jSerialComm deploys but obviously doesn't start because it's missing the imports from the transport package:

that is because this jserialcomm addon is meant to be run on a OH 4.2 branch.. You could use one of the Milestone releases if you want

mvalla avatar May 10 '24 20:05 mvalla

@mvalla actually I said that wrong jSerialcomm deploys but your transport doesn't It appears your are importing:

org.openhab.core.io.transport.serial;version="[4.2,5)"

This isn't resolving the version should probably be 4.1 are you on a dev branch?

The transport serial exports:

Export-Package = org.openhab.core.io.transport.serial;version=4.1.2

realPyR3X avatar May 10 '24 20:05 realPyR3X

lol we commented at the same time. Can I just edit the manifest for now or does it have to be on a milestone

realPyR3X avatar May 10 '24 20:05 realPyR3X

I think editing the manifest should do the trick: org.openhab.core.io.transport.serial;version="[4.2,5)" -> "[4.1,5)"

mvalla avatar May 10 '24 20:05 mvalla

@mvalla I set it to 4.1.2 to match the others. The bundle is active. Unfortunately my zigbee ember chipset can't open the serial devices.

realPyR3X avatar May 10 '24 20:05 realPyR3X

ok, if you set log level to DEBUG for org.openhab.core.io.transport.serial.jserialcomm and copy here the log when you try to open the serial device, that would help to solve incompatibility

mvalla avatar May 10 '24 21:05 mvalla

@mvalla it works! I had an error in the manifest I edited. The chipset is online.

realPyR3X avatar May 10 '24 21:05 realPyR3X

@mvalla what will it take to get this to replace rxtx as the default serial transport? If not the default, what will be the process to enable it? i.e. disable rxtx through console and start the feature?

realPyR3X avatar May 11 '24 02:05 realPyR3X