[Solved] RPi ModBus+Serial problem

Hello !

I have a problem that could not resolve even after few deys of googling. The root of the problem in modbus service. I have custom sensors module based on arduino and it is works well with my custom python scripts and with different testing software. Few days ago ive decided to try openHAB and its ModBus service but no success.

At first, here is some technical data:

root@raspberrypi:/opt/openhab/conf# java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)

I`ve added these lines to {OHROOT}/conf/services/modbus.cfg :

serial.slave1.connection=/dev/ttyAMA0:9600:8:none:1:rtu:35:1500:none:none
serial.slave1.id=5
serial.slave1.start=7
serial.slave1.length=1
serial.slave1.type=input

Here is permissions on serial port:

root@raspberrypi:/opt/openhab/userdata/logs# ls -lhS /dev/ttyAMA0 
crw-rw---- 1 root dialout 204, 64 Jan 29 06:25 /dev/ttyAMA0

I have RPi 3 with Bluetooth disabled and full hardware serial (ttyAMA0) directed to header pins. It works well with all of my test scripts. But when i trying to use this port in openHAB 2.0 i see folowing errors in log file:

2017-01-29 06:38:12.863 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 1/3 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@bd680f[portName=/dev/ttyAMA0,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@2f18d0[portName=/dev/ttyAMA0]
2017-01-29 06:38:12.904 [ERROR] [et.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. null
2017-01-29 06:38:12.906 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 2/3 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@bd680f[portName=/dev/ttyAMA0,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@2f18d0[portName=/dev/ttyAMA0]
2017-01-29 06:38:12.947 [ERROR] [et.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. null
2017-01-29 06:38:12.948 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 3/3 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@bd680f[portName=/dev/ttyAMA0,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@2f18d0[portName=/dev/ttyAMA0]
2017-01-29 06:38:12.949 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - re-connect reached max tries 3, throwing last error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@bd680f[portName=/dev/ttyAMA0,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@2f18d0[portName=/dev/ttyAMA0]
2017-01-29 06:38:12.950 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - Error connecting connection SerialConnection@bd680f[portName=/dev/ttyAMA0,port=<null>] for endpoint ModbusSerialSlaveEndpoint@2f18d0[portName=/dev/ttyAMA0]: Could not get port identifier, maybe insufficient permissions. null
2017-01-29 06:38:12.951 [WARN ] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (PlantsBox): Error getting a new connection for endpoint ModbusSerialSlaveEndpoint@2f18d0[portName=/dev/ttyAMA0]. Error was: Unable to validate object
2017-01-29 06:38:12.952 [WARN ] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (PlantsBox) not connected -- aborting read request net.wimpi.modbus.msg.ReadInputRegistersRequest@110e070. Endpoint ModbusSerialSlaveEndpoint@2f18d0[portName=/dev/ttyAMA0]
2017-01-29 06:38:12.958 [ERROR] [et.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. null

I`ve tried ti run openHAB with dedicated user ‘openhab’ that has been added to dialout group, tried to set 777 permissions to device, tried run openHAB as root but all of my tries gives same result.

Please help me to fix that issue! I could provide any additional info or ssh access if it is neccessary. :slight_smile:
Thanks !

How about EXTRA_JAVA_OPTS
http://docs.openhab.org/installation/linux.html#recommended-additional-setup-steps

1 Like

Hi!

Thanks! Ive tried to add Java options but in wrong way. Because whole unzipped package in one directory used, i have no files in /etc. Previously ive added option “-Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0:/dev/ttyS0” directly to {OHROOT}/runtime/bin/karaf script but in wrong place.
Right now i`ve added a following line to “karaf” script at top of the file:

EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0:/dev/ttyS0"

And then removed artifacts from my previous attempts. And it is works!
Thank you, friend ! :slight_smile:

1 Like