/dev/ttyUSB0 No such port - AGAIN

I’ve read probably 20 threads about this problem here in the forum and on the internet but still I can’t get it working…
I use the binding MySensors. The instillation went well and I could add the Port Settings in the PaperUI.

However I get this error:

06:13:46.071 [DEBUG] [ocol.serial.MySensorsSerialConnection] - Connecting to /dev/ttyUSB0 [baudRate:115200]
06:13:46.072 [ERROR] [ocol.serial.MySensorsSerialConnection] - No such port: /dev/ttyUSB0

gnu.io.NoSuchPortException: null
at gnu.io.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:273) ~[260:com.neuronrobotics.nrjavaserial:3.15.0.OH2]
at org.openhab.binding.mysensors.internal.protocol.serial.MySensorsSerialConnection.establishConnection(MySensorsSerialConnection.java:51) [275:org.openhab.binding.mysensors:2.4.0.201812040738]
at org.openhab.binding.mysensors.internal.protocol.MySensorsAbstractConnection.connect(MySensorsAbstractConnection.java:148) [275:org.openhab.binding.mysensors:2.4.0.201812040738]
at org.openhab.binding.mysensors.internal.protocol.MySensorsAbstractConnection.run(MySensorsAbstractConnection.java:127) [275:org.openhab.binding.mysensors:2.4.0.201812040738]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
at java.lang.Thread.run(Thread.java:748) [?:?]

OpenHab is running in a docker container with those additional arguments:

EXTRA_JAVA_OPTS = -Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0

devices:

/dev/USB0:/dev/USB0

So /dev/ttyUSB0 is for sure the right port.
I can read the data with

cat /dev/ttyUSB0

On the linux server and when I go to the docker with:

docker exec -it openhab /bin/bash

I can also read the serial port by using the same command:

cat /dev/ttyUSB0

I also added:

adduser openhab dialout
adduser openhab tty

but somehow each time I restart the docker I need to add the

adduser openhab tty

command again…

when I enter this command:

docker lgs openhab

I get a long list with this error:

java.lang.NoClassDefFoundError: Could not initialize class gnu.io.RXTXCommDriver thrown while loading gnu.io.RXTXCommDriver

What else can I do what might be the problem?

1 Like

I think I once read that when using Docker the ports may not be immediately available and sleeping a couple of seconds before starting OH may help by adding a startup script:

Does it also work if you restart the binding again using the Console? If so, the binding may be missing serial port reconnection logic which would make it a lot more stable.

So I restarted the binding but no success:

06:37:25.990 [DEBUG] [org.openhab.binding.mysensors ] - BundleEvent STOPPED - org.openhab.binding.mysensors
06:37:25.992 [DEBUG] [org.openhab.binding.mysensors ] - BundleEvent STARTING - org.openhab.binding.mysensors
06:37:25.993 [DEBUG] [org.openhab.binding.mysensors ] - BundleEvent STARTED - org.openhab.binding.mysensors
06:37:25.999 [DEBUG] [org.openhab.binding.mysensors ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory}={service.id=507, service.bundleid=275, service.scope=bundle, component.name=org.openhab.binding.mysensors.factory.MySensorsHandlerFactory, component.id=339} - org.openhab.binding.mysensors
06:37:26.054 [DEBUG] [ensors.handler.MySensorsBridgeHandler] - Initialization of the MySensors bridge
06:37:26.054 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - ‘mysensors:bridge-ser:616dc2bb’ changed from UNINITIALIZED (HANDLER_MISSING_ERROR) to INITIALIZING
06:37:26.055 [DEBUG] [sensors.factory.MySensorsCacheFactory] - Cache file: given_ids.cached exist.
06:37:26.056 [DEBUG] [sensors.factory.MySensorsCacheFactory] - Cache (given_ids) content: []
06:37:26.057 [DEBUG] [ocol.serial.MySensorsSerialConnection] - Enabling connection watchdog
06:37:26.066 [DEBUG] [ocol.serial.MySensorsSerialConnection] - Connecting to /dev/ttyUSB0 [baudRate:115200]
06:37:26.066 [DEBUG] [org.openhab.binding.mysensors ] - ServiceEvent REGISTERED - {org.eclipse.smarthome.config.discovery.DiscoveryService}={service.id=508, service.bundleid=275, service.scope=singleton} - org.openhab.binding.mysensors
06:37:26.066 [ERROR] [ocol.serial.MySensorsSerialConnection] - No such port: /dev/ttyUSB0

If it never works it may also be a permissions problem or Docker configuration problem. On some Synology NASes you also need to load extra kernel modules for serials comms to work.

It has never worked yet (just trying now for 2 days)
Its a normal server no NAS etc with an Intel Xeon processor running in VM.
But why can I read data (with cat) in the docker itself but openhab can’t?

the user 9001 that is used for openhab according to the docker has those writes on the mail system:

id openhab
uid=9001(openhab) gid=9001(openhab) groups=9001(openhab),5(tty),20(dialout)

How did you pass the EXTRA_JAVA_OPTS to the container?

over the ENV option:

It looks good to me! Maybe @TimO can help?

Have you added that port to the EXTRA_JAVA_OPTS in the start.sh file? I recently went through some port troubleshooting and found this in the OH documentation.

Tried to do taht but failed because of the permission.
I made a start.sh file in the conf folder:

-rwxrwxrwx+ 1 openhab openhab 122 Nov 7 11:04 start.sh

then I pointed the start command to this folder and script:

gosu openhab tini -s ./conf/start.sh

But I get:

  • exec gosu openhab tini -s ./conf/start.sh
    [FATAL tini (22)] exec ./conf/start.sh failed: Permission denied

What kind of permission does the start.sh need

even when I directly copy the start.sh inside the container to the conf folder I get the same permission error

so I made a new docker file to test if it would work. However I’m not sure how to add the Paramter to the start.sh file. My Start.sh file now looks like this:

#!/bin/sh

echo Launching the openHAB runtime…

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

DIRNAME=dirname "$0"
exec “${DIRNAME}/runtime/bin/karaf” “${@}”

I have also had success adding the OPTS string to /etc/default/openhab2 configuration file to resolve my test issue That file needs to be edited as root

hmm cant find this “file”, can you show me a console output

Have you tried reading the port as the openhab user inside the container?

su - openhab -c 'cat /dev/ttyUSB0'

Just a thought, it may reveal an error, or confirm that the permissions are not the issue.

From what I understand from a GitHub issue I opened for a different binding, there are different ways the binding uses to access the serial port device.

See here.

this works wihtout a problem:

root@openhab:/openhab# su - openhab -c ‘cat /dev/ttyUSB0’
0;255;3;0;9;10027 TSM:FAIL:RE-INIT
0;255;3;0;9;10030 TSM:INIT
0;0;255;3;0;9;0 MCO:BGN:INIT GW,CP=RNNGA—,REL=255,VER=2.3.1
0;255;3;0;9;5 TSM:INIT
0;255;3;0;9;7 TSF:WUR:MS=0
0;255;3;0;9;14 !TSM:INIT:TSP FAIL
0;255;3;0;9;17 TSM:FAIL:CNT=1
0;255;3;0;9;20 TSM:FAIL:DIS
0;255;3;0;9;22 TSF:TDI:TSL

Please post logs and code using code fences, it makes them easier to read. There are buttons above the edit box for a post to insert them for you.

This is interesting, it sounds like you’re missing a driver possibly? Or you’ve specified the wrong thing in your Java extra options?

Also for the record I have yet to use any serial bindings, but I do run openhab in docker. I’m just coming at this with general diagnostic questions.

I need the serial interface for the MySensor Binding. The instruction I used is from here: