Modbus configuration

Hello,
I need help with modbus configuration. Is it possible for modbus binding to read different type of item in 1 slave ?

I’m trying to connect openhab and modicon M221 using modbus binding and I’m only using 1 PLC without any expander or add-ons. From the documentation about modbus binding, it can only read/write 1 type of item in 1 slave. Can anyone give me some example of modbus configuration ?

Thanks :smile:

Yes. You set it up as ‘virtual’ slaves.
Each Modbus slave configured in OpenHAB can only be of one type of register. And can only be a continuous set or group of register adresses.
But you can set up multiple slaves that all look at the same physical device.
So you might have slave01 for Input registers 2 to 20, slave02 for Coils 0-5, slave03 for Input registers 100-101. But all these slaves can point to address COM1 ID=7 or suchlike.

Exact details or examples depend on whether you are using binding version 1 or 2, the setup is quite different.

Thanks @rossko57 for your reply.

# sets refresh interval to Modbus polling service.
# Value in milliseconds (optional, defaults to 200)
poll=200

tcp.slave1.connection=192.168.0.105:502:60:0:0:3:100
tcp.slave1.type=coil
tcp.slave.start=0
tcp.slave1.length=10
tcp.slave1.valuetype=bit

tcp.slave2.connection=192.168.0.105:502:60:0:0:3:100
tcp.slave2.type=holding
tcp.slave2.start=0
tcp.slave2.length=11
tcp.slave2.valuetype=uint16

So the configuration will be like that ? I’m using modbus binding from Sami Salonen btw and I think it’s version 2.
Is there anything else needs to be configured in the modbus configuration ?

When I see the log, it come out like this :

openhab> log:tail
14:31:37.922 [INFO ] [.io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = 87b5a82c-88ed-4480-a93e-45562c19a826, base URL = http://localhost:8080)
14:31:42.700 [INFO ] [del.core.internal.ModelRepositoryImpl] - Loading model 'modtest.items'
14:31:44.109 [INFO ] [rthome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
14:31:44.726 [INFO ] [del.core.internal.ModelRepositoryImpl] - Loading model 'modtest.sitemap'
14:31:44.944 [INFO ] [del.core.internal.ModelRepositoryImpl] - Loading model 'modtest.things'
14:31:45.003 [INFO ] [thome.event.ItemChannelLinkAddedEvent] - Link 'uibathroom1-modbus:data:localhostTCP:holding:uibathroom1:switch' has been added.
14:31:45.006 [INFO ] [thome.event.ItemChannelLinkAddedEvent] - Link 'internalrelay-modbus:data:localhostTCP:coils:internalrelay:switch' has been added.
14:31:45.019 [INFO ] [thome.event.ItemChannelLinkAddedEvent] - Link 'uilight1-modbus:data:localhostTCP:holding:uilight1:switch' has been added.
14:31:45.021 [INFO ] [thome.event.ItemChannelLinkAddedEvent] - Link 'terminalroom1on-modbus:data:localhostTCP:coils:terminalroom1on:switch' has been added.
14:31:45.024 [INFO ] [thome.event.ItemChannelLinkAddedEvent] - Link 'terminalroom2on-modbus:data:localhostTCP:coils:terminalroom2on:switch' has been added.
14:31:45.041 [INFO ] [thome.event.ItemChannelLinkAddedEvent] - Link 'uilight3-modbus:data:localhostTCP:holding:uilight3:switch' has been added.
14:31:45.045 [INFO ] [thome.event.ItemChannelLinkAddedEvent] - Link 'terminalroom3on-modbus:data:localhostTCP:coils:terminalroom3on:switch' has been added.
14:31:45.052 [INFO ] [thome.event.ItemChannelLinkAddedEvent] - Link 'uilight2-modbus:data:localhostTCP:holding:uilight2:switch' has been added.
14:31:45.055 [INFO ] [thome.event.ItemChannelLinkAddedEvent] - Link 'uibathroom3-modbus:data:localhostTCP:holding:uibathroom3:switch' has been added.
14:31:45.057 [INFO ] [thome.event.ItemChannelLinkAddedEvent] - Link 'uibathroom2-modbus:data:localhostTCP:holding:uibathroom2:switch' has been added.
14:31:46.735 [INFO ] [i.dashboard.internal.DashboardService] - Started dashboard at http://192.168.1.31:8080
14:31:46.737 [INFO ] [i.dashboard.internal.DashboardService] - Started dashboard at https://192.168.1.31:8443
14:31:46.887 [INFO ] [.basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
14:31:46.933 [INFO ] [marthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
14:31:46.995 [INFO ] [bpanel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
14:31:47.281 [ERROR] [binding.modbus.internal.ModbusBinding] - Exception when parsing configuration parameter tcp.slave1.connection = 192.168.0.105:502:60:0:0:3:100  --  java.lang.IllegalArgumentException invalid baud rate: 502
14:31:47.285 [ERROR] [org.apache.felix.configadmin         ] - [org.osgi.service.cm.ManagedService, org.osgi.service.event.EventHandler, id=308, bundle=210/mvn:org.openhab.binding/org.openhab.binding.modbus/1.11.0]: Updating property tcp.slave1.connection of configuration org.openhab.modbus caused a problem: Exception when parsing configuration parameter tcp.slave1.connection = 192.168.0.105:502:60:0:0:3:100  --  java.lang.IllegalArgumentException invalid baud rate: 502
org.osgi.service.cm.ConfigurationException: tcp.slave1.connection : Exception when parsing configuration parameter tcp.slave1.connection = 192.168.0.105:502:60:0:0:3:100  --  java.lang.IllegalArgumentException invalid baud rate: 502
        at org.openhab.binding.modbus.internal.ModbusBinding.updated(ModbusBinding.java:702) [210:org.openhab.binding.modbus:1.11.0]
        at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updated(ManagedServiceTracker.java:189) [7:org.apache.felix.configadmin:1.8.16]
        at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:152) [7:org.apache.felix.configadmin:1.8.16]
        at org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:85) [7:org.apache.felix.configadmin:1.8.16]
        at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.provide(ConfigurationManager.java:1479) [7:org.apache.felix.configadmin:1.8.16]
        at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1435) [7:org.apache.felix.configadmin:1.8.16]
        at org.apache.felix.cm.impl.UpdateThread.run0(UpdateThread.java:141) [7:org.apache.felix.configadmin:1.8.16]
        at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:109) [7:org.apache.felix.configadmin:1.8.16]
        at java.lang.Thread.run(Thread.java:748) [?:?]
14:32:03.704 [ERROR] [.io.openhabcloud.internal.CloudClient] - Socket.IO error: {}
io.socket.engineio.client.EngineIOException: xhr post error
        at io.socket.engineio.client.Transport.onError(Transport.java:71) [208:org.openhab.io.openhabcloud:2.2.0]
        at io.socket.engineio.client.transports.PollingXHR.access$000(PollingXHR.java:19) [208:org.openhab.io.openhabcloud:2.2.0]
        at io.socket.engineio.client.transports.PollingXHR$4$1.run(PollingXHR.java:88) [208:org.openhab.io.openhabcloud:2.2.0]
        at io.socket.thread.EventThread$2.run(EventThread.java:80) [208:org.openhab.io.openhabcloud:2.2.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.io.IOException: 400
        at io.socket.engineio.client.transports.PollingXHR$Request$1.run(PollingXHR.java:218) ~[?:?]
        ... 1 more
14:32:03.717 [INFO ] [.io.openhabcloud.internal.CloudClient] - Disconnected from the openHAB Cloud service (UUID = 87b5a82c-88ed-4480-a93e-45562c19a826, base URL = http://localhost:8080)
14:32:05.904 [INFO ] [.io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = 87b5a82c-88ed-4480-a93e-45562c19a826, base URL = http://localhost:8080)
14:32:31.890 [ERROR] [.io.openhabcloud.internal.CloudClient] - Socket.IO error: {}
io.socket.engineio.client.EngineIOException: xhr post error
        at io.socket.engineio.client.Transport.onError(Transport.java:71) [208:org.openhab.io.openhabcloud:2.2.0]
        at io.socket.engineio.client.transports.PollingXHR.access$000(PollingXHR.java:19) [208:org.openhab.io.openhabcloud:2.2.0]
        at io.socket.engineio.client.transports.PollingXHR$4$1.run(PollingXHR.java:88) [208:org.openhab.io.openhabcloud:2.2.0]
        at io.socket.thread.EventThread$2.run(EventThread.java:80) [208:org.openhab.io.openhabcloud:2.2.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.io.IOException: 400
        at io.socket.engineio.client.transports.PollingXHR$Request$1.run(PollingXHR.java:218) ~[?:?]
        ... 1 more
14:32:31.899 [INFO ] [.io.openhabcloud.internal.CloudClient] - Disconnected from the openHAB Cloud service (UUID = 87b5a82c-88ed-4480-a93e-45562c19a826, base URL = http://localhost:8080)
14:32:33.668 [INFO ] [.io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = 87b5a82c-88ed-4480-a93e-45562c19a826, base URL = http://localhost:8080)
14:35:36.985 [ERROR] [.io.openhabcloud.internal.CloudClient] - Socket.IO error: {}
io.socket.engineio.client.EngineIOException: xhr post error
        at io.socket.engineio.client.Transport.onError(Transport.java:71) [208:org.openhab.io.openhabcloud:2.2.0]
        at io.socket.engineio.client.transports.PollingXHR.access$000(PollingXHR.java:19) [208:org.openhab.io.openhabcloud:2.2.0]
        at io.socket.engineio.client.transports.PollingXHR$4$1.run(PollingXHR.java:88) [208:org.openhab.io.openhabcloud:2.2.0]
        at io.socket.thread.EventThread$2.run(EventThread.java:80) [208:org.openhab.io.openhabcloud:2.2.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.io.IOException: 400
        at io.socket.engineio.client.transports.PollingXHR$Request$1.run(PollingXHR.java:218) ~[?:?]
        ... 1 more
14:35:36.996 [INFO ] [.io.openhabcloud.internal.CloudClient] - Disconnected from the openHAB Cloud service (UUID = 87b5a82c-88ed-4480-a93e-45562c19a826, base URL = http://localhost:8080)
14:35:39.785 [INFO ] [.io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = 87b5a82c-88ed-4480-a93e-45562c19a826, base URL = http://localhost:8080)
14:36:31.629 [ERROR] [.io.openhabcloud.internal.CloudClient] - Socket.IO error: {}
io.socket.engineio.client.EngineIOException: xhr post error
        at io.socket.engineio.client.Transport.onError(Transport.java:71) [208:org.openhab.io.openhabcloud:2.2.0]
        at io.socket.engineio.client.transports.PollingXHR.access$000(PollingXHR.java:19) [208:org.openhab.io.openhabcloud:2.2.0]
        at io.socket.engineio.client.transports.PollingXHR$4$1.run(PollingXHR.java:88) [208:org.openhab.io.openhabcloud:2.2.0]
        at io.socket.thread.EventThread$2.run(EventThread.java:80) [208:org.openhab.io.openhabcloud:2.2.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
        at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.io.IOException: 400
        at io.socket.engineio.client.transports.PollingXHR$Request$1.run(PollingXHR.java:218) ~[?:?]
        ... 1 more
14:36:31.638 [INFO ] [.io.openhabcloud.internal.CloudClient] - Disconnected from the openHAB Cloud service (UUID = 87b5a82c-88ed-4480-a93e-45562c19a826, base URL = http://localhost:8080)
14:36:34.054 [INFO ] [.io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = 87b5a82c-88ed-4480-a93e-45562c19a826, base URL = http://localhost:8080)
14:36:37.664 [WARN ] [okhttp3.OkHttpClient                 ] - A connection to https://myopenhab.org/ was leaked. Did you forget to close a response body?
14:37:05.577 [WARN ] [okhttp3.OkHttpClient                 ] - A connection to https://myopenhab.org/ was leaked. Did you forget to close a response body?

I’m using tcp for the connection, but it comes out the baud rate is wrong. In the documentation, there is no baud rate setting for the tcp. Which configuration that I go wrong ?

Thank you for your help :smile:

Sorry I know what is wrong with my configuration. In the tcp.slave1.connection I write all the configuration for the modbus including port and everything. But the runtime read it as baud rate so it cannot run the connection. Monday maybe I’ll give update about the configuration if it’s work.

Thanks! :smile:

It seems you have the versions mixed up?

What do you get with bundle:list|grep modbus?

As commented here, binding v2 does not need nor does it support modbus.cfg.

Best,
Sami

Thanks @ssalonen for your reply.

Do you mean I don’t need to install modbus binding for communication to ther PLC ?
Is it because on the things configuration, communication for the modbus has been configured ?

Sorry I’m not really understand about this. As far as I know, openHAB still need modbus binding to communicate to the PLC

Indeed you are correct, you need modbus binding for communicating with modbus slaves from openHAB.

However, you need to decide which version of modbus binding you wish to use.

With version 1 binding, you would use the modbus.cfg. With version 2, you would use the things, and not modbus.cfg.

You should not mix the versions.

Best
Sami

Hi, have you any example for serial modbus configuration? Actual for modbus bindings - from eclipse market. I am little bit lost . first I tried modbus 1, now I see you use modbus from market. my application works with modbuspoll - mbpoll software. I am usin openHAB2.2 under wondows7
sorry I am confused.
thanx Martin

under PAPER UI it works. thanx. next - BASIC UI, I will see

sorry for the very late reply @ssalonen. Finally today I can try to run PLC with openHAB . The result is, it runs but I’m using the version 1 binding. With version 2 binding, the PLC won’t respond to any command from openHAB. But there is still problem with version 1.

Here is my configuration :

version1.items

Switch digital1 "Digital 1 [%d]" {modbus="slave3:0"}
Switch digital2 "Digital 2 [%d]" {modbus="slave3:1"}
Switch digital3 "Digital 3 [%d]" {modbus="slave3:2"}
Switch digital4 "Digital 4 [%d]" {modbus="slave3:3"}
Switch digital5 "Digital 5 [%d]" {modbus="slave3:4"}
Switch digital6 "Digital 6 [%d]" {modbus="slave3:5"}
Switch digital7 "Digital 7 [%d]" {modbus="slave3:6"}
Switch digital8 "Digital 8 [%d]" {modbus="slave3:7"}
Switch digital9 "Digital 9 [%d]" {modbus="slave3:8"}

String analog1 "Analog 1 [%s]" {modbus="<[slave2:0]"}
String analog2 "Analog 2 [%s]" {modbus="<[slave2:1]"}
String analog3 "Analog 3 [%s]" {modbus="<[slave2:2]"}
String analog4 "Analog 4 [%s]" {modbus="<[slave2:3]"}
String analog5 "Analog 5 [%s]" {modbus="<[slave2:4]"}
String analog6 "Analog 6 [%s]" {modbus="<[slave2:5]"}
String analog7 "Analog 7 [%s]" {modbus="<[slave2:6]"}
String analog8 "Analog 8 [%s]" {modbus="<[slave2:7]"}
String analog9 "Analog 9 [%s]" {modbus="<[slave2:8]"}

version1.sitemap

sitemap version1 label="version 1"
{
    Frame {
		Switch item=digital1 label="Digital 1"
		Switch item=digital2 label="Digital 2"
		Switch item=digital3 label="Digital 3"
		Switch item=digital4 label="Digital 4"
		Switch item=digital5 label="Digital 5"
		Switch item=digital6 label="Digital 6"
		Switch item=digital7 label="Digital 7"
		Switch item=digital8 label="Digital 8"
		Switch item=digital9 label="Digital 9"
		
		Default item=analog1 label="Analog 1"
		Default item=analog2 label="Analog 2"
		Default item=analog3 label="Analog 3"
		Default item=analog4 label="Analog 4"
		Default item=analog5 label="Analog 5"
		Default item=analog6 label="Analog 6"
		Default item=analog7 label="Analog 7"
		Default item=analog8 label="Analog 8"
		Default item=analog9 label="Analog 9"
     
		} 
}

modbus.cfg

modbus:poll=50

modbus:tcp.slave3.connection=192.168.0.105
modbus:tcp.slave3.type=coil
modbus:tcp.slave3.start=0
modbus:tcp.slave3.length=9

modbus:tcp.slave2.connection=192.168.0.105
modbus:tcp.slave2.type=holding
modbus:tcp.slave2.start=0
modbus:tcp.slave2.length=9

The problem is :

  1. If I’m using modbus:tcp.slave1.type:holding and modbus:tcp.slave2.type:coil openHAB will read the tcp.slave1 connection as serial connection not tcp. Do you know why it happens ?

  2. with the configuration that I’m using, both slave connection using tcp. But, holding type won’t read input data from the PLC (I’m using Poll Modbus from my Phone to check the communication between openHAB and PLC). What is wrong with holding type ?

Final result for today test is,

  1. PLC Modicon M221 work with version 1 modbus binding for digital input, but for analogue input I’m not getting any clue yet why it’s not working.
  2. Modbus binding version 2 not working yet with M221 PLC and I don’t know why. I’m already following the guide from modbus binding version 2 for alpha testing, but still not getting any working result.
  3. My openHAB read holding type on modbus:tcp.slave1.connection as serial connection if used together with coil type on modbus:tcp.slave2.connection
  4. Even though I already change the connection address (192.168.0.100 to 192.168.0.105), in the log openHAB still try to connect to 192.168.0.100 using modbus:tcp.slave1.connection. It make my log:tail full of error message :frowning:

I think that’s all for result that I get from my test today. Once again sorry for the very late reply.

Thanks a lot :slight_smile: :slight_smile: :slight_smile: