Modbus openHAB2 binding available for alpha testing

openhab2-addons
modbus
binding
Tags: #<Tag:0x00007f1826edc110> #<Tag:0x00007f1826edde70> #<Tag:0x00007f1826edbe90>

(Ssalonen) #162

Updated the development version just now

Changes:

  • removed read, write, and readwrite things
  • added retry (maxTries) for poller (retry with reads) and data (retry with writes)
  • consistent handling of errors in polling and writing, previously
    connection errors were not handled properly with write, for example.
  • some errors now trigger re-connection (e.g. “broken pipe”), while
    with some we re-use the connection (e.g. modbus slave exception
    responses). This is improvement from openHAB1 binding which just retried the write with broken TCP connection (no chance of succeeding even with many retries)
  • transport API changes and cleanup

(Jon Sands) #163

Apologies if this is covered somewhere, but after searching I couldn’t find an answer. I’m on OH2 using the OH1 modbus binding. If I move to this OH2 modbus binding, can I use my existing modbus.cfg definition file? I have over 100 slaves/registers defined and I really don’t want to re-do all of them.

They’re in this format:

# UPS 2 Battery
tcp.slave33.connection=192.168.1.18:502:0
tcp.slave33.id=2
tcp.slave33.start=70
tcp.slave33.length=1
tcp.slave33.type=holding
tcp.slave33.valuetype=uint16

(Lukasz Knop) #164

@ssalonen Great job on the binding! I have been testing it for a while (I only use modbus RTU devices) and from my tests it proves to be very reliable. However, it seems to have issues with the plugwise binding.

Plugwise is a zibee-like network, communicates with OH2 via a usb-stick device, itself using a ftdi usb-serial adapter. When I am using the plugwise binding on a different serial port, the modbus binding crashes after some time and stops communicating with the rs485 adapter (I am using a usb-rs485 gateway, non-ftdi one). The OS is debian linux and I am polling quite often - every 200ms. I have done quite a lot of similar work in the past so I should be able to debug this myself but I am looking for pointers where the culprit may be to isolate the problem.

Is anyone having problems (or, perhaps, no problems) with modbus-RTU communication interfering with another serial-based protocol?
Is OH2 serial connection using some locks on hardware resources?
Any other suggestions where to look for?

Thanks in advance for any help.


(Miika Jukka) #165

I’d say no. Configuration files are very much different. You can find examples of them in this topic and here’s the link to documentation. https://github.com/ssalonen/openhab2-addons/blob/modbus-openhab2-native-binding/addons/binding/org.openhab.binding.modbus/README.md


(Ssalonen) #166

Thanks for reporting this!

Sounds very peculiar. What do you mean that binding “crashes”? Do you have any logs?

Sami


(Ssalonen) #167

Documentation also has section regarding this very topic, “Changes from Modbus 1.x binding”.


(Nanna Agesen) #168

Hi There

Anyone experience High CPU load with the new Modbus Binding Latest update.

I’m running openhab in a virtual environment, with the version before Developer I had 0% Cpu load, with the latest version this has increased to 20% and a delay in the modbus communication about 45 Seconds.


(Nanna Agesen) #169

I haven’t found any errors in the log, only thing is I have a lot of retries - i’m not sure if this is the issue?

08:49:09.746 [TRACE] [ling.ModbusSlaveConnectionFactoryImpl] - ...Passivated connection TCPMasterConnection@63f1ff8e[socket=Socket[addr=/192.168.100.86,port=502,localport=55584]] for endpoint ModbusTCPSlaveEndpoint@397baf44[address=192.168.100.86,port=502]
08:49:09.747 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - returned connection for endpoint ModbusTCPSlaveEndpoint@397baf44[address=192.168.100.86,port=502]
08:49:09.747 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Connection was returned to the pool, ending operation [operation ID c9bcd454-664a-475a-9958-f5630dff7d61]
08:49:09.747 [DEBUG] [ort.modbus.internal.ModbusManagerImpl] - Executing scheduled (5000ms) poll task PollTaskImpl@4076dbcb[request=ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@35d6353c[slaveId=30,functionCode=READ_MULTIPLE_REGISTERS,start=0,length=1,maxTries=3],endpoint=ModbusTCPSlaveEndpoint@4f622851[address=192.168.100.30,port=502],callback=java.lang.ref.WeakReference@175b0a01]
08:49:09.747 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Executing task PollTaskImpl@4076dbcb[request=ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@35d6353c[slaveId=30,functionCode=READ_MULTIPLE_REGISTERS,start=0,length=1,maxTries=3],endpoint=ModbusTCPSlaveEndpoint@4f622851[address=192.168.100.30,port=502],callback=java.lang.ref.WeakReference@175b0a01] (oneOff=false)! Waiting for connection [operation ID 1eb5e2d5-df66-4299-9078-d248815cee63]
08:49:09.768 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Response for read request (FC=3, transaction ID=29927): 74 e7 00 00 00 13 1e 03 10 00 1f 00 01 00 01 00 02 08 98 00 00 13 88 00 00  [operation ID 6c6683b3-1428-423e-92a3-1fbdc8405718]
08:49:09.768 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Try 2 out of 3 [operation ID 6c6683b3-1428-423e-92a3-1fbdc8405718]
08:49:09.768 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Ensuring that enough time passes before retrying again. Sleeping [operation ID 6c6683b3-1428-423e-92a3-1fbdc8405718]
08:49:09.798 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Sleep ended [operation ID 6c6683b3-1428-423e-92a3-1fbdc8405718]
08:49:09.799 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Going execute transaction with request request (FC=READ_MULTIPLE_REGISTERS): 00 00 00 00 00 06 1e 03 03 e8 00 08  [operation ID 6c6683b3-1428-423e-92a3-1fbdc8405718]
08:49:09.828 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Response for read request (FC=3, transaction ID=29930): 74 ea 00 00 00 13 1e 03 10 00 1f 00 01 00 01 00 02 08 98 00 00 13 88 00 00  [operation ID 6c6683b3-1428-423e-92a3-1fbdc8405718]
08:49:09.828 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Try 3 out of 3 [operation ID 6c6683b3-1428-423e-92a3-1fbdc8405718]
08:49:09.828 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Ensuring that enough time passes before retrying again. Sleeping [operation ID 6c6683b3-1428-423e-92a3-1fbdc8405718]
08:49:09.828 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Sleep ended [operation ID 6c6683b3-1428-423e-92a3-1fbdc8405718]
08:49:09.828 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Going execute transaction with request request (FC=READ_MULTIPLE_REGISTERS): 00 00 00 00 00 06 1e 03 03 e8 00 08  [operation ID 6c6683b3-1428-423e-92a3-1fbdc8405718]
08:49:09.907 [TRACE] [ort.modbus.internal.ModbusManagerImpl] - Response for read request (FC=3, transaction ID=29931): 74 eb 00 00 00 13 1e 03 10 00 1f 00 01 00 01 00 02 08 98 00 00 13 88 00 00  [operation ID 6c6683b3-1428-423e-92a3-1fbdc8405718]

(Ssalonen) #170

Thanks @Nanna_Agesen, the latest version had a bug – the modbus requests were retried even though they were successful. :stuck_out_tongue:

Fixed version is now building, and should be updated in 10mins.


(Joris Palmas) #171

Can you run this binding in parallel to 1.10 to test?


(Ssalonen) #172

Not sure, haven’t tried. Feel free to test and report back, though!

I have a feeling that it might not work since the binding has the same name org.openhab.binding.modbus.


(Nanna Agesen) #173

Great Thanks :slight_smile:


(Nanna Agesen) #174

Yes - I did that for 4 weeks during converting all code to the new binding - works perfect.


(Nanna Agesen) #175

@ssalonen Just to confirm it looks good now, I have the same CPU load as before and no delay :slight_smile:


(Miika Jukka) #176

Hi!

I’m getting connection errors. Everything works but always the first connection attempt gets Connection refused. Updating to newest build didn’t solve this. @ssalonen might rememeber my case but i’ll paste my .things file also.

modbus.things

Bridge modbus:tcp:endpointTCP [ host="192.168.1.100", port=502, id=2, connectMaxTries=3, timeBetweenTransactionsMillis=100 ] {
    Bridge poller coils [ start=2, length=4, refresh=30000, type="coil" ] {
        Thing data do2 [ readStart="2", readValueType="bit", writeStart="2", writeValueType="bit", writeType="coil" ]
        Thing data do3 [ readStart="3", readValueType="bit", writeStart="3", writeValueType="bit", writeType="coil" ]
        Thing data do4 [ readStart="4", readValueType="bit", writeStart="4", writeValueType="bit", writeType="coil" ]
        Thing data do5 [ readStart="5", readValueType="bit", writeStart="5", writeValueType="bit", writeType="coil" ]
    }

 	Bridge poller holding [ start=0, length=14, refresh=30000, type="holding" ] {
        Thing data mh4 [ readStart="0", readValueType="uint16", readTransform="JS(divide.js)" ]
        Thing data ph [ readStart="2", readValueType="uint16", readTransform="JS(divide.js)" ]
        Thing data phrh [ readStart="3", readValueType="uint16", readTransform="JS(divide.js)" ]
        Thing data mh1 [ readStart="4", readValueType="uint16", readTransform="JS(divide.js)" ]
        Thing data mh2 [ readStart="6", readValueType="uint16", readTransform="JS(divide.js)" ]
        Thing data mh3 [ readStart="8", readValueType="uint16", readTransform="JS(divide.js)" ]
        Thing data oh [ readStart="10", readValueType="uint16", readTransform="JS(divide.js)" ]
        Thing data tekn [ readStart="12", readValueType="uint16", readTransform="JS(divide.js)" ]
        Thing data teknrh [ readStart="13", readValueType="uint16", readTransform="JS(divide.js)" ]
    } 
}

openhab.log

15:35:08.639 [DEBUG] [ort.modbus.internal.ModbusManagerImpl] - Executing scheduled (30000ms) poll task PollTaskImpl@7e7482b2[request=ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@3097612e[slaveId=2,functionCode=READ_COILS,start=2,length=4,maxTries=3],endpoint=ModbusTCPSlaveEndpoint@6557e86[address=192.168.1.100,port=502],callback=java.lang.ref.WeakReference@7d5cf1df]
15:35:08.678 [DEBUG] [.wimpi.modbus.net.TCPMasterConnection] - connect()
15:35:08.704 [TRACE] [.wimpi.modbus.io.ModbusTCPTransaction] - Sending request with transaction ID 34818: net.wimpi.modbus.msg.ReadCoilsRequest@49cc5b41
15:35:08.731 [TRACE] [.wimpi.modbus.io.ModbusTCPTransaction] - Received response with transaction ID 34818
15:35:08.741 [TRACE] [net.wimpi.modbus.util.BitVector      ] - Get bit #0
15:35:08.751 [TRACE] [net.wimpi.modbus.util.BitVector      ] - Get bit #1
15:35:08.760 [TRACE] [net.wimpi.modbus.util.BitVector      ] - Get bit #2
15:35:08.769 [TRACE] [net.wimpi.modbus.util.BitVector      ] - Get bit #3
15:35:08.803 [TRACE] [.wimpi.modbus.io.ModbusTCPTransaction] - Sending request with transaction ID 34819: net.wimpi.modbus.msg.ReadCoilsRequest@4a579a86
15:35:08.819 [TRACE] [.wimpi.modbus.io.ModbusTCPTransaction] - Received response with transaction ID 34819
15:35:08.827 [TRACE] [net.wimpi.modbus.util.BitVector      ] - Get bit #0
15:35:08.833 [DEBUG] [ort.modbus.internal.ModbusManagerImpl] - Executing scheduled (30000ms) poll task PollTaskImpl@54423ec1[request=ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@5539e580[slaveId=2,functionCode=READ_MULTIPLE_REGISTERS,start=0,length=14,maxTries=3],endpoint=ModbusTCPSlaveEndpoint@6557e86[address=192.168.1.100,port=502],callback=java.lang.ref.WeakReference@607579f2]
15:35:08.829 [TRACE] [.wimpi.modbus.io.ModbusTCPTransaction] - Sending request with transaction ID 34820: net.wimpi.modbus.msg.ReadCoilsRequest@77725931
15:35:08.835 [TRACE] [net.wimpi.modbus.util.BitVector      ] - Get bit #1
15:35:08.874 [TRACE] [.wimpi.modbus.io.ModbusTCPTransaction] - Received response with transaction ID 34820
15:35:08.883 [TRACE] [net.wimpi.modbus.util.BitVector      ] - Get bit #0
15:35:08.875 [TRACE] [net.wimpi.modbus.util.BitVector      ] - Get bit #2
15:35:08.892 [TRACE] [net.wimpi.modbus.util.BitVector      ] - Get bit #1
15:35:08.891 [DEBUG] [.wimpi.modbus.net.TCPMasterConnection] - connect()
15:35:08.912 [TRACE] [net.wimpi.modbus.util.BitVector      ] - Get bit #2
15:35:08.902 [TRACE] [net.wimpi.modbus.util.BitVector      ] - Get bit #3
15:35:08.931 [ERROR] [ling.ModbusSlaveConnectionFactoryImpl] - connect try 1/3 error: Yhteys torjuttu (Connection refused). Connection TCPMasterConnection@201e33e6[socket=Socket[unconnected]]. Endpoint ModbusTCPSlaveEndpoint@6557e86[address=192.168.1.100,port=502]
15:35:08.931 [TRACE] [net.wimpi.modbus.util.BitVector      ] - Get bit #3
15:35:09.050 [DEBUG] [.wimpi.modbus.net.TCPMasterConnection] - connect()
15:35:09.062 [TRACE] [.wimpi.modbus.io.ModbusTCPTransaction] - Sending request with transaction ID 34821: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@22cf37b1
15:35:09.094 [TRACE] [.wimpi.modbus.io.ModbusTCPTransaction] - Received response with transaction ID 34821
15:35:09.162 [TRACE] [.wimpi.modbus.io.ModbusTCPTransaction] - Sending request with transaction ID 34822: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@1ad0c490
15:35:09.195 [TRACE] [.wimpi.modbus.io.ModbusTCPTransaction] - Received response with transaction ID 34822
15:35:09.202 [TRACE] [.wimpi.modbus.io.ModbusTCPTransaction] - Sending request with transaction ID 34823: net.wimpi.modbus.msg.ReadMultipleRegistersRequest@3f0202f3
15:35:09.216 [TRACE] [.wimpi.modbus.io.ModbusTCPTransaction] - Received response with transaction ID 34823

While writing this post I tested with different refresh rates. Coil poller with 30000ms and Holding register poller with 20000ms so about every third polling hapens at same time and that’s when i get these connection refused errors. After this I changed rates back to 30000ms and added timeBetweenReconnectMillis=100 setting to .things file but no help.

Seems that my S1200 is a bit slow responder. Is it something in your code or in my settings that’s wrong?

Edit #1
Putting timeBetweenReconnectMillis=1000 seems to work. Feels a bit long time doesn’t it?


(Ssalonen) #177

Thanks @gitMiguel

I actually have S1200 as well so I have noticed the same issue with openHAB1 binding already. My understanding is that the root cause is with the slave, not with the binding. As a real time system, with hardware interrupts, the PLC can accept the modbus connection only at certain times – otherwise it refuses the connection attempt. At least I can only see these connection level issues with the PLC but not with local server, for example.

For maximum performance, I would increase number of connection retries, and keep the try interval between those very short. For example, (tcp thing)

connectMaxTries=10
timeBetweenReconnectMillis=100

You might want to also keep the connection open for longer, e.g. 60 seconds:

reconnectAfterMillis=60000

While writing this post I tested with different refresh rates. Coil poller with 30000ms and Holding register poller with 20000ms so about every third polling hapens at same time and that’s when i get these connection refused errors.

The binding should not execute two polls at the same time, only one connection and one transaction is active at once.

To rule out any possible issues with the binding, you can bombard the slave with command line tools (modpoll):

for i in $(seq 100); do echo Trying poll; date +%s%N;./modpoll -1 -o 0.1 -m tcp 192.168.1.100 ; done

Or even simpler, just try to establish TCP connection using nc:

for i in $(seq 100); do echo -n "Trying to connect $(date +%s%N|tr -d '\n'): $(nc -4 -z -v 192.168.1.100 502 | tr -d '\n')" ; done

For example, with my S1200:

Trying to connect 1510073863109626372: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073863142576993: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073863185484134: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073863218088977: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073863259630610: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073863291970509: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073863337910589: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073863370133040: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073863412766017: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073863446110489: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073863492385618: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073863539760424: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073863583162977: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073863626523030: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073863666622749: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073863699325717: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073863743331857: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073863773945210: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073863815726944: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073863848356579: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073863893408908: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073863924892095: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073863964586506: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864000037937: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864040377394: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864075629973: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864118639717: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864149993739: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864191608652: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864224933177: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864270921954: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864303159562: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864346151181: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864377542390: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864417548830: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864449493419: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864487165402: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864531856952: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864572319064: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864612869405: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864646044763: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864688982373: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864721579873: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864762096671: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864795543590: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864832829066: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864871088022: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864916346651: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073864947938327: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073864992149153: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865023929369: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073865065662146: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865098484175: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073865139024203: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865171975397: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073865215369929: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865246289320: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073865289698643: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865320785950: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073865363319500: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865396601420: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073865439529759: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865471709763: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865520906114: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073865567238742: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865598083759: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073865640512154: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865672793876: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073865716728872: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865747663731: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073865791812214: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865822428118: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073865868492572: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865900418412: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073865940913388: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073865973504430: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073866016451206: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073866048999383: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073866093359791: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073866124579648: Connection to 192.168.1.100 502 port [tcp/*] succeeded!
Trying to connect 1510073866167912149: nc: connect to 192.168.1.100 port 502 (tcp) failed: Connection refused
Trying to connect 1510073866199328567: Connection to 192.168.1.100 502 port [tcp/*] succeeded!

From the log you can determine that the pc tried out to connect every ~30-40ms, and every other connection attempt fails. So you might want to reduce timeBetweenReconnectMillis even to 30 or so.

With local server (diagslave), you will not get such behaviour.

Best,
Sami


(Miika Jukka) #178

I don’t know much about hardware interrupts and believe you are right about that. But if I have understood documentation right, S1200 can only handle one connection at a time per MB_SERVER. And here lies my problem.

As you suggested I switched timeBetweenReconnectMillis=1000 to reconnectAfterMillis= with value larger than my polling rates. So this keeps the connection open constantly if I understand right. Errors are now gone. Now if I poll my S1200 let’s say once a minute I don’t want to keep the connection open whole time because then nothing else can connect to it. I think here’s more appropriate to use timeBetweenReconnectMillis=

To me it seems that this is exactly what is happening. Connection isn’t properly closed before another is opened. But can some kind of hardware problem cause this? Because looks like I’m the only one suffering from it.

I tested using default values and as long as you have the connection open, S1200 can respond quite fast to consecutive polls. But when it comes opening and closing the connection, then it is slow.


(Ssalonen) #179

Actually, reconnectAfterMillis means that connection is… Reconnected after this many milliseconds. For example if reconnectAfterMillis is 10000 or 10 seconds, the connection is kept open for 10s (at least), and then closed. I believe connection age will be checked after every modbus transaction (read or write).

Sorry for the bad parameter naming, it’s a bit confusing.

It is also true that s1200 can handle only one connection at a time. In fact, some other slaves are like this plc, and that was the original reason for introducing strict connection sharing in the old binding. If you would like to keep connection free for other clients, you probably do not want to use reconnectAfterMillis, and go with default (connection closed after every transaction). That is no issue but with this plc you need to prepare to get “connection refused” errors, I think. That’s where retrying establishing connection becomes important.

I was a bit hasty with my previous reply regarding connection retries. The binding will retry the connection in case of errors (e.g. Connection refused like with you). A certain time is spent between each retry: max(timeBetweenReconnectMillis, timeBetweenTransactionsMillis). Furthermore, the number of connection attempts is specified with connectMaxTries)

The default for connection attempts is actually 1, so that’s why you do not see the retries with connection. That’s why it’s important to change it, see my example above with 10 connection attempts.

For fast retries with connection attempts, you need to lower timeBetweenReconnectMillis and timeBetweenTransactionsMillis. Actually, you want to disconnect after every transaction, and since the binding re-attempts connection after max(timeBetweenReconnectMillis, timeBetweenTransactionsMillis) milliseconds, you can just drop out timeBetweenReconnectMillis (default 0) and play with timeBetweenTransactionsMillis . Something like

timeBetweenTransactionsMillis=35
maxTries=10

(leave out timeBetweenReconnectMillis and reconnectAfterMilli)

I think this PLC starts to have performance issues when the time between transactions/connections gets lower than 35 ms or something like that. You can try different values and find the best settings for you.

Hope this helps! Let me know how it goes…


(Miika Jukka) #180

Not trying to be a difficult here but I’ll explain these errors once more. I think I didn’t made myself clear in the beginning. It’s sometimes hard to put my thoughs to words.

From the beginning connectionMaxTries has always been 3.

Bridge modbus:tcp:endpointTCP [ host="192.168.1.100", port=502, id=2, connectMaxTries=3, timeBetweenTransactionsMillis=100 ] {

First time I got this setup running with this binding I also had similar errors but putting timeBetweenTransactionsMillis=100 (as above) those errors were fixed. Now same kind of errors came back few updates ago. Today I tested all kinds of combinations as you suggested and the only time they aren’t showing is when I have only one poller. And when i have only one of them (one holding register), polling rate can be as low as 100ms. Adding another poller forces me to raise the rate to at least 500ms and keep connection continuously open.

But then again, I might be totally on the wrong tracks and just don’t understand your posts. :slight_smile:

After all these testings I’m starting to think that if I want to get rid of all these errors I’ll setup a second MB_SERVER.

One more question regarding different config. I need to get 9 status bits from the same PLC. I have created an array of booleans in the holding register. Have you ever tried to read this kind of array through modbus with openHAB. I can’t get it to work and think there might be something wrong with my addressing.


(Ssalonen) #181

Thanks for this, really opens up the issues. Does not make sense indeed that errors happen with two pollers but not with one poller.

Can you please provide verbose logs with 1) one poller 2) two pollers and timeBetweenTransactionsMillis=100 so I can see how it looks like with verbose log?

And for just in case, can you share things config for both cases?

Best,
Sami