pbix / HA-solark-PV

Home Assistant integration for the SolArk PV Inverter
Apache License 2.0
37 stars 9 forks source link

Unexpected error fetching SolArk data: unpack requires a buffer of 4 bytes #2

Closed poldim closed 3 years ago

poldim commented 3 years ago

I'm getting this error and no values get reported (ever). Based on the error, are you expecting 32bit values while 16bit appears to work fine?

2021-09-22 23:31:15 ERROR (MainThread) [custom_components.solark_modbus.hub] Unexpected error fetching SolArk data: unpack requires a buffer of 4 bytes
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 187, in _async_refresh
    self.data = await self._async_update_data()
  File "/config/custom_components/solark_modbus/hub.py", line 87, in _async_update_data
    realtime_data = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/solark_modbus/hub.py", line 128, in read_modbus_realtime_data
    data["totalinv_e"] = decoder.decode_32bit_uint()/10.0
  File "/usr/local/lib/python3.9/site-packages/pymodbus/payload.py", line 411, in decode_32bit_uint
    handle = self._unpack_words(fstring, handle)
  File "/usr/local/lib/python3.9/site-packages/pymodbus/payload.py", line 361, in _unpack_words
    handle = unpack(up, handle)
struct.error: unpack requires a buffer of 4 bytes

My HA runs via docker. I can go into CLI of the HA container and read values over TCP without any issues image

poldim commented 3 years ago

Upon some more testing, I see that when I add the integration, it fails on the first data pull, succeeds on the second, fails on the third and everyone thereafter.

So if the time is left to default 60s, and you add the integration at t=0s, then at 60s it comes up with an initial set of values, and then as 120s all of those values become unavailable and never come back as values.

Here is a screen cap of this: https://imgur.com/a/tjU4599

pbix commented 3 years ago

Can you run Wireshark and see if the Modbus requests are failing sporadically? I have been using 15 second updates on my machine without any issue but if the request are not successfully completed I think you will see the results you have. In Wireshark we should see the requests going out and the responses coming back. You could also just let your Modpoll test run for awhile and see if its reliable or not.

poldim commented 3 years ago

Can you run Wireshark and see if the Modbus requests are failing sporadically? I have been using 15 second updates on my machine without any issue but if the request are not successfully completed I think you will see the results you have. In Wireshark we should see the requests going out and the responses coming back. You could also just let your Modpoll test run for awhile and see if its reliable or not.

Thanks for the suggestion. I was successfully getting single responses but after your suggestion, I tried it on a 10-sec interval and they failed after the first one. I did some more digging and set ModbusTCP Poll to a 5000 ms timeout. This solved it and then I check it's working fine.

image

image