Skip to content

Try to use with mqtt #13

Description

@heiko1988

Good day,

I'm trying to integrate a mqtt client that I can use the data in the smart home. in my case it would be iobroker

I've tried a bit to integrate it. Unfortunately, I lack expertise

I hope one of you can help me

The demo with the serial output runs great :)

My hardware:

Esp32 Wroom

The code where not working:

#include "NETSGPClient.h"
#include "EspMQTTClient.h"

EspMQTTClient client(
  "wifi_test",
  "password_test",
  "192.168.0.119",  // MQTT Broker server ip
  "iobroker",   // Can be omitted if not needed
  "Passwort",   // Can be omitted if not needed
  "SG600MD"      // Client name that uniquely identify your device
);

constexpr const uint8_t PROG_PIN = 4; /// Programming enable pin of RF module
constexpr const uint8_t RX_PIN = 17; /// RX pin of RF module
constexpr const uint8_t TX_PIN = 16; /// TX pin of RF module
constexpr const uint32_t inverterID = 0x38004044; /// Identifier of your inverter (see label on inverter)




NETSGPClient client(Serial2, PROG_PIN); /// NETSGPClient instance

void setup()
{
    Serial.begin(115200);
    Serial2.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN);
//    pinMode(LED_BUILTIN, OUTPUT);
    delay(1000);
    Serial.println("Welcome to Micro Inverter Interface by ATCnetz.de and enwi.one");

    // Make sure the RF module is set to the correct settings
    if (!client.setDefaultRFSettings())
    {
        Serial.println("Could not set RF module to default settings");
    }
}



void onConnectionEstablished() {

  client.subscribe("mytopic/test", [] (const String &payload)  {
    Serial.println(payload);
  });

  client.publish("mytopic/test", "This is a message");
}


uint32_t lastSendMillis = 0;
void loop()
{
    const uint32_t currentMillis = millis();
    if (currentMillis - lastSendMillis > 2000)
    {
        lastSendMillis = currentMillis;

//        digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
        Serial.println("");
        Serial.println("Sending request now");

        const NETSGPClient::InverterStatus status = client.getStatus(inverterID);
        if (status.valid)
        {
            Serial.println("*********************************************");
            Serial.println("Received Inverter Status");
            Serial.print("Device: ");
            Serial.println(status.deviceID, HEX);
            Serial.println("Status: " + String(status.state));
            Serial.println("DC_Voltage: " + String(status.dcVoltage) + "V");
            Serial.println("DC_Current: " + String(status.dcCurrent) + "A");
            Serial.println("DC_Power: " + String(status.dcPower) + "W");
            Serial.println("AC_Voltage: " + String(status.acVoltage) + "V");
            Serial.println("AC_Current: " + String(status.acCurrent) + "A");
            Serial.println("AC_Power: " + String(status.acPower) + "W");
            Serial.println("Power gen total: " + String(status.totalGeneratedPower));
            Serial.println("Temperature: " + String(status.temperature));
        }
    }
}

the error description from the compiler:

PollDemo:21:21: error: conflicting declaration 'NETSGPClient client'
 NETSGPClient client(Serial2, PROG_PIN); /// NETSGPClient instance
                     ^
C:\Users\chaos\Desktop\NETSGPClient-1.1.0 (1)\NETSGPClient-1.1.0\examples\PollDemo\PollDemo.ino:4:15: note: previous declaration as 'EspMQTTClient client'
 EspMQTTClient client(
               ^
C:\Users\chaos\Desktop\NETSGPClient-1.1.0 (1)\NETSGPClient-1.1.0\examples\PollDemo\PollDemo.ino: In function 'void setup()':
PollDemo:32:17: error: 'class EspMQTTClient' has no member named 'setDefaultRFSettings'
     if (!client.setDefaultRFSettings())
                 ^
C:\Users\chaos\Desktop\NETSGPClient-1.1.0 (1)\NETSGPClient-1.1.0\examples\PollDemo\PollDemo.ino: In function 'void loop()':
PollDemo:62:60: error: 'class EspMQTTClient' has no member named 'getStatus'
         const NETSGPClient::InverterStatus status = client.getStatus(inverterID);
                                                            ^
Mehrere Bibliotheken wurden für "WiFi.h" gefunden
 Benutzt: C:\Users\chaos\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\WiFi
 Nicht benutzt: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
conflicting declaration 'NETSGPClient client'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions