RPi ModBus - Openhab does not read data

After two days of fighting, I will ask you for help.
It reads the data from the energy meter through the usb adapter connected to the RPi. They use a python script to read register values. The problem arises when I want to read data through Openhab.

Things:

Bridge modbus:serial:localSerial [port="/dev/ttyUSB1", id=1, baud=9600, stopBits="1", parity="none", dataBits=8, encoding="rtu"]
{
         Bridge poller Licznik   [ start=512, length=3, refresh=10000, type="holding" ]
{
            Thing data Faza1    [readStart="512", readValueType="int16"]
            Thing data Faza2    [readStart="513", readValueType="int16"]
            Thing data Faza3    [readStart="514", readValueType="int16"]
 }
}

Items:

Number Licznik_Faza1 "Voltage1 [%.1f V]" <energy> {channel="modbus:data:localSerial:Licznik:Faza1:number"}
Number Licznik_Faza2 "Voltage2 [%.1f V]" <energy> {channel="modbus:data:localSerial:Licznik:Faza2:number"}
Number Licznik_Faza3 "Voltage3 [%.1f V]" <energy> {channel="modbus:data:localSerial:Licznik:Faza3:number"}


Here is permissions on serial port:

[09:31:31] openhabian@openHABianPi:~$ ls -lhS /dev/ttyUSB1
crw-rw---- 1 root dialout 188, 1 Sep 28 09:27 /dev/ttyUSB1

In /etc/default/openhab2 I added:

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

The only difference is that when reading a script, I give the HEX address value, e.g. 0x200 and in Openhab DEC

more explanation would help to figure what you want. First are you able to connect or not ? second its normal that your item display a decimal because of this [%.1f V]. What are you expecting to receive as value if what you receive is not correct ?

I can’t connect to Modbus. I have such an error.

2022-09-28 11:19:19.227 [ERROR] [et.wimpi.modbus.net.SerialConnection] - open port failed: gnu.io.PortInUseException: Modbus Serial Master

2022-09-28 11:19:19.233 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 1/1 error: open port failed: Modbus Serial Master. Connection SerialConnection@53b02[portName=/dev/ttyUSB1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@12ae85e[portName=/dev/ttyUSB1]

2022-09-28 11:19:19.238 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - re-connect reached max tries 1, throwing last error: open port failed: Modbus Serial Master. Connection SerialConnection@53b02[portName=/dev/ttyUSB1,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@12ae85e[portName=/dev/ttyUSB1]

2022-09-28 11:19:19.242 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - Error connecting connection SerialConnection@53b02[portName=/dev/ttyUSB1,port=<null>] for endpoint ModbusSerialSlaveEndpoint@12ae85e[portName=/dev/ttyUSB1]: open port failed: Modbus Serial Master

2022-09-28 11:19:19.249 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Could not connect to endpoint ModbusSerialSlaveEndpoint@12ae85e[portName=/dev/ttyUSB1] -- aborting request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@1b54382[slaveId=1,functionCode=READ_MULTIPLE_REGISTERS,start=512,length=3,maxTries=3] [operation ID bad6bba6-1bb2-449d-a53f-38e74d6ded9b]

I have one more idea. Maybe the problem is Modbus Binding. In OH 2.5, I installed it by copying it to /user/share/openhab2/addons/ from 2.5.0 and I’m not sure if it’s correct.
Could someone please share the files from the newer version with me?
Now I added such because I did not find others.
org.openhab.binding.modbus-2.5.0-SNAPSHOT.jar
org.openhab.io.transport.modbus-2.5.0-SNAPSHOT.jar

are planning on staying on 2.5 or upgrade to 3 openhab? for openhab 3 depending on your choise of install enviroment you can see here
https://www.openhab.org/docs/administration/serial.html
if you plan on staying on 2.5 afraid the new binding will not work on 2.5 so you have to follow this link for configuration
https://v2.openhab.org/addons/bindings/modbus/
Now if you can post more details of the device that you want to connect to like registers id baud. The manual of that device will help establish if you are using the correct parameters to connect to it.
Sometimes the polarity of the data wires can be wrong also and you dont get anything.
Post as much information as you can about your setup to get more help

I plan to stay at OH 2.5. I can’t find these files anywhere to install the new binding modbus:
org.openhab.binding.modbus-2.5.12.jar
org.openhab.io.transport.modbus-2.5.12.jar

The connections to the adapter are correct because I can read the data from the meter via the phyton script.


#! /usr/bin/python
from pymodbus.client.sync import ModbusSerialClient as ModbusClient

client = ModbusClient(method='rtu', port='/dev/ttyUSB1', timeout=1, stopbits = 1, bytesize = 8,  parity='N', baudrate= 9600)
client.connect()
request = client.read_holding_registers(0x200,1,unit=1)
print(request.registers)

At hex 0x200, there is voltage on L1. Here is the modbus documentation from the energy meter that I’m trying to connect to: LINK

I tried to reinstall bindings modbus version 2.5.0 but I have this error:

2022-09-28 12:52:28.585 [ERROR] [core.karaf.internal.FeatureInstaller] - Failed installing 'openhab-binding-modbus': Error:

	Resource mvn:org.openhab.addons.bundles/org.openhab.io.transport.modbus/2.5.0 does not contain a manifest

	Resource mvn:org.apache.commons/commons-pool2/2.4.3 does not contain a manifest

hmm from what i can see in the manual for modbus rtu for voltage the register you need is between 0000-0001 and also its a float value
so this will be

Bridge modbus:serial:localSerial [port="/dev/ttyUSB1", id=1, baud=9600, stopBits="1", parity="none", dataBits=8, encoding="rtu"]
{
         Bridge poller Licznik   [ start=0000, length=4, refresh=10000, type="input" ]
{
            Thing data Faza1    [readStart="0000", readValueType="float32"]
            Thing data Faza2    [readStart="0002", readValueType="float32"]
            Thing data Faza3    [readStart="0003", readValueType="float32"]
 }
}

Now for the connection to it please read carrefully
https://www.openhab.org/docs/administration/serial.html

I have changed but I have this error all the time

2022-09-28 13:18:28.569 [ERROR] [core.karaf.internal.FeatureInstaller] - Failed installing 'openhab-binding-modbus': Error:

	Resource mvn:org.apache.commons/commons-pool2/2.4.3 does not contain a manifest

	Resource mvn:org.openhab.addons.bundles/org.openhab.io.transport.modbus/2.5.0 does not contain a manifest

You cant have 2 programs open the tty port at the same time.

also
https://community.openhab.org/t/failed-installing-addons/122428/4

See also

I was able to run Modbus reading in Openhab. Installing the missing stuff from the kar file helped. I can already read data about individual identifiers using the code:

Bridge modbus:serial:localSerial [port="/dev/ttyUSB0", id=1, baud=9600, stopBits="1", parity="none", dataBits=8, encoding="rtu"]
{
         Bridge poller Licznik   [ start=512, length=4, refresh=10000, type="input" ]
{
            Thing data Faza1    [readStart="512", readValueType="int16"]
            Thing data Faza2    [readStart="513", readValueType="int16"]
            Thing data Faza3    [readStart="514", readValueType="int16"]
 }
}

Unfortunately, for some data only such a double code is given, e.g. 0034-0035 or 0x0E-0x0F. How to read it? When I use the code below, I get stupid things.

Bridge modbus:serial:localSerial [port="/dev/ttyUSB0", id=1, baud=9600, stopBits="1", parity="none", dataBits=8, encoding="rtu"]
{
         Bridge poller Licznik   [ start=34, length=4, refresh=10000, type="input" ]
{
            Thing data Inport1    [readStart="34", readValueType="int16"]
            Thing data Inport2    [readStart="35", readValueType="int16"]
 }
}

Documentation with Modbus addresses is here: LINK

Well that need to be a float32 or float32_swap insted of int16