dewet22 / givenergy-modbus

A python library to access GivEnergy inverters via Modbus TCP on a local network, with no dependency on the GivEnergy Cloud.
Other
19 stars 15 forks source link

Intermittent results when querying the Inverters #19

Open lodge-rj99 opened 1 year ago

lodge-rj99 commented 1 year ago

Description

Describe what you were trying to get done.

Run this simple python script in PyCharm IDE to grab the battery and inverter info. Would just expect a clean exit

import json
import logging
import datetime
import time
from givenergy_modbus.client import GivEnergyClient
from givenergy_modbus.model.inverter import Model
from givenergy_modbus.model.battery import Battery
from givenergy_modbus.model.plant import Plant
from os.path import exists
import os

client = GivEnergyClient(host='192.168.0.70')

p = Plant(number_batteries=1)

client.refresh_plant(p, full_refresh=True)
GEInv = p.inverter
GEBat = p.batteries

Tell us what happened, what went wrong, and what you expected to happen.

Sometimes it works and sometimes it doesn't, it's completely random.

When it works it exits cleanly (and if I add the code to print out an inverter or battery setting, it prints the correct value)

When it fails I see this

Did not receive expected response type: ReadHoldingRegistersResponse != ReadInputRegistersResponse Returned base register (0) does not match that from request (60). Traceback (most recent call last): File "/Users/richard/PycharmProjects/pythonProject3/venv/giv.py", line 17, in GEInv = p.inverter ^^^^^^^^^^ File "/Users/richard/PycharmProjects/pythonProject3/venv/lib/python3.11/site-packages/givenergy_modbus/model/plant.py", line 32, in inverter return Inverter.from_orm(self.inverter_rc) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "pydantic/main.py", line 578, in pydantic.main.BaseModel.from_orm File "pydantic/main.py", line 1056, in pydantic.main.validate_model File "/Users/richard/PycharmProjects/pythonProject3/venv/lib/python3.11/site-packages/givenergy_modbus/model/register_getter.py", line 69, in get return getattr(self._obj, key, default) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/richard/PycharmProjects/pythonProject3/venv/lib/python3.11/site-packages/givenergy_modbus/model/register_cache.py", line 26, in getattr val = self[register]


KeyError: HR:120

The ability to query the inverters and batteries directly in this way is very interesting to us, so I'd love to get this working and stable if I can

Wondering if it could be poor comms quality as our 3 inverters have wifi dongles for connectivity.

britkat1980 commented 1 year ago

The modbus response from the GE invertors is not 100% stable, so it is to be expected that you will occasionally get these failures. The code you write to use this library will need to account for this. When I use this library in GivTCP I see this behaviour too and handle it by holding the cache and retrying.

lodge-rj99 commented 1 year ago

That’s most helpful. Good to know it’s not an issue unique to us. Many thanks for the information. Regards On 23 Jan 2023, at 22:31, britkat1980 @.***> wrote: The modbus response from the GE invertors is not 100% stable, so it is to be expected that you will occasionally get these failures. The code you write to use this library will need to account for this. When I use this library in GivTCP I see this behaviour too and handle it by holding the cache and retrying.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>