I'm trying the same and your code put me on the right track!
I used ChatGPT to give me some more info and it suggested to use 'pymodbus' instead.
To find the registers, see https://support.huawei.com/enterprise/en/doc/EDOC1100050690
(check out page 14 -> SN 30 -> that is where the register info is I'm talking about).
The code I used to check out the Daily Yield as test:
from pymodbus.client import ModbusTcpClient
# Replace 'x.x.x.x' with your Smartlogger IP address
client = ModbusTcpClient('x.x.x.x')
# Specify the Modbus unit ID (default is 0)
unit_id = 0
# Specify the starting register address and the number of registers to read
starting_register = 40562
num_registers = 2
try:
# Connect to the Modbus TCP server
if client.connect():
# Read holding registers from the Smartlogger
response = client.read_holding_registers(starting_register, num_registers, unit=unit_id)
if not response.isError():
# Extract the data from the response
data = response.registers
print(data)
else:
print("Modbus error response:", response)
else:
print("Could not connect to Modbus TCP server.")
except Exception as e:
print("Error:", e)
finally:
# Close the Modbus TCP connection
client.close()
This gave me this result:
[0, 19560]
The Web UI of the Smartlogger shows 1.96MWh, and the docu says this value has a gain of 10 and is in kWh. So divide the result by 10 and you have your kWh.