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 ?
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.
# 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 ?
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.
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
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
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.
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 ?
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,
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.
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.
My openHAB read holding type on modbus:tcp.slave1.connection as serial connection if used together with coil type on modbus:tcp.slave2.connection
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
I think that’s all for result that I get from my test today. Once again sorry for the very late reply.