UPB Binding - has thrown an exception

RaspberryPi version2 using openhabian (2.5.0~S1558-1) and (2.4.0-1)
with the included java Runtime

During startup the UPB Binding keeps getting an error:

[ERROR] [org.openhab.binding.upb             ] - bundle org.openhab.binding.upb:1.14.0.201903211405 (222)[org.openhab.binding.upb.binding(186)] : The activate method has thrown an exception
java.lang.RuntimeException: Failed to open serial port.
        at org.openhab.binding.upb.internal.UPBBinding.activate(UPBBinding.java:81) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
        at org.apache.felix.scr.impl.inject.methods.BaseMethod.invokeMethod(BaseMethod.java:228) ~[?:?]
        at org.apache.felix.scr.impl.inject.methods.BaseMethod.access$500(BaseMethod.java:41) ~[?:?]
        at org.apache.felix.scr.impl.inject.methods.BaseMethod$Resolved.invoke(BaseMethod.java:664) ~[?:?]
        at org.apache.felix.scr.impl.inject.methods.BaseMethod.invoke(BaseMethod.java:510) ~[?:?]
        at org.apache.felix.scr.impl.inject.methods.ActivateMethod.invoke(ActivateMethod.java:317) ~[?:?]
        at org.apache.felix.scr.impl.inject.methods.ActivateMethod.invoke(ActivateMethod.java:307) ~[?:?]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:341) ~[?:?]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:114) ~[?:?]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:983) ~[?:?]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:956) ~[?:?]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:901) ~[?:?]
        at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse$1.run(ServiceFactoryUse.java:212) ~[?:?]
        at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
        at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.factoryGetService(ServiceFactoryUse.java:210) ~[?:?]
        at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.getService(ServiceFactoryUse.java:111) ~[?:?]
        at org.eclipse.osgi.internal.serviceregistry.ServiceConsumer$2.getService(ServiceConsumer.java:45) ~[?:?]
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:508) ~[?:?]
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.getService(ServiceRegistry.java:461) ~[?:?]
        at org.eclipse.osgi.internal.framework.BundleContextImpl.getService(BundleContextImpl.java:624) ~[?:?]
        at com.eclipsesource.jaxrs.publisher.internal.ResourceTracker.addingService(ResourceTracker.java:39) ~[?:?]
        at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941) ~[?:?]
......
<snip>

I’ve tested with on my Synology Slim414 and RaspberryPi with the same results when using the SmartAutomation USB PIM. There isn’t much online to help sort this out. The Synology is using OpenJDK and after reading this might cause problems with some bindings. I moved to my RPi with 2.4.0-1 with the same result. I decide to use the Snapshot update to see if there was a fix, but no change is behavior.

Any help would be appreciated

Searching this forum for serial port problems should give you the means to check what ports exist, permissions, etc.

I did some searching tried the following:

sudo usermod -a -G dialout openhab

awk -F’:’ ‘/dialout/{print $4}’ /etc/group

openhabian,openhab

sudo adduser openhab dialout

The user `openhab' is already a member of `dialout'.

And I also uncommented the line in /etc/default/openhab2:

EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyS0:/dev/ttyS2:/dev/ttyACM0:/dev/ttyAMA0"

Same results

Try adding the user named pi to the tty and dialout Linux groups

The current UPB binding you can install through the paper ui doesn’t seem to work at all.

That said, you still have to get your system configuration into a place where the binding isn’t throwing exceptions, regardless of whether you use the binding installable through the paper UI or from the jar file.

My system

Release = Raspbian GNU/Linux 10 (buster)
Kernel = Linux 4.19.75-v7+
Platform = Raspberry Pi 3 Model B Plus Rev 1.3
ModMyPi Serial HAT from pishop

I had to do all of the following to get UPB to stop throwing exceptions and to be able to actually send traffic (using echo test12345 > /dev/serial0) on the serial port.

Openhabian Configuration tool

Use the configuration tool to enable all three serial port options:
openhabian-config 🡒 30 System settings 🡒 34 Prepare serial port 🡒

 1 (RPi) Disable serial console
 2 (RPi3) Disable Bluetooth module
 3 Add common serial ports to openHAB JVM

…except that this didn’t actually seem to do the job, so then I went and did the same things manually.

Raspberry Pi 3 + serial port (on GPIO 14 & 15) UART issues

  1. Disable the serial console, i.e. prevent the raspbian linux installation from sitting on the port, by removing the following from /boot/cmdline.txt:
    console=serial0,115200
    
  2. Move the bluetooth to the mini-uart, by adding the following to /boot/config.txt:
    enable_uart=1
    dtoverlay= pi3-miniuart-bt
    core_freq=250
    

Now when you boot the system you’ll have:

  • /dev/serial0 -> ttyAMA0, the serial port
  • /dev/serial1 -> ttyS0, the bluetooth module

Both of these belong to the dialout group.

These symlinks will reliably point at those specific devices, which helps avoid headaches.

Java serial port access

Uncomment one of the appropriate lines in /etc/default/openhab2 – specifically, you need at least:

EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts/dev/serial0"

UPB binding configuration

Finally, the UPB binding also needs to know which TTY is the serial port, which is specified in $OPENHAB_CONF/services/upb.cfg:

port=/dev/serial0

Testing

I used a null modem adapter and a gender changer to hook a serial cable from the pi to a usb-serial adapter on my Windows machine. For sniffing the traffic, I used ComDebug, which is free. You can simply do mode in a windows command prompt to get the COM port, baud, parity and data bit settings you need to enter in ComDebug. If you’re using a USB adapter, as I did, it’ll almost certainly be the highest-numbered COM port, but you can verify that in Device Manager.

A loopback cable (made by shorting pins 2 and 3, i.e. Rx and Tx) should also let you test the serial port itself.