0

I'm trying to query a smartlogger using modbus TCP. I used pyModbusTCP

from pyModbusTCP.client import ModbusClient

c = ModbusClient()

c.host = 'x.x.x.x' #my smartlogger IP
c.port = 502
c.debug = True

regs = c.read_holding_registers(0, 10)

if regs:
    print(regs)
else:
    print("read error regs")

and got the error: modbus exception (code 3 "illegal data value")

Got any suggestion for a potential error or for another software to communicate with the smartlogger?

Tried using different int values for c.read_holding_registers(0, 10), but still got the same error: modbus exception (code 3 "illegal data value")

  • try this open source [modpoll](https://github.com/gavinying/modpoll) tool and use MQTT for further integration. – balun Jul 16 '23 at 08:41

1 Answers1

0

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.