Reading data from Huawei inverter SUN 2000 (3KTL-10KTL) via modbus TCP and RTU

I saw this with parallel connections to dongle. If
You have two separate tcp connections SDongle will get crazy, it is able to send reply from first connection to the second. I collected a sample pcap with this and I am certain it happens because I saw a reply with completely odd transaction id from other openhab connection which ran much longer.

Hi @Andreas_Pircher,

you are using a super aggressive poller refresh of 2sec (refresh=2000) or 10sec (refresh=10000). You may reduce the poll rate by increasing the refresh to something larger - like I use 1min (refresh=60000). I guess the SDonge cannot cope with such a high poll rate.

Good luck!

It can under a primary condition: you have a single TCP connection to it which is retained over long time. I know that support advices polling of 5 secs or more but its not justified by anything but their promise.

This means that even if there is a failure with an payload or something else, connection should not be terminated. Otherwise you get into re-initialization cycle and re-establishment of RTU communication between dongle and inverter itself. The more reconnects you have, the less stable dongle is.
If you get two TCP connections (ie openhab and mbpoll or other agent), then SDongle will become unstable as well.

I made a test with an even more aggressive scan of 500 ms and 250 ms inter transaction gap and it worked just fine. I reverted to 5 secs to not spam storage with too much of power data. :slight_smile: I had two inverters and two dongles and both survived the same test.

… well, with a cascading setup where each inverter has its own ModbusID, I have to setup 2 Modbus TCP Slaves connecting to the single SDongle on the master inverter. This counts as multi-connection?

I see occational warnings on mismatching transaction IDs across both ModbusIDs as well as the 4 Modbus Pollers I have setup. I need to check the event timeline to see if there are specific conditions where the warnings occure. So far things work pretty good.

No, the openHAB binding is smart enough to run just one TCP connection for all pollers targeting one hostname/IP address.
BUT
for that to happen you must be careful to configure all the TCP settings the same. I think its hard to mess that up, the configure validation complains otherwise - check in the logs at binding startup time.
It is the dongle’s job to just pass the ID through to the serial bus.

So, no matter which device a transaction is associated with, we should be getting back sensible packet sequence numbers. All openHAB’s polls to different IDs are part of the same sequence.

The problem @splatch is describing is about two different servers polling the dongle, and the dongle sending the response to query from server “X” to server “Y” by mistake. “Server Y” might be a phone app, etc.

I think I’ve seen other gateways make the same mistake, probably to do with sending a serial response message to whichever server queried last (which isn’t necessarily the one that queried for that message).

Having said all that …

There is another way for this to happen.
openHAB has no control of the timeout the gateway allows on the serial side, we are relying on the TCP side timeout.
So let’s say OH sends a poll “A”, there’s no response for a while. OH timeout occurs, abandons it, logs it and starts the next poll “B”…
Meantime the serial response “A” arrives back at the dongle/gateway, which hasn’t timed it out, so it sends the late message “A” to OH.
OH is waiting for response to poll B, not A, and complains because it doesn’t match…

Easiest way to confirm this is running single endpoint at the time. If you get stable operations with single connection talking to single slave and failures with two then its issue of dongle. If even one slave is a problem then its issue of the configuration.

I would not be surprised if that thing would fail with two slaves. I saw it miss-behaving when I was changing tcp unit id as well.

5 posts were split to a new topic: Help with USB RS485 Converter

Hi all,

I try to connect OH 3.2 to a Huawei Sun 2000 via Modbus- TCP but I get this error every time.

2022-06-26 19:46:56.526 [ERROR] [rt.modbus.internal.ModbusManagerImpl] - Last try 1 failed when executing request (ModbusReadRequestBlueprint [slaveId=1, functionCode=READ_MULTIPLE_REGISTERS, start=32000, length=1, maxTries=1]). Aborting. Error was I/O error, so resetting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: SocketTimeoutException Read timed out [operation ID c8b8319d-1054-41a4-9f27-b1e9cbb7ce52]

Modbus TCP Slave Thing:
UID: modbus:tcp:bdc5541c40
label: Modbus TCP Slave
thingTypeUID: modbus:tcp
configuration:
timeBetweenTransactionsMillis: 250
connectMaxTries: 3
reconnectAfterMillis: 1300
port: 502
timeBetweenReconnectMillis: 10000
host: 192.168.10.182
connectTimeoutMillis: 10000
afterConnectionDelayMillis: 2000
id: 1
enableDiscovery: false

Poller Thing:
UID: modbus:poller:bdc5541c40:23170e4020

Thanks in advance
label: Regular Poll
thingTypeUID: modbus:poller
configuration:
length: 1
start: 32000
refresh: 15000
maxTries: 1
cacheMillis: 50
type: holding
bridgeUID: modbus:tcp:bdc5541c40

IP- Inverter: 192.168.10.182
IP-Dongle: 192.168.10.183

I have the wLAN-Dongle and Modbus activated in the Huawei settings.

OH sent its poll, but there was no reply. Not much more we can tell from this end.

In general, check your IP address, routing, modbus ID.

Hi rossko57,

thanks for your reply.
I tried it with a other modbus client software and the same connection parameters and recieve some values.

.
I tried it with the dongle ip and inverter ip but without success.
Any ideas?

You seem to have a timeout error with your other utility as well.

@tlrider, did you somehow resolve the problem?
i am currently using the SUN2000-8KTL-M1 firmware
V100R001C00SPC145 and a SDongleA with firmware V100R001C00SPC128. My PI 3b running Openhab 3.3 is connected to the same switch as the Dongle.

2022-06-29 23:34:09.498 [ERROR] [rt.modbus.internal.ModbusManagerImpl] - Last try 3 failed when executing request (ModbusReadRequestBlueprint [slaveId=1, functionCode=READ_MULTIPLE_REGISTERS, start=30073, length=10, maxTries=3]). Aborting. Error was I/O error, so resetting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: EOFException null [operation ID 8af19212-950a-4e53-8caa-8281c5364278]

my thing config looks like:
Bridge modbus:tcp:localhostTCP [ host=“192.168.1.104”, port=502, id=1, timeBetweenTransactionsMillis=1200, rtuEncoded=false, connectMaxTries=1, reconnectAfterMillis=0, timeBetweenReconnectMillis=0, connectTimeoutMillis=10000, enableDiscovery=false ]{

Bridge poller slave101holding [ start=30073, length=10, refresh=10000, type=“holding” ]{

    Thing data Rated_power                      [ readStart="30073", readValueType="uint32",readTransform="JS(divide1000.js)",updateUnchangedValuesEveryMillis="5000000" ]
    Thing data Maximum_active_power             [ readStart="30075", readValueType="uint32",readTransform="JS(divide1000.js)",updateUnchangedValuesEveryMillis="5000000" ]
    Thing data Maximum_apparent_power           [ readStart="30077", readValueType="uint32",readTransform="JS(divide1000.js)",updateUnchangedValuesEveryMillis="5000000" ]
    Thing data Maximum_reactive_power_fed       [ readStart="30079", readValueType="int32",readTransform="JS(divide1000.js)",updateUnchangedValuesEveryMillis="5000000" ]
    Thing data Maximum_reactive_power_absorbed  [ readStart="30081", readValueType="int32",readTransform="JS(divide1000.js)",updateUnchangedValuesEveryMillis="5000000" ]

… and all other lines out of the config in the opening thread.

thanks for any reply.

Does that mean you are trying to run some target with two modbus masters? This is permissable with Modbus-TCP … but not all slaves or gateways implement it.

not sure if i understand your question correctly. I think the SDongleA is the modbus master and openhab is configured as slave. The SDongle is connected to LAN and as i read several threads with timeout issues, i just wanted to express that the SDongle is connect to the same network switch.
The modbus bridge always shows as “Online” in OH3.

Okay, that’s clear and fine.
In fact openHAB is Modbus-TCP master.
The dongle is more complicated, because it acts as a gateway. On it’s serial side it acts as Modbus-RTU master.
On its TCP side, it acts as Modbus-TCP slave.

Hi oschwabe,

sorry for the late reply I was not at home.
Yes, an update to OH 3.3 solved my problem. I can now connect to the inverter an recieve all data I want.
If you need I can share my config.

Hello,

I have managed to connect to SUN2000-5KTL-M1 using WLAN-FE Smart Dongle and modbus TCP.
I am running Openhab version 3.2 on RPI3B+. I have a few items defined and they are updated by the binding. However, I have a regular warning message in the log as follows:

2022-07-07 10:24:59.416 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 1 out of 3 failed when executing request (ModbusReadRequestBlueprint [slaveId=1, functionCode=READ_MULTIPLE_REGISTERS, start=32069, length=19, maxTries=3]). Will try again soon. Error was I/O error, so resetting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: SocketTimeoutException Read timed out [operation ID ac0bf193-1979-4cc3-a33f-77daca5f2741]
2022-07-07 10:25:34.952 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 1 out of 3 failed when executing request (ModbusReadRequestBlueprint [slaveId=1, functionCode=READ_MULTIPLE_REGISTERS, start=32069, length=19, maxTries=3]). Will try again soon. Error was I/O error, so resetting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: SocketTimeoutException Read timed out [operation ID 87f71476-92c2-46cd-b094-769628794c59]
2022-07-07 10:26:10.071 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 1 out of 3 failed when executing request (ModbusReadRequestBlueprint [slaveId=1, functionCode=READ_MULTIPLE_REGISTERS, start=32069, length=19, maxTries=3]). Will try again soon. Error was I/O error, so resetting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: SocketTimeoutException Read timed out [operation ID 34e09ba7-184a-458b-8ac9-5a2dff3e98ba]

Is there a way to tune the modbus setting in OpenHab to avoid the warning ( shall I move to version 3.3 stable)? My current set up is as follows:

UID: modbus:tcp:4801b83789
label: Modbus TCP Slave SUN2000
thingTypeUID: modbus:tcp
configuration:
  rtuEncoded: false
  timeBetweenTransactionsMillis: 1500
  connectMaxTries: 1
  reconnectAfterMillis: 0
  port: 502
  timeBetweenReconnectMillis: 0
  host: 192.168.x.x
  connectTimeoutMillis: 10000
  id: 1
  enableDiscovery: false
UID: modbus:poller:4801b83789:e626774474
label: Modbus SUN2000 Poll105
thingTypeUID: modbus:poller
configuration:
  start: 32069
  length: 19
  refresh: 30000
  maxTries: 3
  cacheMillis: 50
  type: holding
bridgeUID: modbus:tcp:4801b83789

Thank you for any replay

@RafalO I believe you need a afterConnectionDelayMillis option for that thing. Look few posts up:

This was ultimately what I had to add to stabilize dongle behavior. I’d advise disabling retry on poler as well. With 30s poll cycle you better wait for another round, otherwise you risk stressing dongle too much. :wink:

2 Likes

Thank you for indicating. So I need to move to version 3.3 to have afterConnectionDelayMillis option avaiable. Then testing.

I can confirm that after upgrading to v3.3.0 and setting afterConnectionDelayMillis=2000 I do not have warnigs in the log :smiley: