openhab / openhab-core

Core framework of openHAB
https://www.openhab.org/
Eclipse Public License 2.0
925 stars 425 forks source link

Add new Serial Transport based on jSerialComm #3982

Open mvalla opened 10 months ago

mvalla commented 10 months ago

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

wborn commented 10 months ago

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.

mvalla commented 10 months ago

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.

realPyR3X commented 8 months ago

@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.

mvalla commented 8 months ago

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

realPyR3X commented 8 months ago

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 commented 6 months ago

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

mvalla commented 6 months ago

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

realPyR3X commented 6 months ago

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

mvalla commented 6 months ago

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 commented 6 months ago

@realPyR3X did you have time to test it?

realPyR3X commented 6 months ago

@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 commented 6 months ago

@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
mvalla commented 6 months ago

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

realPyR3X commented 6 months ago

@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 commented 6 months ago

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

mvalla commented 6 months ago

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

realPyR3X commented 6 months ago

@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.

mvalla commented 6 months ago

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

realPyR3X commented 6 months ago

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

realPyR3X commented 6 months ago

@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?