MODBUS: connect timed out

Hello,
I’ve stuck with issue trying to establish a basic connection to my controller over Modbus TCP binding
I am continuously getting “connection time out error”. :frowning_face:

Some facts:

  • I am able to ping and telnet controller.
  • I am able to communicate with the controller using another tool(ModbusPoll -> ConnectionType:Modbus TCP/IP)
  • There are no active telnets and ModbusPoll connection when openhab is trying to connect and failing
  • I can’t establish a connection from ModbusPoll or telnet when openhabian is continuously pooling controller
  • I play with bridge timeout values up to 3 seconds - does not help
  • Controler - Owen Plc 110

Thing config(based on provided example in doc):
Bridge modbus:tcp:oven “Modbus Bridge” [ host = “192.168.31.31”, port = 502, id = 0, connectTimeoutMillis = 4000, timeBetweenReconnectMillis = 2000 ] {
// // read-write for holding registers. Reading 4 registers, with index 1500, 1501, 1502, 1503.
// // These correspond to holding register numbers 401501, 401502, 401503, 401504.
Bridge poller holding [ start=0, length=1, refresh=3000, type=“holding”] {
Thing data holding1500 [ readStart=“0”, readValueType=“int16”, writeStart=“0000”, writeValueType=“int16”, writeType=“holding” ]
}
}
I’ve also play with reading coils - the same exeption.

LOG:

2019-03-16 13:27:14.796 [DEBUG] [wimpi.modbus.net.TCPMasterConnection] - connect()

2019-03-16 13:27:18.803 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 1/1 error: connect timed out. Connection TCPMasterConnection@69cd74[socket=Socket[unconnected]]. Endpoint ModbusTCPSlaveEndpoint@87c8ca[address=192.168.31.31,port=502]

2019-03-16 13:27:18.807 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - re-connect reached max tries 1, throwing last error: connect timed out. Connection TCPMasterConnection@69cd74[socket=Socket[unconnected]]. Endpoint ModbusTCPSlaveEndpoint@87c8ca[address=192.168.31.31,port=502]

2019-03-16 13:27:18.810 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - Error connecting connection TCPMasterConnection@69cd74[socket=Socket[unconnected]] for endpoint ModbusTCPSlaveEndpoint@87c8ca[address=192.168.31.31,port=502]: connect timed out

2019-03-16 13:27:18.815 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Could not connect to endpoint ModbusTCPSlaveEndpoint@87c8ca[address=192.168.31.31,port=502] – aborting request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@821ede[slaveId=0,functionCode=READ_MULTIPLE_REGISTERS,start=0,length=1,maxTries=3] [operation ID fa0ab1ff-9060-42f4-8926-6c0b6db710fc]

2019-03-16 13:27:18.818 [ERROR] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:oven:holding:holding1500 ‘Modbus data’ had ModbusConnectionException error on read: ModbusConnectionException(Error connecting to endpoint=ModbusTCPSlaveEndpoint@87c8ca[address=192.168.31.31,port=502])

2019-03-16 13:27:21.829 [DEBUG] [wimpi.modbus.net.TCPMasterConnection] - connect()

That looks wrong? Slave ID 0 is reserved for “broadcast” in Modbus. I believe most slaves do not respond to broadcasts by design.

This is not register 1500 of course?

For testing, you can remove all data Things and just play with the bridge things to establish polling.

The behaviour of any given slave if you attempt to read undefined registers is unpredictable - some reject with message, some don’t respond (timeout)

Great thanks for such a quick response :grinning:

  • First register is declared and populated with some int16 value.
  • 1500 was copied from the example ) As I Understand it is just a name and should not affect communication.
  • In my codesys config it is this way (id=0) ModbusSlave -> Modbus[FIX] -> TCP[VAR] -> id = 0, but actually I tried to change id in both places to be 1

I just found in binding doc
-" the binding does not support Modbus RTU over Modbus TCP, also known as “Modbus over TCP/IP” or “Modbus over TCP” or “Modbus RTU/IP”, although normal "
Modbus TCP" is supported. …" :thinking::thinking:

And from another tool, mu successful connection was established with option Modbus Tcp/Ip

So I suppose my controller could not accept protocol type that Binding does - am I right ?

I sniff network requests and found interesting info
Looks like binding try to send some TCP requests and all that request fails with RST (connection reset)
But pooler bridge pools sometimes port 502 with Modbus request and gets an OK response from it.

Bridge modbus:tcp:oven “Modbus Bridge” [ host = “192.168.31.31”, port = 502, id = 1, connectTimeoutMillis = 4000, timeBetweenReconnectMillis = 2000 ] {
Bridge poller holding [ start=0, length=1, refresh=3000, type=“holding”] {
Thing data holding1 [ readStart=“0”, readValueType=“int16”, writeStart=“0000”, writeValueType=“int16”, writeType=“holding” ]
}
}

I don’t know what that means, but slave ID of 0 is not valid in ordinary Modbus protocol, so it would be pot luck if it happened to work in the OH binding or not. If this is under your control, don’t set it to 0.

That is correct.
Modbus-RTU is the “original” serial protocol.
Modbus-TCP is the most common TCP/IP version of the protocol.

There is another format which packages the serial form and sends it over TCP, “Modbus RTU over TCP”, which the OH binding does not support. You’ll need to work out which version your slave supports.

Okay.