binsentsu / home-assistant-solaredge-modbus

Home assistant Component for reading data locally from Solaredge inverter through modbus TCP
286 stars 68 forks source link

Data errors with fast refresh. #37

Open nerfherder opened 3 years ago

nerfherder commented 3 years ago

I have been facing some issues with nonsense data coming out of this integration on and off.

This wasn't an issue with https://github.com/erikarenhill/solaredge-modbus-hass and having a look their it looks like erikarenhill is using import pymodbusTCP whereas bisentsu is using pymodbus the pymodbusTCP implementation lets you keep the connection open with ModbusClient(host, port=port, unit_id=1, auto_open=True) whereas pymodbus appears to require a connect and close each read cycle.

My suspicion is that this open/close cycle can take longer than 5-10 seconds and cause errors if it hasn't run through properly. I would like to trial using pymodbusTCP to see if it makes any difference.

Originally posted by @nerfherder in https://github.com/binsentsu/home-assistant-solaredge-modbus/issues/35#issuecomment-918691933

WillCodeForCats commented 2 years ago

Does HA actually allow for holding the socket open between polling cycles? I don't really know the internals of how HA add ons work.

From my experience with libmodbus in C, ideally the socket would be opened when HA starts up and then never closed unless 1) connection drops and needs to be reopened (network failure, inverter loses power and reboots, whatever) or 2) HA shuts down.

nerfherder commented 2 years ago

The changes in https://github.com/binsentsu/home-assistant-solaredge-modbus/pull/39 introduce pymodbustcp which I believe lets the connection remain open. I set it to auto open so that if the connection drops for some reason it will open again.

https://pymodbustcp.readthedocs.io/en/latest/package/class_ModbusClient.html

WillCodeForCats commented 2 years ago

Wireshark would confirm if it's never intentionally closing the connection if someone has time to try that.

nerfherder commented 2 years ago

I will have a look into monitoring with wireshark as I am already running on that fork.

nerfherder commented 2 years ago

I've just run a wireshark capture on this. From what I can see neither libraries result in the connection closing between reads. They do behave slightly differently though. pymodbustcp image

and modbustcpclient image

The main difference seems to be that the pymodbustcp client triggers a TCP ACK from the solaredge (10.0.0.136 in my case) inverter back to my hassio instance (10.0.0.50) where teh modbustcp client doesn't.

I have very little knowledge in modbus and tcp so someone might be able to interpret what this means better than me.