Serial port gone?

Running 3.3 release, the USB serial adapter ports of my Raspi vanished from openHAB after a reboot.
Things to use them remain offline claiming “No such port /dev/ttyUSB2”.
But the ports ARE there from the OS perspective. 3 adapter with a CH341 chipset if that matters.

I’ve already selectively restarted the serial related bundles, and explicitly started java with but no luck.

Debugging of serial transport tells me:

2022-09-22 11:16:42.646 [DEBUG] [ort.serial.internal.RxTxPortProvider] - No SerialPortIdentifier found for: /dev/ttyUSB2
2022-09-22 11:16:42.953 [DEBUG] [ort.serial.internal.RxTxPortProvider] - No SerialPortIdentifier found for: /dev/ttyUSB1
2022-09-22 11:16:43.048 [DEBUG] [ort.serial.internal.RxTxPortProvider] - No SerialPortIdentifier found for: /dev/ttyUSB0

Any idea ?

It now works after another reboot, but I’ve not determined why.

I noticed this in Java output so assume the reboot has removed those lock files that’s why it works now.

Sep 22 11:48:26 smarthouse karaf[1053]: RXTX Warning:  Removing stale lock file. /var/lock/LCK..ttyUSB2
Sep 22 11:48:27 smarthouse karaf[1053]: RXTX Warning:  Removing stale lock file. /var/lock/LCK..ttyUSB1
Sep 22 11:48:27 smarthouse karaf[1053]: RXTX Warning:  Removing stale lock file. /var/lock/LCK..ttyUSB0

The rxtx (nrjavaserial) ships its own locking mechanism based on files to guarantee exclusive access to serial port. Sometimes these locks are not being released thus serial port can not be opened. I think @fwolter can elaborate a bit more about cause.

@fwolter would it make sense to unconditionally remove /var/lock/LCK..tty* on openHAB start ?

EDIT: limited to ttyUSB* ttyACM0 ttyAMA0 if started in openHABian (not OH on every platform)
There should not be any other software running in openHABian that is locking serial ports.

I’ll guess not, because some other application may hold the lock (that being the point of locks)

IIRC, nrjavaserial is smart enough to detect stale lock files and remove them upon start. I don’t think the two problems you had are connected.

There was a bug preventing to be processed, when OH was started manually. It’s an old one, but maybe your shell scripts weren’t updated for some reason?

No the problem happened when the box had a power cut → who to delete locks on boot ?
As they exist on OH start it does not touch the interfaces.

IIRC nrjavaserial only removes stale locks if the PID in them no longer exists. So if another process is running with the old PID that openHAB had before it starts it will not remove the lock files and you might run into this issue.

Usually your OS already takes care of removing these temporary files on bootup. On Debian based distros this is done using tmpfiles.d (e.g. /usr/lib/tmpfiles.d/legacy.conf).

1 Like

Then I guess that’s what happened, thanks for explaining.
I reckon I shouldn’t be messing with the locks then.