Micro Inverter

Micro Inverter

July 14, 2023

What it does. #

The setup consits of 2 300 Watt solarpanels and a sg600md micro-inverter that can be be plugged directly into a wall socket. The micro-inverter transmits it’s serial console data over 2.4ghz and thanks to the NETSGPClient the output can be received by a lc12s module connected to an ESP32. From there an MQTT client sends the received data to mosquitto over wifi and depending on the topic the MQTT message will be processed by Node-Red. The next step is saving the power statistics in the mqtt message to a database for visual representation in grafana.

Prototype Images #

Front Side Top
thumb-1 thumb-2 thumb-3
Solar-Panel Battery Final-Stage
thumb-4 thumb-5 thumb-6

Early draft of the Uart-Wifi-Mqtt code #

#include "Arduino.h"
#include <WiFi.h>
#include "ESP32MQTTClient.h"
#include <NETSGPClient.h>
const char *ssid = "ssid";
const char *pass = "pass";
char *server = "mqtt://username:password@server:port";
char *publishTopic = "test/test";
constexpr const uint8_t PROG_PIN = 4; /// Programming enable pin of RF module
constexpr const uint8_t RX_PIN = 16; /// RX pin of ESP32 connect to TX of RF module
constexpr const uint8_t TX_PIN = 17; /// TX pin of ESP32 connect to RX of RF module
constexpr const uint32_t inverterID = 0x00000000; /// Identifier of your inverter (0xInverter_ID)
#define debugSerial Serial
#define clientSerial Serial2

ESP32MQTTClient mqttClient; // all params are set later
NETSGPClient netsgpClient(clientSerial, PROG_PIN);
void setup()
    clientSerial.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN);
    debugSerial.println("Welcome to Micro Inverter Interface by ATCnetz.de and enwi.one");

    // Make sure the RF module is set to the correct settings
    if (!netsgpClient.setDefaultRFSettings())
        debugSerial.println("Could not set RF module to default settings");
    // Serial.begin(115200);
    log_i("setup, ESP.getSdkVersion(): ");
    log_i("%s", ESP.getSdkVersion());


    mqttClient.enableLastWillMessage("lwt", "I am going offline");
    WiFi.begin(ssid, pass);

int pubCount = 0;

void loop()
        digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
        debugSerial.println("Sending request now");

        const NETSGPClient::InverterStatus status = netsgpClient.getStatus(inverterID);
        if (status.valid)
            debugSerial.println("Received Inverter Status");
            debugSerial.print("Device: ");
            debugSerial.println(status.deviceID, HEX);
            debugSerial.println("Status: " + String(status.state));
            debugSerial.println("DC_Voltage: " + String(status.dcVoltage) + "V");
            debugSerial.println("DC_Current: " + String(status.dcCurrent) + "A");
            debugSerial.println("DC_Power: " + String(status.dcPower) + "W");
            debugSerial.println("AC_Voltage: " + String(status.acVoltage) + "V");
            debugSerial.println("AC_Current: " + String(status.acCurrent) + "A");
            debugSerial.println("AC_Power: " + String(status.acPower) + "W");
            debugSerial.println("Power gen total: " + String(status.totalGeneratedPower));
            debugSerial.println("Temperature: " + String(status.temperature));
            String msg = "Power: " + String(status.dcPower) + "W";
            mqttClient.publish(publishTopic, msg, 0, false); // This sends the current dcPower in watt 

void onConnectionEstablishedCallback(esp_mqtt_client_handle_t)

esp_err_t handleMQTT(esp_mqtt_event_handle_t event)
    return ESP_OK;