USB port conflict zigbee2mqtt and Modbus

Hi,
I have a problem with cooperation zigbee2mqtt and Modbus on my rapsberry pi 3 with Openhabian.
It started when I had to change zigbee2mqtt dongle with CC2531 to Sonoff Dongle Plus (more then 20 zigbee devices). In my RP i use two USB ports: one for Modbus (usb converter) and other for Sonoff. When I was using CC2531 it linked to /dev/ttyACM0 and Modbus converter to /dev/ttyUSB0 and everything worked perfect. When I changed CC2531 to Sonoff, Sonoff linked to /dev/ttyUSB0 aswell (the same like Modbus) so I moved Modbus converter to other physical port in RP and reconfigured Modbus Serial Slave Thing to /dev/ttyUSB1. It helped but not quite. Now, after reboot, sometimes everything work OK and sometimes not (it looks like the same conflict with USB communication like before changing /dev/ttyUSB0 to /dev/ttyUSB1). There is no rule, some reboot is OK and some causes problem when at the end, zigbee2mqtt bridge goes offline and no zigbee devices work. I’m not linux expert, I don’t know if is possible to match permanently physical usb port to unique file in /dev. It looks like /dev/ttyUSB0 could be on every of four physical ports in RP. Could you have any idea how to fix the problem?

Welcome to the openHab forum, Marek !
I’m not a linux crack but I guess that the system is sometime changing the physical port below tty…

Specific for a Pi there is this post, guess it is worth having a look into it.

So maybe addressing it differently will solve it. There is a post on Stack Exchange describing a solution.

Regards,
Thomas

udev is the way to go:

1 Like

Hi guys,
thank you for your help. I have done suggested instructions but something is still wrong. I enclose screen with my devices.
While zigbee dongle works very well on the new device /dev/ttyUSB_DEVICE1, the Modbus converter doesn’t work on /dev/ttyUSB_DEVICE1 , generating in log messages as below. Do you have any idea how to fix it. I’m sorry if this post is difficult to read but this is my second post on this forum :wink:

2023-01-17 23:49:17.488 [WARN ] [ing.ModbusSlaveConnectionFactoryImpl] - Connect reached max tries 1, throwing last error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection [m_SerialPort=null, m_Parameters.getPortName()=/dev/ttyUSB_DEVICE2]. Endpoint ModbusSerialSlaveEndpoint [getPortName()=/dev/ttyUSB_DEVICE2]

2023-01-17 23:49:17.492 [WARN ] [ing.ModbusSlaveConnectionFactoryImpl] - Error connecting connection SerialConnection [m_SerialPort=null, m_Parameters.getPortName()=/dev/ttyUSB_DEVICE2] for endpoint ModbusSerialSlaveEndpoint [getPortName()=/dev/ttyUSB_DEVICE2]: Could not get port identifier, maybe insufficient permissions. null

2023-01-17 23:49:17.497 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Could not connect to endpoint ModbusSerialSlaveEndpoint [getPortName()=/dev/ttyUSB_DEVICE2] – aborting request ModbusReadRequestBlueprint [slaveId=1, functionCode=READ_INPUT_REGISTERS, start=1280, length=12, maxTries=3] [operation ID 0155633a-e0b1-4912-b69b-2768ff68283e]

Which guide did you follow?
Please post the content of /etc/udev/rules.d/99-usb-serial.rules, maybe there is a typo within the IDs?

Thomas,
I have followed every suggested, in this topic, guide with the same effect :wink:
Maybe it’s something connected with Modbus Binding that it doesn’t accept symlinks (with /dev/ttyUSB1 works perfect only if Zigbee dongle is not linked to it).
For instance, following this instruction I created /etc/udev/rules.d/99-usb-serial.rules file like this:

SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="ttyUSB_DEVICE1"
SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="ttyUSB_DEVICE2"

Try adding the ports to JAVA like in this post.

Since you are using non-standard port names and the Modbus Binding does not use the openHAB serial transport (openhab-addons#7573) you need to set this non-standard port using -Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB_DEVICE2
as documented in the Serial Port Configuration docs.

The Zigbee Binding does use the openHAB serial transport, so the openHAB serial transport will automatically add this configuration so it is possible to use this non-standard port name with the serial library.

2 Likes

Guys, you are greate! It works. I have red Serial Port Configuration doc before but the information that in case of openhabian you just need to use openhabian-config tool is misleading. I use openhabian and it wasn’t enough at all. My /etc/default/openhab file looks now like this (I am not sure if all USB devices, system’s and created by me should be listed here) :

EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyUSB1:/dev/ttyUSB_DEVICE1:/dev/ttyUSB_DEVICE2"
##   EXTRA_JAVA_OPTS="-Djna.library.path=/lib/arm-linux-gnueabihf/ -Duser.timezone=Europe/Berlin -D>

#EXTRA_JAVA_OPTS="-Xms192m -Xmx320m"

I have the last question (I haven’t found the answer by myself). I had to hash

#EXTRA_JAVA_OPTS="-Xms192m -Xmx320m"

to make EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyUSB1:/dev/ttyUSB_DEVICE1:/dev/ttyUSB_DEVICE2" working. Is it possible to have two EXTRA_JAVA_OPTS declaration in this file or maybe I should somehow concatenate the two declarations. EXTRA_JAVA_OPTS=“-Xms192m -Xmx320m” means something concerning memory so hashing it couldn’t be good for Openhabian system.

1 Like

You can concatenate them. Xms and Xmx are already concatenated as well as the other comment that contains the timezone.
Put a space at the end of the first one ( before the double quote ) and add the -Xms…

EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyUSB1:/dev/ttyUSB_DEVICE1:/dev/ttyUSB_DEVICE2 -Xms192m -Xmx320m"
1 Like