core: modbus callback_data problem

The problem

After update to core-2024.4.3, still the same problem that started after core update to 2024.4.0, see #115114, #115236, #115348 core-2024.4.3 solved the problems unfortunately not yet. Even a complete reboot of the system did not help.

Python-Version 3.12.2 Linux 6.1.73-haos-raspi aarch64 Home Assistant OS 12.2 stable supervisor-2024.04.0

What version of Home Assistant Core has the issue?

core-2024.4.3

What was the last working version of Home Assistant Core?

core-2024.3.3

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

modbus_sungrow.yaml

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

I am using
https://github.com/mkaiser/Sungrow-SHx-Inverter-Modbus-Home-Assistant/blob/main/modbus_sungrow.yaml

without changes.

Version from 2024-04-05

Anything in the logs that might be useful for us?

Logger: pymodbus.logging
Quelle: runner.py:189
Erstmals aufgetreten: 14:13:28 (152 Vorkommnisse)
Zuletzt protokolliert: 19:33:37
General exception: index out of range


**Followed each time by this error:**


Logger: homeassistant
Quelle: /usr/src/homeassistant/homeassistant/runner.py:146
Erstmals aufgetreten: 14:13:28 (152 Vorkommnisse)
Zuletzt protokolliert: 19:33:37
Error doing job: Fatal error: protocol.data_received() call failed.

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 1017, in _read_ready__data_received
    self._protocol.data_received(data)
  File "/usr/local/lib/python3.12/site-packages/pymodbus/transport/transport.py", line 302, in data_received
    self.datagram_received(data, None)
  File "/usr/local/lib/python3.12/site-packages/pymodbus/transport/transport.py", line 336, in datagram_received
    cut = self.callback_data(self.recv_buffer, addr=addr)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pymodbus/client/base.py", line 207, in callback_data
    self.framer.processIncomingPacket(data, self._handle_response, slave=0)
  File "/usr/local/lib/python3.12/site-packages/pymodbus/framer/base.py", line 139, in processIncomingPacket
    self.frameProcessIncomingPacket(single, callback, slave, **kwargs)
  File "/usr/local/lib/python3.12/site-packages/pymodbus/framer/socket_framer.py", line 110, in frameProcessIncomingPacket
    raise ModbusIOException("Unable to decode request")
pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] Unable to decode request

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 20 (6 by maintainers)

Most upvoted comments

Found the problem, we receive:

2024-04-13 18:15:23.782 DEBUG (MainThread) [pymodbus.logging] recv: 0x0 0x10 0x0 0x0 0x0 0x2 0x1 0x84 0x2 old_data: addr=None

0x02 is the length, but it is followed by 3 bytes, which means we miss the last byte.

The standard defines " The length field is a byte count of the following fields, including the Unit Identifier and data fields." which means it should be 3 !!! so the device is NOT following the standard.

To be honest I have however seen this problem in a number of devices, so I will adapt pymodbus to allow for this non standard behavior.

There are currently NO timeline for a fix, but it is likely to to be in 2024.5.

@janiversen I think this is the same problem I was experiencing that I had commented in another thread. For what it’s worth, I had a stable configuration working completely well since at least 2022 and the only change was updating to 2024.4. I wonder what in the code changed that made this non standard output throw an error when it did not before…

Unfortunately the problem still exists here too. Because of all the changes were done in the last versions, I created a new logfile with version 2024.4.4.

Configuration:

- name: "myOrnoModBus"
  type: serial
  method: rtu
  port: /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0
  baudrate: 9600
  stopbits: 1
  bytesize: 8
  parity: E
  timeout: 60
  message_wait_milliseconds: 1000
  sensors:
    - name: "myOrnoVoltageL1"
      address: 0x00E
      unit_of_measurement: V
      precision: 1
      data_type: float32
    - name: "myOrnoVoltageL2"
      address: 0x010
      unit_of_measurement: V
      precision: 1
      data_type: float32
    - name: "myOrnoVoltageL3"
      address: 0x012
      unit_of_measurement: V
      precision: 1
      data_type: float32

    - name: "myOrnoCurrentL1"
      address: 0x016
      unit_of_measurement: A
      precision: 2
      data_type: float32
    - name: "myOrnoCurrentL2"
      address: 0x018
      unit_of_measurement: A
      precision: 2
      data_type: float32
    - name: "myOrnoCurrentL3"
      address: 0x01A
      unit_of_measurement: A
      precision: 2
      data_type: float32

    - name: "myOrnoActivePowerAll"
      address: 0x01C
      unit_of_measurement: kW
      precision: 3
      data_type: float32
    - name: "myOrnoActivePowerL1"
      address: 0x01E
      unit_of_measurement: kW
      precision: 3
      data_type: float32
    - name: "myOrnoActivePowerL2"
      address: 0x020
      unit_of_measurement: kW
      precision: 3
      data_type: float32
    - name: "myOrnoActivePowerL3"
      address: 0x022
      unit_of_measurement: kW
      precision: 3
      data_type: float32

    - name: "myOrnoTotalEnergyAll"
      address: 0x100
      unit_of_measurement: kWh
      precision: 2
      data_type: float32
    - name: "myOrnoTotalEnergyL1"
      address: 0x102
      unit_of_measurement: kWh
      precision: 2
      data_type: float32
    - name: "myOrnoTotalEnergyL2"
      address: 0x104
      unit_of_measurement: kWh
      precision: 2
      data_type: float32
    - name: "myOrnoTotalEnergyL3"
      address: 0x106
      unit_of_measurement: kWh
      precision: 2
      data_type: float32

Logfile:

024-04-24 09:22:49.840 DEBUG (MainThread) [pymodbus.logging] Connecting to /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0.
2024-04-24 09:22:49.840 DEBUG (MainThread) [pymodbus.logging] Connecting comm
2024-04-24 09:22:49.862 INFO (MainThread) [homeassistant.components.modbus.modbus] modbus myOrnoModBus communication open
2024-04-24 09:22:49.882 DEBUG (MainThread) [pymodbus.logging] Connected to comm
2024-04-24 09:22:49.883 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-04-24 09:22:53.697 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-04-24 09:22:53.697 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-04-24 09:22:53.698 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x3 0x0 0xe 0x0 0x2 0xa4 0x19
2024-04-24 09:22:53.756 DEBUG (MainThread) [pymodbus.logging] recv: 0xa 0x3 0x4 0x43 0x68 0x99 0x9a 0x3e 0x90 old_data:  addr=None
2024-04-24 09:22:53.757 DEBUG (MainThread) [pymodbus.logging] Processing: 0xa 0x3 0x4 0x43 0x68 0x99 0x9a 0x3e 0x90
2024-04-24 09:22:53.757 DEBUG (MainThread) [pymodbus.logging] Getting Frame - 0x3 0x4 0x43 0x68 0x99 0x9a
2024-04-24 09:22:53.757 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-04-24 09:22:53.757 DEBUG (MainThread) [pymodbus.logging] Frame advanced, resetting header!!
2024-04-24 09:22:53.757 DEBUG (MainThread) [pymodbus.logging] Getting transaction 10
2024-04-24 09:22:53.758 DEBUG (MainThread) [pymodbus.logging] Unrequested message: ReadHoldingRegistersResponse (2)
2024-04-24 09:23:53.699 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-04-24 09:23:53.699 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-04-24 09:23:53.700 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x3 0x0 0xe 0x0 0x2 0xa4 0x19
2024-04-24 09:23:53.752 DEBUG (MainThread) [pymodbus.logging] recv: 0xa 0x3 0x4 0x43 0x68 0x66 0x66 0x7f 0x21 old_data:  addr=None
2024-04-24 09:23:53.752 DEBUG (MainThread) [pymodbus.logging] Processing: 0xa 0x3 0x4 0x43 0x68 0x66 0x66 0x7f 0x21
2024-04-24 09:23:53.752 DEBUG (MainThread) [pymodbus.logging] Getting Frame - 0x3 0x4 0x43 0x68 0x66 0x66
2024-04-24 09:23:53.752 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-04-24 09:23:53.753 DEBUG (MainThread) [pymodbus.logging] Frame advanced, resetting header!!
2024-04-24 09:23:53.753 DEBUG (MainThread) [pymodbus.logging] Getting transaction 10
2024-04-24 09:23:53.753 DEBUG (MainThread) [pymodbus.logging] Unrequested message: ReadHoldingRegistersResponse (2)
2024-04-24 09:24:53.701 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-04-24 09:24:53.701 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-04-24 09:24:53.701 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x3 0x0 0xe 0x0 0x2 0xa4 0x19
2024-04-24 09:24:53.755 DEBUG (MainThread) [pymodbus.logging] recv: 0xa 0x3 0x4 0x43 0x68 0x33 0x33 0x80 0x4e old_data:  addr=None
2024-04-24 09:24:53.755 DEBUG (MainThread) [pymodbus.logging] Processing: 0xa 0x3 0x4 0x43 0x68 0x33 0x33 0x80 0x4e
2024-04-24 09:24:53.755 DEBUG (MainThread) [pymodbus.logging] Getting Frame - 0x3 0x4 0x43 0x68 0x33 0x33
2024-04-24 09:24:53.755 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-04-24 09:24:53.756 DEBUG (MainThread) [pymodbus.logging] Frame advanced, resetting header!!
2024-04-24 09:24:53.756 DEBUG (MainThread) [pymodbus.logging] Getting transaction 10
2024-04-24 09:24:53.756 DEBUG (MainThread) [pymodbus.logging] Unrequested message: ReadHoldingRegistersResponse (2)
2024-04-24 09:25:53.703 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-04-24 09:25:53.703 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-04-24 09:25:53.703 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x3 0x0 0xe 0x0 0x2 0xa4 0x19
2024-04-24 09:25:53.755 DEBUG (MainThread) [pymodbus.logging] recv: 0xa 0x3 0x4 0x43 0x68 0x33 0x33 0x80 0x4e old_data:  addr=None
2024-04-24 09:25:53.755 DEBUG (MainThread) [pymodbus.logging] Processing: 0xa 0x3 0x4 0x43 0x68 0x33 0x33 0x80 0x4e
2024-04-24 09:25:53.756 DEBUG (MainThread) [pymodbus.logging] Getting Frame - 0x3 0x4 0x43 0x68 0x33 0x33
2024-04-24 09:25:53.756 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-04-24 09:25:53.756 DEBUG (MainThread) [pymodbus.logging] Frame advanced, resetting header!!
2024-04-24 09:25:53.756 DEBUG (MainThread) [pymodbus.logging] Getting transaction 10
2024-04-24 09:25:53.756 DEBUG (MainThread) [pymodbus.logging] Unrequested message: ReadHoldingRegistersResponse (2)
2024-04-24 09:26:53.706 DEBUG (MainThread) [pymodbus.logging] Connection lost comm due to Server not responding
2024-04-24 09:26:53.709 DEBUG (MainThread) [pymodbus.logging] callback_disconnected called: Server not responding
2024-04-24 09:26:53.709 ERROR (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: myOrnoModBus: Error: device: 0 address: 14 -> Modbus Error: [Input/Output] ERROR: No response received after 3 retries
2024-04-24 09:26:53.710 DEBUG (MainThread) [pymodbus.logging] Wait comm 100.0 ms before reconnecting.
2024-04-24 09:26:53.811 DEBUG (MainThread) [pymodbus.logging] Connecting to /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0.
2024-04-24 09:26:53.811 DEBUG (MainThread) [pymodbus.logging] Connecting comm
2024-04-24 09:26:53.818 DEBUG (MainThread) [pymodbus.logging] Connected to comm
2024-04-24 09:26:53.819 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-04-24 09:26:54.711 DEBUG (MainThread) [pymodbus.logging] Adding transaction 2
2024-04-24 09:26:54.711 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-04-24 09:26:54.711 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x3 0x0 0x10 0x0 0x2 0xc4 0x1f
2024-04-24 09:26:54.768 DEBUG (MainThread) [pymodbus.logging] recv: 0xa 0x3 0x4 0x43 0x68 0x19 0x9a 0x5f 0x50 old_data:  addr=None
2024-04-24 09:26:54.768 DEBUG (MainThread) [pymodbus.logging] Processing: 0xa 0x3 0x4 0x43 0x68 0x19 0x9a 0x5f 0x50
2024-04-24 09:26:54.768 DEBUG (MainThread) [pymodbus.logging] Getting Frame - 0x3 0x4 0x43 0x68 0x19 0x9a
2024-04-24 09:26:54.768 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-04-24 09:26:54.768 DEBUG (MainThread) [pymodbus.logging] Frame advanced, resetting header!!
2024-04-24 09:26:54.769 DEBUG (MainThread) [pymodbus.logging] Getting transaction 10
2024-04-24 09:26:54.769 DEBUG (MainThread) [pymodbus.logging] Unrequested message: ReadHoldingRegistersResponse (2)
2024-04-24 09:27:54.713 DEBUG (MainThread) [pymodbus.logging] Adding transaction 2
2024-04-24 09:27:54.713 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-04-24 09:27:54.713 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x3 0x0 0x10 0x0 0x2 0xc4 0x1f
2024-04-24 09:27:54.766 DEBUG (MainThread) [pymodbus.logging] recv: 0xa 0x3 0x4 0x43 0x68 0x0 0x0 0xd4 0xab old_data:  addr=None
2024-04-24 09:27:54.766 DEBUG (MainThread) [pymodbus.logging] Processing: 0xa 0x3 0x4 0x43 0x68 0x0 0x0 0xd4 0xab
2024-04-24 09:27:54.766 DEBUG (MainThread) [pymodbus.logging] Getting Frame - 0x3 0x4 0x43 0x68 0x0 0x0
2024-04-24 09:27:54.766 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-04-24 09:27:54.766 DEBUG (MainThread) [pymodbus.logging] Frame advanced, resetting header!!
2024-04-24 09:27:54.766 DEBUG (MainThread) [pymodbus.logging] Getting transaction 10
2024-04-24 09:27:54.767 DEBUG (MainThread) [pymodbus.logging] Unrequested message: ReadHoldingRegistersResponse (2)