Laderegler

Für die Epever Laderegler gibt es bereits hier eine Dokumentation auf welche Ports geschrieben und gelesen werden kann. Diese ist allerdings ohne etwas Ahnung von dem Modbus Protokoll zu haben etwas unverständlich. Hier also nun das Code Schnipsel zum auslesen.

import ctypes
from datetime import datetime
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.exceptions import ModbusIOException
from pymodbus.mei_message import ReadDeviceInformationRequest
from pymodbus.constants import DeviceInformation
import time
import sys
import os
import traceback

CHARGE_CONTROLLER_UNIT = 1
POLL_TIME = 10

def getClient():
    return ModbusClient(
        method = "rtu",
        port = "/dev/ttyUSB0",
        baudrate = 115200,
        timeout = 1
    )
    
def current_milli_time():
    return round(time.time() * 1000)

timeToSleep=POLL_TIME

ADRESSES_TO_READ = 19

while True:
    print("\n\nCheck for data")

    stamp = datetime.now()

    client = getClient()

    if client.connect():
        print("connect")
        result = client.read_input_registers(0x3100, ADRESSES_TO_READ, unit=CHARGE_CONTROLLER_UNIT)
        if isinstance(result, Exception):
            print("Got exception reading 0x3100 - 0x3118")
        else:
            if result.function_code < 0x80:

                data = [{'timestamp':current_milli_time(),
                        'chargeVolt':result.registers[0]/100,
                        'chargeAmpere':result.registers[1]/100,
                        'batteryVoltage':result.registers[4]/100,
                        'batteryAmpere':result.registers[5]/100 - result.registers[13]/100,
                        'batteryTemperature':result.registers[16]/100,
                        'consumptionVoltage':result.registers[12]/100,
                        'consumptionAmpere':result.registers[13]/100,
                        'deviceTemperature':result.registers[17]/100,
                        'chargerTemperature':result.registers[18]/100
                }]
                
                print(data)
            else:
                print("Error on reading result)

    client.close()
    
    dif = datetime.now() - stamp
    timeToSleep = POLL_TIME - dif.total_seconds()
    if(timeToSleep > 0):
        print("Sleep for: ", timeToSleep, " Seconds")
        time.sleep(timeToSleep)


Getestet mit folgenden Geräten: LS1024B, XTRA4415N, 4210AN