splitscreen more_vert
SOLAR_DB chevron_right Collecting Solar Data.md

Solar DB

Overview

This project is the backbone of all the apps which use data from the solar collectors.

Tech Stack

  • Language: Python

  • Hardware: Raspberry Pi

  • Technologies: modbus

  • Database: MySQL

  • Tools: Docker, Git, VS Code

Details

Here we are using pymodbus to read the registers of the Kostal inverters. This data is then stored inside a local MySQL database.

def readfloat(client, myadr_dec, unitid):
    r1 = client.read_holding_registers(myadr_dec, 2, slave=unitid)
    FloatRegister = BinaryPayloadDecoder.fromRegisters(r1.registers, byteorder=Endian.BIG, wordorder=Endian.LITTLE)
    result_FloatRegister = round(FloatRegister.decode_32bit_float(), 2)
    return (result_FloatRegister)
def read(inverter_ip, inverter_port):
    try:
        # connection Kostal
        client = ModbusTcpClient(inverter_ip, port=inverter_port)
        client.connect()
        result = {}
        # read the registers - save it in a dict
        consumptionbat = readfloat(client, 106, 71)
        result["consumptionbat"] = consumptionbat

        consumptiongrid = readfloat(client, 108, 71)
        result["consumptiongrid"] = consumptiongrid

        consumptionpv = readfloat(client, 116, 71)
        result["consumptionpv"] = consumptionpv

        consumption_total = consumptionbat + consumptiongrid + consumptionpv
        result["consumption_total"] = consumption_total

        inverter = readfloat(client, 172, 71)
        result["inverter"] = inverter

        batteryamp = readfloat(client, 200, 71)
        result["batteryamp"] = batteryamp

        batteryvolt = readfloat(client, 216, 71)
        result["batteryvolt"] = batteryvolt

        powerToBattery = -round(batteryamp * batteryvolt, 2)
        result["powerToBattery"] = powerToBattery

        if batteryamp > 0.1:
            result["batteryflag"] = 0
        elif batteryamp < -0.1:
            result["batteryflag"] = 1
        else:
            result["batteryflag"] = 0.5

        batterypercent = readfloat(client, 210, 71)
        result["batterypercent"] = batterypercent

        # Kostal generation (by tracker/battery)
        dc1 = readfloat(client, 260, 71)
        result["dc1"] = dc1

        dc2 = readfloat(client, 270, 71)
        result["dc2"] = dc2

        dc3 = readfloat(client, 280, 71)
        result["dc3"] = dc3

        generation = round(dc1 + dc2 + dc3, 2)
        result["generation"] = generation
        # this is not exact
        powerToGrid = -readfloat(client, 252, 71)
        result["powerToGrid"] = powerToGrid

        # wrong for negative consumption
        # if we send power to battery or grid
        surplus = round(powerToBattery + powerToGrid, 2)
        result["surplus"] = surplus

        dailyyield = round(readfloat(client, 322, 71) / 1000, 2)    
        result["dailyyield"] = dailyyield

        return result

    except Exception as ex:
        print("ERROR Kostal: ", ex)
    finally:
        client.close()

The storage of the data is crucial for future applications and ML models.

Key Features

  • Feature One: Description of the feature.

  • Feature Two: Description of the feature.

  • Feature Three: Description of the feature.

Challenges & Learnings

  • Challenge 1: What was difficult? How did you solve it?

  • Learning 1: What new concept or tool did you learn?

Future Improvements

  • [ ] Add user authentication

  • [ ] Improve UI/UX

  • [ ] Add unit tests

Links

Screenshots

Screenshot description

## Comments

Please login to leave a comment.

No comments yet. Initiate payload.