Raspberry Pi - Make serial USB ports persistent via symlinks

Sorry, it was not you I was answering to. Forgot the quote.

As a minimum your openHAB version, even better #10:

In your case: old openHAB version, probably an operating system issue, newer snapshot openHAB version, probably an openHAB related problem (see my link to github)

I have the OpenHab 2.4 stable version and Ubuntu 18.04 LTS. Everything installed 3 days ago.

Did you also add that that port Symlink in the extra java opts as described in the first part here https://www.openhab.org/docs/administration/serial.html#serial-port-configuration?

i added this to my /etc/default/openhab2

EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB-ZStick"

@Rintano I have been using 3 USB devices on a Pi 3b+ with Symlinks and Openhab no problem. Works fine on a reboot. The zwave binding is actually the one that worked best with Symlinks for me. On a Pi with Openhabian and oh 2.5M1 this works for me:
Definition of my Symlinks added to the bottom of /etc/udev/rules.d/99-com.rules

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="ttyEnocean"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="ttyZwave"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="16a8", SYMLINK+="ttyZigbee"

and this is what I added in the EXTRA_JAVA_OPTS line in /etc/default/openhab2

-Dgnu.io.rxtx.SerialPorts=/dev/ttyEnocean:/dev/ttyZwave:/dev/ttyZigbee:/dev/ttyUSB0"

For me it was important to add them to the EXTRA_JAVA_OPTS line that was already there and not to make a new one and there is a bug in Openhabian that overwrites your EXTRA_JAVA_OPTS when you use the add common ports option in the openhabian-config.
I dint know if you have to do anything else when you use a manual installation.
Best regards Johannes

1 Like

I have just one EXTRA_JAVA_OPTS too. no other, but OpenHab still dont have access to the port somehow

PROBLEM RESOLVED: sudo usermod -a -G dialout openhab
was need to make

1 Like

Why??

Because the openhab user need to be in the group dialout. if not, have no access to read the serial ports

But in the first message of this thread, #6 it says:

Add openhab user to the right groups:
sudo adduser openhab dialout
sudo adduser openhab tty

When I do that, I´m beeing told openhab is already a member of tty and dialout.

1 Like

@KraxelHuber I know this topic is quiet old but it was a really useful tutorial to create and configure symlinks within openhab.

I’m running this setup for a while but it seems the binding that uses the symlink can’t recover once the connection es reestablished. The symlink is going to an USB port /dev/tty/USBGeneric and the configuration file for the binding is filled with the above symlink port. It happens from time to time that the symlink changes from eg. /dev/ttyUSB0 to /dev/ttyUSB1. Everytime the symlink changes (during runtime) the binding can’t find the USB port anymore, although it should be transparent for the binding as it is configured to use the symlink port /dev/tty/USBGeneric…

After restart of the binding all is fine… so I do not understand if there is something wrong with the symlink definition or the openhab binding or both… :slight_smile:
Using Openhabian 2.4 stable on a Pi Zero.

Did anybody have any similar behavior with openhab bindings not recovering after a connection drop although the USB port is still the same?

Appreciate your thoughts!

Bernd

I followed all steps to get my Serial Port stable, too. But I can’t access that port from within openhab(ian) as its not displayed there - despite the fact that I added it in the config.
I changed group permissions but I get the following situation where the link is accessible via root:root and only the destination is accessible via root:dialout, is that correct?

ls * -l
lrwxrwxrwx 1 root root          12 Aug 14 21:49 ttyUSB-ZStick -> input/event0
drwxr-xr-x 4 root root         120 Aug 14 21:49 input

ls input* -l
crw-rw-rw- 1 root dialout 13, 64 Aug 14 21:49 event0

Thank you for help

Great tip. I’ve been using it for a while and works perfectly. Except… when I’m upgrading to a new (snapshot) version of OpenHAB. Then the /etc/default/openhab2 file is being overwritten.

Is there a way to prevent the file from being overwritten when upgrading. Or even better, can we achieve the same with a configuration that does not get overwritten by a newer version when upgrading?

I think Introduce additional openhab2 service options file by paulianttila · Pull Request #139 · openhab/openhab-linuxpkg · GitHub will resolve this, but @pauli_anttila would know best.

Hi Markus… Did you ever get this problem fixed??
I have finally found the reason why my symlinks have never worked. And it´s exact the same problem. My symlinks is only accessible from root, and not from dialout (and therefore not openhab as well).
This has been a huge problem for so long now, and due to updating to 2.5Release today I ran into the problem again, and now I cant get my RS485 USB dongle (modbus) to work. So I was forced to do something about it. Unfortunatly I cant seem to get this permission issue fixed :rage:

[22:10:56] openhabian@openHABianPi:~$ ls -al /dev | grep tty

lrwxrwxrwx  1 root root           7 Jan  1 18:52 ttyUSB_RS485 -> ttyUSB0
lrwxrwxrwx  1 root root           7 Jan  1 18:52 ttyUSB_ZStick -> ttyACM0


Intended behavior:

This is how it looks on my VM (Debian Buster)

ls -al /dev | grep tty
lrwxrwxrwx   1 root       root           7 Dez 24 10:57 CC2531 -> ttyACM0
crw-rw----   1 root       dialout 166,   0 Jan  2 11:45 ttyACM0
crw-rw----   1 root       dialout 166,   1 Jan  2 11:45 ttyACM1
lrwxrwxrwx   1 root       root           7 Dez 23 12:17 ZWAVEUZB -> ttyACM1

grafik

How come I cant see my symlinks in Habadmin? This has never worked for me :frowning:

Good question :grinning:

Maybe my udev rule does help?

#Zigbee Stick CC2531
SUBSYSTEM=="tty", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="16a8", ATTRS{serial}=="__0X00124B001949FDC4", SYMLINK+="CC2531"
#Zwave Stick UZB
SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", ATTRS{serial}=="12345678-9012-3456-7890-123456789012", SYMLINK+="ZWAVEUZB"

To find the correct attributes you should use

udevadm info --name=/dev/ttyACM0 --attribute-walk

The only difference is, that you use the ATTRS{serial}, and I dont. The ATTRS{serial} option is only needed, when the idVendore and the idProduct is the same, (ie if you have two of the same id´s).

This is my symlinks:

SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="ttyUSB-ZStick", GROUP="dialout", MODE="0666"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="ttyUSB-RS485", GROUP="dialout", MODE="0666"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", SYMLINK+="ttyUSB-DVBT", GROUP="dialout", MODE="0666"

Notice all id´s are different, which is why I dont need to set the ATTRS{serial}.
Also notice, I use Group “dialout” and Mode “0666”. I´m not sure if these are actually required.