Modbus openHAB2 binding available for alpha testing

Great to hear it’s now working!

The behavior you see with states is expected. Openhab updates item state automatically when commands are issued.

Please read the following post on autoupdate : Rule to postUpdate an Item works but Item falls back after some seconds

You might want to disable autoupdate with your items.

Sami

1 Like

Will see yet :smiley:. This is still not the full amount of things I have. There is at least tripple of what is currently configured :wink: and I still didn’t touched holding registers or inputs. Will keep you informed.
Thanks for the hint with autoupdate. Appreciate it. I will try to see if this helps.

Great, thanks!

Make sure you update to latest version, there was a bug with the latest version, see Possible performance of bindings?

I’m running stable 2.3. Can I request for link to the latest version? Versions at marketplace seems to be not up to date?

I think the versions are up-to-date? 2.4.0-SNAPSHOT (you can check the date once you have installed the binding).

1 Like

Hi,

I have the Modbus serial working in version 1 but in the v2 I’m having some dificulty to understand how to do the same thing. Can you help me ssalonen. First I would like to start with a simple example of reading a light meter and showing the values. After I will add one more sensor, for example, a temperature sensor. And after I will add a switch to control a LED. I’m using an arduino in the hardware side.

V1 - led.sitemap:

sitemap demo label="Modbus Smart House"
{
Frame {
    Text item=LightSensor icon="light"

}
Frame {
    Text item=Temperature icon="temperature"
}
}

V1 - led.items

Number LightSensor  "Light Sensor [%d LUX]" { modbus="slave2:0" }
Number Temperature  "Temperature [%.1f °C]" { modbus="slave2:1" }

V1 - modbus.cfg

modbus:poll=5000

modbus:serial.slave1.connection=/dev/ttyUSB0:19200:8:none:1:rtu:35:1500:none:none
modbus:serial.slave1.type=holding
modbus:serial.slave1.id=1
modbus:serial.slave1.start=1
modbus:serial.slave1.length=2

The V1 example above It’s working and I unsderstood the way it works. But Trying to make the same thing in V2, I don’t know how It works. Specially the modbus.things.

V2 - modbus.things

Bridge modbus:serial:endpoint [ port="/dev/ttyS0", baud=19200, id=1, stopBits="1.0", parity="none",dataBits=8, echo=false, encoding="rtu", flowControlIn="none", flowControlOut="none", receiveTimeoutMillis=1500 ] {
    Bridge poller poller1 [ start=0, length=2, refresh=500, type="holding" ] {
        Bridge readwrite readwriteCollector { 
            //Thing read read1 [ start=0, transform="default", trigger="*", valueType="int16" ]
            Thing read read2 [ start=1, transform="default", trigger="*", valueType="int16" ]
            // Thing write write1 [ start=0, transform="default", trigger="*", valueType="int16", type="holding" ]
        }
    }   
}

V2 - modbus.items

Number NumberItemTest            "Number readwrite [%d LUX]"    { channel="modbus:readwrite:endpoint:poller1:readwriteCollector:number" }

V2 - modbus.sitemap

sitemap modbus label="Modbus"
{
    Frame {
        Text item=NumberItemTest
    }
}

I’m available to collaborate in the wiki to add serial examples, after I understand how to do it.

The v2 config you use (e.g. readwrite) is no longer working. It was a “side-step” during the development of this new binding.

Please refer to docs for up-to-date examples.

Let me know if you have issues

best
Sami

But in the documentation there are only full examples for TCP connection. Not for serial RTU.

Reading the documentation I came into this.

V2 - modbus.things

Bridge modbus:serial:endpoint [ port="/dev/ttyUSB0", baud=19200, id=1, stopBits="1", parity="none", dataBits=8, echo=false, encoding="rtu", flowControlIn="none", flowControlOut="none", receiveTimeoutMillis=1500 ] {
    Bridge poller poller1 [ start=1, length=2, refresh=500, type="holding" ] {
		Thing data NumberItemTest [ readStart="1", readValueType="int16" ]
		}   
}

V2 - modbus.items

Number NumberItemTest            "Number readwrite [%f]"    { channel="modbus:data:endpoint:items:NumberItemTest:number" }

V2 - modbus.sitemap

sitemap modbus label="Modbus"
{
    Frame {
        Text item=NumberItemTest
    }
}

Is this correct?

Looks about right!

Check the channel name in your item configuration, it looks wrong (especially the “items” part). You can find out full thing id from paper ui

Best
Sami

Hello!
i recently (yesterday…) updated to OH2.3 and now my Modbus Snapshot won’t work anymore:

2018-07-16 07:24:03.363 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/usr/share/openhab2/addons/org.openhab.io.transport.modbus-2.3.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.io.transport.modbus [12]
  Unresolved requirement: Import-Package: gnu.io
	at org.eclipse.osgi.container.Module.start(Module.java:444) [?:?]
	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) [?:?]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [9:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [9:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1221) [9:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:515) [9:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [9:org.apache.felix.fileinstall:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [9:org.apache.felix.fileinstall:3.6.4]

how to get back on track? for now i haven’t done anything (because i’m afraid to lose my config…)

cheers
Peter

That would indicate that serial transport is missing, check out the first post for installation instructions.

Btw, you are using old snapshot – I suggest using 2.4.0-SNAPSHOT available, from eclipse IOT store

thanks! back in business!

Hello!
I am new to OpenHab and ModBus. I have OH2.3 and installed latest ModBus add-on version. I have clean OH install. I want to connect my arduino UNO with OH. I did all the ModBus settings in Paper UI and it works with mod_RSsim simulator. But when I try to connect to arduino I have errors. Arduino is set using Modbus-Master-Slave-for-Arduino library with simple slave example:

/**
 *  Modbus slave example 1:
 *  The purpose of this example is to link a data array
 *  from the Arduino to an external device.
 *
 *  Recommended Modbus Master: QModbus
 *  http://qmodbus.sourceforge.net/
 */

#include <ModbusRtu.h>

// data array for modbus network sharing
uint16_t au16data[16] = {
  3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 };

/**
 *  Modbus object declaration
 *  u8id : node id = 0 for master, = 1..247 for slave
 *  u8serno : serial port (use 0 for Serial)
 *  u8txenpin : 0 for RS-232 and USB-FTDI 
 *               or any pin number > 1 for RS-485
 */
Modbus slave(1,0,0); // this is slave @1 and RS-232 or USB-FTDI

void setup() {
  slave.begin( 9600 ); // baud-rate at 9600
}

void loop() {
  slave.poll( au16data, 16 );
}

In Paper UI I set a Modbus serial slave, Regular poll that is bridged to slave and modbus data that is bridget to poll. This setup works well with simulator. But I can not connect to my arduino bord.

Here is my openhab.log:

2018-07-28 12:20:13.572 [INFO ] [er.internal.HomeBuilderDashboardTile] - Started Home Builder at /homebuilder
2018-07-28 12:20:14.896 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at http://192.168.0.127:8090
2018-07-28 12:20:14.897 [INFO ] [.dashboard.internal.DashboardService] - Started Dashboard at https://192.168.0.127:8443
2018-07-28 12:20:16.632 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.items'
2018-07-28 12:20:17.217 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.rules'
2018-07-28 12:20:17.226 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'home.rules' is either empty or cannot be parsed correctly!
2018-07-28 12:20:17.272 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2018-07-28 12:20:17.423 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.sitemap'
2018-07-28 12:20:17.922 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-07-28 12:20:17.951 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-07-28 12:20:17.975 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2018-07-28 12:20:17.987 [INFO ] [sysfs.internal.SysfsUsbSerialScanner] - Cannot perform scans with this configuration: sysfsTtyDevicesDirectory: /sys/class/tty, devDirectory: /dev
2018-07-28 12:20:17.991 [INFO ] [sfs.internal.PollingUsbSerialScanner] - Do not start background scanning, as the configured USB-Serial scanner cannot perform scans on this system
2018-07-28 12:20:17.992 [INFO ] [sfs.internal.PollingUsbSerialScanner] - Do not start background scanning, as the configured USB-Serial scanner cannot perform scans on this system
2018-07-28 12:20:18.010 [INFO ] [rt.modbus.internal.ModbusManagerImpl] - Modbus manager activated
2018-07-28 12:20:18.022 [INFO ] [modbus.internal.ModbusHandlerFactory] - Setting manager: org.openhab.io.transport.modbus.internal.ModbusManagerImpl@322920b9
2018-07-28 12:20:20.197 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 02 00 00 00 04 79 c9
2018-07-28 12:20:20.197 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2018-07-28 12:20:20.202 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputDiscretesRequest@2b36d1f (unit id 1 & transaction 1). Serial parameters: SerialParameters@7272913e[portName=COM3,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-07-28 12:20:20.203 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputDiscretesRequest@2b36d1f (unit id 1 & transaction 1). Serial parameters: SerialParameters@7272913e[portName=COM3,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-07-28 12:20:20.203 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 1 out of 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@4869194a[slaveId=1,functionCode=READ_INPUT_DISCRETES,start=0,length=4,maxTries=3]). Will try again soon. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID 3c517d51-d9a3-40f3-b113-294f1f980048]
2018-07-28 12:20:21.746 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 02 00 00 00 04 79 c9
2018-07-28 12:20:21.746 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2018-07-28 12:20:21.747 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputDiscretesRequest@4af92f2e (unit id 1 & transaction 2). Serial parameters: SerialParameters@7272913e[portName=COM3,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-07-28 12:20:21.747 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.ReadInputDiscretesRequest@4af92f2e (unit id 1 & transaction 2). Serial parameters: SerialParameters@7272913e[portName=COM3,baudRate=9600,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-07-28 12:20:21.747 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 1 out of 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@4869194a[slaveId=1,functionCode=READ_INPUT_DISCRETES,start=0,length=4,maxTries=3]). Will try again soon. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID 61d5810f-e3cb-48c9-a548-42631eaf3f9d]

Can you please help? Where is the problem? Maybe i should use different arduino library? During this process my arduino blinks all the time.
Thank you!

UPDATE:when using mod_RSsim ModBus simulator it is not possible to write data into holding register using my setup. Why is it so?

Hi

Unfortunately cannot comment on the arduino stuff. I suggest figure out that separately, using commonly available tools or openhab to poll the data from arduino. By reading other posts here, it would be relevant to know all serial parameters and check the physical connections. Perhaps open new thread to get more visibility? Perhaps there is something already in the forums?

Regarding your write issue with the simulator : the write to the slave happens only if writing had been configured to the data things. The documentation has examples of read+write and read-only things. If you need more support, I would need verbose logs and exact configuration of data things. If you used paper ui to configure, you can either take screenshots (lot of work) or take relevant items from openHAB rest api (/rest/things)

1 Like

Thank you very much for reply! I used read-write examples and everything worked for the simulator. I still can not connect my arduino bord. Thank you once again for your responsiveness, you do a great job!

1 Like

UPDATE: I installed my setup on Ubuntu and everything works now. I can read and write registers to arduino as a slave. I do not know what was the problem with windows. It was suggested in arduino forum that it was a timing issue.

For anyone trying to use modbus binding on ubuntu it is necessary to give openhab permision to use serial:

Add openhab to some groups:

sudo adduser openhab dialout
sudo adduser openhab tty   # ?

You need to edit openhab2 file aswell:

sudo nano /etc/default/openhab2

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

I did all the OpenHab bindings using paper UI which is pretty simple step.
Thank you!

@mbs38 I got the response from Kai in the github discussion thread.

He mentioned that they are working on a generic feature to disable individual “things” temporarily from user code. As far as I understand, disabling means “disposing” the thing, and turning it OFFLINE. With poller poller things this should stop the polling for sure. It might also stop all writes from child data things of this poller.

Would this actually solve your use case?

Best,
Sami

I am happy to announce that he binding got merged to official openHAB master. It will be available in the next release!

Very big thanks to all beta testers!

3 Likes

Congratulations :slight_smile:

BTW. Could you help me with configuration of holding registers?
I can’t make it work :confused:
The current configuration I have is:

    Bridge poller holding_R0_to_R3839 "FatekPLC_Poller_R0_to_R3839" [ start=40000, length=3840, refresh=10000, type="holding" ] {
        Thing data FatekPLC_Modbus_R0 "FatekPLC_Modbus_R0" @ "Modbus" [ readStart="40000", readValueType="int16", writeStart="40000", writeValueType="int16", writeType="holding" ]
        Thing data FatekPLC_Modbus_R1 "FatekPLC_Modbus_R1" @ "Modbus" [ readStart="40001", readValueType="int16", writeStart="40001", writeValueType="int16", writeType="holding" ]
        Thing data FatekPLC_Modbus_R13 "FatekPLC_Modbus_R13" @ "Modbus" [ readStart="40013", readValueType="int16", writeStart="40013", writeValueType="int16", writeType="holding" ]
}

Log:

2018-08-02 23:48:12.388 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException CRC Error in received frame: 0 bytes: . Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@18e3c53 (unit id 1 & transaction 1532). Serial parameters: SerialParameters@1873c77[portName=/dev/ttyUSB0,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-08-02 23:48:12.391 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException CRC Error in received frame: 0 bytes: . Request: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@18e3c53 (unit id 1 & transaction 1532). Serial parameters: SerialParameters@1873c77[portName=/dev/ttyUSB0,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2018-08-02 23:48:12.395 [ERROR] [rt.modbus.internal.ModbusManagerImpl] - Last try 3 failed when executing request (ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@2a374a[slaveId=1,functionCode=READ_MULTIPLE_REGISTERS,start=40000,length=3840,maxTries=3]). Aborting. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException CRC Error in received frame: 0 bytes: [operation ID 93e1ea96-5f81-4e0f-92f4-47b892994180]
2018-08-02 23:48:12.427 [ERROR] [odbus.handler.ModbusDataThingHandler] - Thing modbus:data:fatekplcusb0:holding_R0_to_R3839:FatekPLC_Modbus_R0 ‘FatekPLC_Modbus_R0’ had ModbusSlaveIOExceptionImpl error on read: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message='I/O exception: IOException CRC Error in received frame: 0 bytes: ', cause2=null)
2018-08-02 23:48:12.435 [ERROR] [odbus.handler.ModbusDataThingHandler] - Thing modbus:data:fatekplcusb0:holding_R0_to_R3839:FatekPLC_Modbus_R1 ‘FatekPLC_Modbus_R1’ had ModbusSlaveIOExceptionImpl error on read: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message='I/O exception: IOException CRC Error in received frame: 0 bytes: ', cause2=null)
2018-08-02 23:48:12.442 [ERROR] [odbus.handler.ModbusDataThingHandler] - Thing modbus:data:fatekplcusb0:holding_R0_to_R3839:FatekPLC_Modbus_R13 ‘FatekPLC_Modbus_R13’ had ModbusSlaveIOExceptionImpl error on read: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message='I/O exception: IOException CRC Error in received frame: 0 bytes: ', cause2=null)

In the other modbus binding I had registers configured as folllows:
serial.slaveR1.connection=/dev/ttyUSB0:115200:8:none:1:rtu:150
serial.slaveR1.id=1
serial.slaveR1.start=0
serial.slaveR1.length=64
#serial.slaveR1.length=1280
serial.slaveR1.type=holding
#serial.slaveR1.valuetype=uint16

Fatek documentation:
http://www.esea.cz/support/fatek/FBs_Manual/Manual_2/Chapter_13.pdf

I would appreciate some help