Binding Modbus 2.5.7. Stops working after unsuccessful read attempt

Hello
After switching to openhab 2.5.7, the Modbus binding, after unsuccessful read attempts, simply stopped. On version 2.5.6, warnings were recorded in the logs, but the binding continued to work. These errors did not bother me much, but a complete stop is of course different.
An attempt to reinstall openhab to 2.5.6, oddly enough, did not lead to a positive result.
Openhab 2.5.7. Installed in a Proxmox container. Openhabian.
Interrogates the OM310
Via USR-D404
Fragment of thing

Bridge modbus:tcp:om310 [ host="192.168.88.27", port=8899, id=1, timeBetweenTransactionsMillis=60,reconnectAfterMillis=60000 ] //USR-D404
{  
        // Токи 
	Bridge poller current [ start=100, length=4, refresh=20000, type="holding" ] {
        Thing data if1 [ readStart="100", readValueType="uint16"]
        Thing data if2 [ readStart="101", readValueType="uint16"]
	    Thing data if3 [ readStart="102", readValueType="uint16"]
	    Thing data if0 [ readStart="103", readValueType="uint16"]

    }
	Bridge poller current1 [ start=104, length=7, refresh=10000, type="holding" ] {
        Thing data is1 [ readStart="104", readValueType="uint16"]
	    Thing data is2 [ readStart="105", readValueType="uint16"]
	    Thing data is3 [ readStart="106", readValueType="uint16"]
        Thing data in1 [ readStart="107", readValueType="uint16"]
	    Thing data in2 [ readStart="108", readValueType="uint16"]
	    Thing data in3 [ readStart="109", readValueType="uint16"]
        Thing data iop [ readStart="110", readValueType="uint16"]
    }
	Bridge poller slave1 [ start=111, length=3, refresh=10000, type="holding", updateUnchangedValuesEveryMillis=0 ] {
        Thing data s1 [ readStart="111", readValueType="uint16"]
        Thing data s2 [ readStart="112", readValueType="uint16"]
	    Thing data s3 [ readStart="113", readValueType="uint16"]
    }
 *********************************
	// setting4
	Bridge poller setting4 [ start=183, length=6, refresh=120000, type="holding" ] {
	Thing data att [ readStart="183", readValueType="uint16"]	
	Thing data arr [ readStart="184", readValueType="uint16"]	
	Thing data apd [ readStart="185", readValueType="uint16"]	
	Thing data acd [ readStart="186", readValueType="uint16"]	
	Thing data t5i [ readStart="187", readValueType="uint16"]	
	Thing data sin [ readStart="188", readValueType="uint16"]
	}
  
}

Here’s an example of an error.

2020-07-26 13:46:35.169 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 1 out of 3 failed when executing request (ModbusPollerThingHandler.ModbusPollerReadRequest@cb6566[slaveId=1,functionCode=READ_MULTIPLE_REGISTERS,start=111,length=3,maxTries=3]). Will try again soon. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: SocketTimeoutException Read timed out [operation ID e963fc31-fb7a-43de-b2a7-a611c57c047d]
2020-07-26 13:46:35.173 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Error invalidating connection in pool for endpoint ModbusTCPSlaveEndpoint@468d48[address=192.168.88.27,port=8899]. Error was: java.lang.NullPointerException null
java.lang.NullPointerException: null
	at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936) ~[?:1.8.0_232]
	at org.openhab.io.transport.modbus.internal.pooling.ModbusSlaveConnectionFactoryImpl$PooledConnection.maybeResetConnection(ModbusSlaveConnectionFactoryImpl.java:87) ~[?:?]
	at org.openhab.io.transport.modbus.internal.pooling.ModbusSlaveConnectionFactoryImpl.passivateObject(ModbusSlaveConnectionFactoryImpl.java:223) ~[?:?]
	at org.openhab.io.transport.modbus.internal.pooling.ModbusSlaveConnectionFactoryImpl.passivateObject(ModbusSlaveConnectionFactoryImpl.java:1) ~[?:?]
	at org.apache.commons.pool2.impl.GenericKeyedObjectPool.addIdleObject(GenericKeyedObjectPool.java:1272) ~[?:?]
	at org.apache.commons.pool2.impl.GenericKeyedObjectPool.addObject(GenericKeyedObjectPool.java:1255) ~[?:?]
	at org.apache.commons.pool2.impl.GenericKeyedObjectPool.invalidateObject(GenericKeyedObjectPool.java:589) ~[?:?]
	at org.openhab.io.transport.modbus.internal.ModbusManagerImpl.lambda$1(ModbusManagerImpl.java:407) ~[?:?]
	at java.util.Optional.ifPresent(Optional.java:159) ~[?:1.8.0_232]
	at org.openhab.io.transport.modbus.internal.ModbusManagerImpl.invalidate(ModbusManagerImpl.java:405) ~[?:?]
	at org.openhab.io.transport.modbus.internal.ModbusManagerImpl.lambda$9(ModbusManagerImpl.java:642) ~[?:?]
	at org.openhab.io.transport.modbus.internal.SimpleStopWatch.timeConsumer(SimpleStopWatch.java:169) ~[?:?]
	at org.openhab.io.transport.modbus.internal.ModbusManagerImpl.executeOperation(ModbusManagerImpl.java:642) ~[?:?]
	at org.openhab.io.transport.modbus.internal.ModbusManagerImpl.access$2(ModbusManagerImpl.java:525) ~[?:?]
	at org.openhab.io.transport.modbus.internal.ModbusManagerImpl$ModbusCommunicationInterfaceImpl.lambda$1(ModbusManagerImpl.java:782) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_232]
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_232]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_232]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_232]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_232]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_232]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_232]

There are several topics on the forum with similar errors, but I did not notice a similar problem - the binding stops.

How can I fix the situation?

The root cause of TCP timeout is ordinary enough.

I’d suspect this is the bit going wrong, and making it unrecoverable.
@ssalonen advice needed here

Thanks for the answer! I do not want to solve the problem with this error so much as to make the binding work further.
A banal loss of connection with the device stops the binding for a short time.

This is most likely a bug introduced in 2.5.7 (larger refactoring of the code base) – will need to have a closer look.

For now I would recommend downgrading the binding and transport bundles to 2.5.6…

Potential fix here: https://github.com/openhab/openhab-addons/pull/8206

Thanks, I’ll try

I thought it would not be difficult, but I got confused. Teach me how to do this, please.

@vshaev, instead of downgrading, could you try this version: https://github.com/openhab/openhab-addons/files/4977927/org.openhab.io.transport.modbus-2.5.8-SNAPSHOT.zip ?

P.S. can you add modbus as a label for this post?

1 Like

I copied the *.jar file to /usr/share/openhab2/addons folder
Appeared in the log -

2020-07-26 22: 48: 37.657 [INFO] [rt.modbus.internal.ModbusManagerImpl] - Modbus manager activated

Simulated an error (rebooted the USR-D404) - the binding generated an error and stopped working.
Rebooted openab. Everything is the same. In the Paper UI, I only see version 2.5.7. Apparently I copied the *.jar to the wrong place, or did you need to perform any other actions with it?

You have to uninstall that first.

1 Like

No you did right in copying the jar.
But you forgot to uninstall the binding in PaperUI, like rossko57 says :slight_smile:

Did the modbus binding update in 2.5.7?? (I havnt updated yet).

EDIT - Ignore the question about modbus 2.5.7 update… just read the release notes again… Its there :woozy_face:

2 Likes

I did everything as I was advised - now it works !!! I provoked an error several times, the binding “swears”, but when the channel is restored, it continues to work normally. Great job! Thank!

3 Likes

I tried using the new plugin but get the following error:

Unresolved requirement: Import-Package: org.apache.commons.pool2; version="[2.4.0,3.0.0)"

Any idea how to resolve that ?

@mvwieringen do you mean you tried to install the 2.5.8-SNAPSHOT version linked above?

Or do you get that error straight away with 2.5.7 release version?

That’s with the 2.5.8-SNAPSHOT zip extracted.

1 Like

EDIT: openhab 2.5.8 stable has been now released. The stable version is recommended for most users and the instructions below are not needed.

I made these step-by-step instructions (working at least with “manual” installation), hopefully helping others as well

  1. Confirm you have 2.5.7 versions running (Active)
openhab> bundle:list -s|grep modbus
247 │ Active │  80 │ 2.5.7                   │ org.openhab.binding.modbus
248 │ Active │  80 │ 2.5.7                   │ org.openhab.binding.modbus.sunspec
255 │ Active │  80 │ 2.5.7                   │ org.openhab.io.transport.modbus

This is important. The org.openhab.io.transport.modbus-2.5.8-SNAPSHOT.jar will not work with pre-2.5.7 org.openhab.binding.modbus/sunspec.

  1. Unzip 2.5.8-SNAPSHOT zip (see above)
  2. Copy org.openhab.io.transport.modbus-2.5.8-SNAPSHOT.jar to addons folder (for exact location, refer to https://www.openhab.org/docs/installation/linux.html#file-locations)
  3. List bundles and confirm you have 2.5.8 snapshot registered
openhab> bundle:list -s|grep modbus                                                                                                                        
259 │ Active │  80 │ 2.5.7                   │ org.openhab.binding.modbus
260 │ Active │  80 │ 2.5.7                   │ org.openhab.binding.modbus.sunspec
267 │ Active │  80 │ 2.5.7                   │ org.openhab.io.transport.modbus
268 │ Active │  80 │ 2.5.8.202007261630      │ org.openhab.io.transport.modbus
  1. Uninstall older (2.5.7) org.openhab.io.transport.modbus version, using the ID (first column) above
openhab> bundle:uninstall 267
  1. Confirm that old bundle is removed:
openhab> bundle:list -s|grep modbus                                                                                                                        
259 │ Waiting │  80 │ 2.5.7                   │ org.openhab.binding.modbus
260 │ Active  │  80 │ 2.5.7                   │ org.openhab.binding.modbus.sunspec
268 │ Active  │  80 │ 2.5.8.202007261630      │ org.openhab.io.transport.modbus

You can refresh bundle status manually:

openhab> bundle:refresh 259
openhab> bundle:list -s|grep modbus
259 │ Active │  80 │ 2.5.7                   │ org.openhab.binding.modbus
260 │ Active │  80 │ 2.5.7                   │ org.openhab.binding.modbus.sunspec
268 │ Active │  80 │ 2.5.8.202007261630      │ org.openhab.io.transport.modbus
  1. Restart openHAB & confirm that there is no old transport version running, and all the bundles are Active
openhab> bundle:list -s|grep modbus                                                                                                                        
259 │ Active │  80 │ 2.5.7                   │ org.openhab.binding.modbus
260 │ Active │  80 │ 2.5.7                   │ org.openhab.binding.modbus.sunspec
268 │ Active │  80 │ 2.5.8.202007261630      │ org.openhab.io.transport.modbus
5 Likes

EDIT: users are reporting that these steps do not necessarily work out (missing dependencies)
EDIT2: Added couple of additional steps to finish the installation and resolve the dependency issues
EDIT3: openhab 2.5.8 stable has been now released. The stable version is recommended for most users and the instructions below are not needed.

Alternatively, you can now just download SNAPSHOT versions of modbus binding and modbus transport from ci.openhab.org, and just use them

  1. Uninstall 2.5.7 modbus binding, using Paper UI
  2. Confirm uninstallation using bundle:list -s |grep modbus, no bundles should be installed
  3. Download https://ci.openhab.org/view/Integration%20Builds%20(2.5.x)/job/openHAB-Distribution/lastSuccessfulBuild/artifact/distributions/openhab-addons/target/openhab-addons-2.5.8-SNAPSHOT.kar
  4. rename openhab-addons-2.5.8-SNAPSHOT.kar to openhab-addons-2.5.8-SNAPSHOT.zip
  5. Unzip
  6. Find 2.5.8-SNAPSHOT versions from following locations of the extracted files:
  • /repository/org/openhab/addons/bundles/org.openhab.binding.modbus/2.5.8-SNAPSHOT/org.openhab.binding.modbus-2.5.8-SNAPSHOT.jar modbus binding
  • /repository/org/openhab/addons/bundles/org.openhab.io.transport.modbus/2.5.8-SNAPSHOT/org.openhab.io.transport.modbus-2.5.8-SNAPSHOT.jar modbus transport

In case you use the modbus.sunspec addon:

  • /repository/org/openhab/addons/bundles/org.openhab.binding.modbus.sunspec/2.5.8-SNAPSHOT/org.openhab.binding.modbus.sunspec-2.5.8-SNAPSHOT.jar
  1. Copy the 2.5.8-SNAPSHOT versions to addons
  2. Check the logs, you will probably have error there
08:08:07.785 [WARN ] [org.apache.felix.fileinstall         ] - Error while starting bundle: file:/home/salski/src/openhab-tests/openhab-2.5.7-test/addons/org.openhab.binding.modbus-2.5.8-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.modbus [205]
  Unresolved requirement: Import-Package: org.openhab.io.transport.modbus.endpoint
    -> Export-Package: org.openhab.io.transport.modbus.endpoint; bundle-symbolic-name="org.openhab.io.transport.modbus"; bundle-version="2.5.8.202008131350"; version="2.5.8"
       org.openhab.io.transport.modbus [203]
         Unresolved requirement: Import-Package: gnu.io; version="[3.12.0,6.0.0)"
  Unresolved requirement: Import-Package: org.openhab.io.transport.modbus
    -> Export-Package: org.openhab.io.transport.modbus; bundle-symbolic-name="org.openhab.io.transport.modbus"; bundle-version="2.5.8.202008131350"; version="2.5.8"; uses:="org.eclipse.smarthome.core.library.types,org.eclipse.smarthome.core.types,org.openhab.io.transport.modbus.endpoint"
  1. gnu.io dependency is missing. Install it by feature:install openhab-transport-serial, and restart the bundles using bundle:restart
openhab> feature:install openhab-transport-serial
openhab> bundle:list -s |grep modbus
203 │ Installed │  80 │ 2.5.8.202008131350      │ org.openhab.io.transport.modbus
204 │ Installed │  80 │ 2.5.8.202008131401      │ org.openhab.binding.modbus.sunspec
205 │ Installed │  80 │ 2.5.8.202008131350      │ org.openhab.binding.modbus
openhab> bundle:restart 203 204 205  # Find correct IDs above
  1. Check the logs (log:tail), you will probably have error there, slightly different this time:
	Unable to start bundle 203: Could not resolve module: org.openhab.io.transport.modbus [203]
  Unresolved requirement: Import-Package: org.apache.commons.pool2; version="[2.4.0,3.0.0)"
...
  1. org.apache.commons.pool2 dependency is missing. Install it by bundle:install, and restart the bundles using bundle:restart
openhab>bundle:install https://repo1.maven.org/maven2/org/apache/commons/commons-pool2/2.4.3/commons-pool2-2.4.3.jar  # modbus transport 2.5.7 is using apache commons pool2 v. 2.4.3 version
openhab> bundle:list -s |grep modbus
203 │ Installed │  80 │ 2.5.8.202008131350      │ org.openhab.io.transport.modbus
204 │ Installed │  80 │ 2.5.8.202008131401      │ org.openhab.binding.modbus.sunspec
205 │ Installed │  80 │ 2.5.8.202008131350      │ org.openhab.binding.modbus
openhab> bundle:restart 203 204 205  # Find correct IDs above
  1. Bundles should be now active, with no errors in logs
openhab> bundle:list -s |grep modbus
203 │ Active   │  80 │ 2.5.8.202008131350      │ org.openhab.io.transport.modbus
204 │ Active   │  80 │ 2.5.8.202008131401      │ org.openhab.binding.modbus.sunspec
205 │ Active   │  80 │ 2.5.8.202008131350      │ org.openhab.binding.modbus
openhab> log:tail
...
08:16:58.685 [INFO ] [ort.modbus.internal.ModbusManagerImpl] - Modbus manager activated
08:16:58.946 [INFO ] [ort.modbus.internal.ModbusManagerImpl] - Modbus manager activated
  1. Installation successfull
6 Likes

Tried following the description above (downloading/extracting jar files), but end up with error relating to missing requirement/import package: org.apache.commons.pool2. Running openHAB 2.5.7 Release version.

Also tried restarting bundle, with error shown below.

Error executing command: Error restarting bundles:
	Unable to start bundle 204: Could not resolve module: org.openhab.io.transport.modbus [204]
  Unresolved requirement: Import-Package: org.apache.commons.pool2; version="[2.4.0,3.0.0)"

@kjoglums did you get the error with both approaches or with just one of them?

I have only tested using the alternative described in post no 16. Started out having the binding installed via Paper UI, doing a full uninstall/clean tmp and cache etc before installing binding manually (modbus and io.transport). From manual install, the bundles are listed as “Installed”, with only one version of each listed (correct version number), but not able to get them “Active”. Have tried several reboots.

EDIT:
Also tried the approach described in post no 15, although starting out with the 2.5.7 version installed from Paper UI.

After manually installing org.openhab.io.transport.modbus-2.5.8-SNAPSHOT.jar, uninstalling the 2.5.7 version and performing OH reboot, I have the correct setup wrt versions, and the bundles seem to be working.

1 Like

Hi, I also followed your instructions and got following error. Do I need to update more packages?

2020-08-03 21:51:55.283 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/usr/share/openhab2/addons/org.openhab.io.transport.modbus-2.5.8-SNAPSHOT.jar

org.osgi.framework.BundleException: Could not resolve module: org.openhab.io.transport.modbus [203]

  Unresolved requirement: Import-Package: gnu.io; version="[3.12.0,6.0.0)"

	at org.eclipse.osgi.container.Module.start(Module.java:444) ~[org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) ~[org.eclipse.osgi-3.12.100.jar:?]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [bundleFile:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [bundleFile:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:520) [bundleFile:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [bundleFile:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [bundleFile:3.6.4]

2020-08-03 21:51:55.633 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/usr/share/openhab2/addons/org.openhab.binding.modbus-2.5.8-SNAPSHOT.jar

org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.modbus [204]

  Unresolved requirement: Import-Package: org.openhab.io.transport.modbus.endpoint

    -> Export-Package: org.openhab.io.transport.modbus.endpoint; bundle-symbolic-name="org.openhab.io.transport.modbus"; bundle-version="2.5.8.202008030359"; version="2.5.8"

       org.openhab.io.transport.modbus [203]

         Unresolved requirement: Import-Package: gnu.io; version="[3.12.0,6.0.0)"

  Unresolved requirement: Import-Package: org.openhab.io.transport.modbus

    -> Export-Package: org.openhab.io.transport.modbus; bundle-symbolic-name="org.openhab.io.transport.modbus"; bundle-version="2.5.8.202008030359"; version="2.5.8"; uses:="org.eclipse.smarthome.core.library.types,org.eclipse.smarthome.core.types,org.openhab.io.transport.modbus.endpoint"

	at org.eclipse.osgi.container.Module.start(Module.java:444) ~[org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) ~[org.eclipse.osgi-3.12.100.jar:?]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [bundleFile:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [bundleFile:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:520) [bundleFile:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [bundleFile:3.6.4]

	at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [bundleFile:3.6.4]