MYPV auslesen mit ESP32 und data.jsn

Ich bräuchte mal wieder die geballte Hilfe des Forums.
Kann mir jemand helfen die Werte der jsn im ESP nutzbar zu machen?
Aller 10 Sekunden sollen diese neu abgefragt werden.
Derzeit gibt es dafür nur ein Beispiel für den ESP8266 was auf dem ESP32 andauernd Crasht.
Die data.jsn sieht so aus:

{
"device":"AC ELWA-E",
"power_system":null,
"status":3,
"power":0,
"boostpower":0,
"temp1":427,
"ww1target":850,
"boostactive":0,
"legboostnext":"null",
"date":"29.05.24",
"loctime":"13:55:18",
"unixtime":1716990918,
"uptime":9,
"ctrlstate":"Modbus Read received",
"blockactive":0,
"meter1_id":null,
"meter1_ip":"null",
"meter2_id":null,
"meter2_ip":"null",
"meter3_id":null,
"meter3_ip":"null",
"meter4_id":null,
"meter4_ip":"null",
"meter5_id":null,
"meter5_ip":"null",
"meter6_id":null,
"meter6_ip":"null",
"meter_ss":null,
"meter_ssid":"null",
"surplus":null,
"m0sum":null,
"m0l1":null,
"m0l2":null,
"m0l3":null,
"m0bat":null,
"m1sum":null,
"m1l1":null,
"m1l2":null,
"m1l3":null,
"m1devstate":null,
"m2sum":null,
"m2l1":null,
"m2l2":null,
"m2l3":null,
"m2soc":null,
"m2state":null,
"m2devstate":null,
"m3sum":null,
"m3l1":null,
"m3l2":null,
"m3l3":null,
"m3soc":null,
"m3devstate":null,
"m4sum":null,
"m4l1":null,
"m4l2":null,
"m4l3":null,
"m4devstate":null,
"ecarstate":"null",
"ecarboostctr":null,
"mss2":"null",
"mss3":"null",
"mss4":"null",
"mss5":"null",
"mss6":"null",
"mss7":"null",
"mss8":"null",
"mss9":"null",
"mss10":"null",
"mss11":"null",
"volt_mains":234,
"volt_aux":4,
"freq":49998,
"tempchip":327,
"fan_speed":0,
"ps_state":0,
"ctrl_errors":0,
"warnings":0,
"fwversionlatest":"null",
"coversionlatest":"null",
"psversionlatest":"null",
"upd_state":0,
"ps_upd_state":0,
"co_upd_state":0,
"cur_eth_mode":0,
"wifi_signal":0,
"wifi_list":[{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0}],
"cur_ip":"192.168.0.102",
"cur_sn":"255.255.255.0",
"cur_gw":"192.168.0.1",
"cur_dns":"192.168.0.1",
"cloudstate":0,
"debug_ip":"0.0.0.0"
}

Und hier das Beispiel für den ESP8266 aber wie Beschrieben nicht lauffähig und Fragt die Schnittstelle viel zu oft ab.

/*
  Rui Santos
  Complete project details at Complete project details at https://RandomNerdTutorials.com/esp32-http-get-post-arduino/

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#include <WiFi.h>
#include <HTTPClient.h>
#include <Arduino_JSON.h>

const char* ssid = "";
const char* password = "";

//Your Domain name with URL path or IP address with path
const char* serverName = "http://192.168.0.102/data.jsn";

// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
unsigned long timerDelay = 10000;

String sensorReadings;
float sensorReadingsArr[80];

void setup() {
  Serial.begin(115200);

  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
 
  Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
  delay(2000);
}

void loop() {
  //Send an HTTP POST request every 10 minutes
  if ((millis() - lastTime) > timerDelay) {
    //Check WiFi connection status
    if(WiFi.status()== WL_CONNECTED){
              
      
    else {
      Serial.println("WiFi Disconnected");
    }
    lastTime = millis();
  }
}

String httpGETRequest(const char* serverName) {
  WiFiClient client;
  HTTPClient http;
    
  // Your Domain name with URL path or IP address with path
  http.begin(client, serverName);
  
  // Send HTTP POST request
  int httpResponseCode = http.GET();
  
  String payload = "{}"; 
  
  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    payload = http.getString();
  }
  else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
  }
  // Free resources
  http.end();

  return payload;
}

Ich hoffe sehr das Jemand die JSON auswerten kann.
Danke Gruß Robert

Wie gut bist Du in Russisch?

(Die gibt es schon länger und lief hier nur über den Ticker, dass die aktuallisiert wurde)

Deepl kann auch Russisch übersetzen.

Gruß Tommy

1 Like

Ist ohne Anmeldung auf 5K Zeichen begrenzt, was zum Problem werden könnte.

Dann übersetzt man halt mehrere Teile einzeln oder meldet sich an.

Gruß Tommy

Habe mir den Code angesehen. Sieht so aus, als würde er die json erst im code zusammen bauen, um zu demmonstriern wie es Arbeitet. Aber wie bekomme ich jetzt meine intranet Seite da rein gebastelt?

Genau so, wie in Deinem Sketch aus #1 (Payload).

Gruß Tommy

Hallo habe es mit Payload probiert, Leider komme ich nicht zum Gewünschten Ergebnis hat noch jemand einen Tipp? mehr als 14 Ergebnisse bekomme ich auch nicht zurück, ob wohl es deutlich mehr sein müssten. Und die Trennung der Zeichen und Werte passt auch nicht.

/*
  Rui Santos
  Complete project details at Complete project details at https://RandomNerdTutorials.com/esp32-http-get-post-arduino/

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

#include <WiFi.h>
#include <HTTPClient.h>
#include <Arduino.h>
#include <GSON.h>

const char* ssid = "";
const char* password = "";

//Your Domain name with URL path or IP address with path
const char* serverName = "http://192.168.0.102/data.jsn";

// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
unsigned long timerDelay = 10000;

String sensorReadings;
float sensorReadingsArr[80];

void setup() {
  Serial.begin(115200);

  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
 
  Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
  delay(2000);
}

void loop() {
  //Send an HTTP POST request every 10 minutes
  if ((millis() - lastTime) > timerDelay) {
    //Check WiFi connection status
    if(WiFi.status()== WL_CONNECTED){
      HTTPClient http;

      String serverPath = serverName;
      
      // Your Domain name with URL path or IP address with path
      http.begin(serverPath.c_str());
      
      // If you need Node-RED/server authentication, insert user and password below
      //http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD");
      
      // Send HTTP GET request
      int httpResponseCode = http.GET();
      
      if (httpResponseCode>0) {
        String payload = http.getString();
        //Serial.println(payload);
           gson::string gs;
           //gs.beginObj();
           //gs.addString(payload);
           //gs.endObj();
           //gs.end();

           //Serial.println("==== PACKET ====");
           //Serial.println(gs);
          gson::Parser p(10);
          p.parse(payload);

              Serial.println("==== CHUNKS ====");
    for (int i = 0; i < p.length(); i++) {
        Serial.print(i);
        Serial.print(". [");
        Serial.print(p.readType(i));
        Serial.print("] ");
        Serial.print(p.key(i));
        Serial.print(":");
        Serial.print(p.value(i));
        Serial.print(" {");
        Serial.print(p.parent(i));
        Serial.println("}");
    }
      }
      else {
        Serial.print("Error code: ");
        Serial.println(httpResponseCode);
      }
      // Free resources
      http.end();
    }
    else {
      Serial.println("WiFi Disconnected");
    }
    lastTime = millis();
  }
}

Ergebnis:

22:50:16.029 -> ==== CHUNKS ====
22:50:16.029 -> 0. [Object] : {511}
...
22:44:43.336 -> 6. [Int] fsetup:0 {0}
22:44:43.336 -> 7. [Int] p1_s:240 {0}
22:44:43.336 -> 8. [String] p1_v:0000901 {0}
22:44:43.336 -> 9. [Int] p2_s:255 {0}
22:44:43.336 -> 10. [String] p2_v:null {0}
22:44:43.336 -> 11. [Int] p_co_s:255 {0}
22:44:43.336 -> 12. [String] p_co_v:null {0}
22:44:43.377 -> 13. [Int] p_ps_s:255 {0}
22:44:43.377 -> 14. [String] p_ps_v:null {0}

Dann gib uns doch mal den Payload, den Du zurück bekommst.

Gruß Tommy

Sehr gern.

        String payload = http.getString();
        Serial.println(payload);

Das ist das Eergebnis

{
"device":"AC ELWA-E",
"fwversion":"00207.00",
"fwversion2_comp":"e0000000",
"psversion":"ep105",
"coversion":"ec103",
"fsetup":0,
"p1_s":240,
"p1_v":"0000000",
"p2_s":255,
"p2_v":"null",
"p_co_s":255,
"p_co_v":"null",
"p_ps_s":255,
"p_ps_v":"null",
"power_system":null,
"status":3,
"power":0,
"boostpower":0,
"temp1":344,
"ww1target":850,
"boostactive":0,
"legboostnext":"null",
"date":"30.05.24",
"loctime":"07:26:04",
"unixtime":1717053964,
"uptime":27,
"ctrlstate":"Modbus Read received",
"blockactive":0,
"meter1_id":null,
"meter1_ip":"null",
"meter2_id":null,
"meter2_ip":"null",
"meter3_id":null,
"meter3_ip":"null",
"meter4_id":null,
"meter4_ip":"null",
"meter5_id":null,
"meter5_ip":"null",
"meter6_id":null,
"meter6_ip":"null",
"meter_ss":null,
"meter_ssid":"null",
"surplus":null,
"m0sum":null,
"m0l1":null,
"m0l2":null,
"m0l3":null,
"m0bat":null,
"m1sum":null,
"m1l1":null,
"m1l2":null,
"m1l3":null,
"m1devstate":null,
"m2sum":null,
"m2l1":null,
"m2l2":null,
"m2l3":null,
"m2soc":null,
"m2state":null,
"m2devstate":null,
"m3sum":null,
"m3l1":null,
"m3l2":null,
"m3l3":null,
"m3soc":null,
"m3devstate":null,
"m4sum":null,
"m4l1":null,
"m4l2":null,
"m4l3":null,
"m4devstate":null,
"ecarstate":"null",
"ecarboostctr":null,
"mss2":"null",
"mss3":"null",
"mss4":"null",
"mss5":"null",
"mss6":"null",
"mss7":"null",
"mss8":"null",
"mss9":"null",
"mss10":"null",
"mss11":"null",
"volt_mains":233,
"volt_aux":5,
"freq":49979,
"tempchip":323,
"fan_speed":0,
"ps_state":0,
"ctrl_errors":0,
"warnings":0,
"fwversionlatest":"null",
"coversionlatest":"null",
"psversionlatest":"null",
"upd_state":0,
"ps_upd_state":0,
"co_upd_state":0,
"cur_eth_mode":0,
"wifi_signal":0,
"wifi_list":[{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0},{"ssid":"","signal":0}],
"cur_ip":"192.168.0.102",
"cur_sn":"255.255.255.0",
"cur_gw":"192.168.0.1",
"cur_dns":"192.168.0.1",
"cloudstate":0,
"debug_ip":"0.0.0.0"
}

Das sieht doch schon mal gut aus. Gib das mal in einen Beispielsketch und löse das nach dieser Dokumentation auf.
Da sind viele Beispiele drin.

Gruß Tommy

Ich komme mal wieder nicht weiter :confused: bekomme den "payload" nicht entschlüsselt.

void setup() {
  Serial.begin(115200);

  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
 
  Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
  delay(2000);
}

void loop() {
  //Send an HTTP POST request every 10 minutes
  if ((millis() - lastTime) > timerDelay) {
    //Check WiFi connection status
    if(WiFi.status()== WL_CONNECTED){
      HTTPClient http;

      String serverPath = serverName;
      
      // Your Domain name with URL path or IP address with path
      http.begin(serverPath.c_str());
      
      // If you need Node-RED/server authentication, insert user and password below
      //http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD");
      
      // Send HTTP GET request
      int httpResponseCode = http.GET();
      
      if (httpResponseCode>0) {
        String payload = http.getString();
        Serial.println(payload);
  // Deserialize the JSON document
  StaticJsonDocument<200> doc;
  DeserializationError error = deserializeJson(json, payload);

  // Test if parsing succeeds.
  if (error) {
    Serial.print(F("deserializeJson() failed: "));
    Serial.println(error.f_str());
    return;
  }

  // Fetch values.
  //
  // Most of the time, you can rely on the implicit casts.
  // In other case, you can do doc["time"].as<long>();
  const char* sensor = doc["p1_s"];
  // Print values.
  Serial.println(sensor);
      }
      // Free resources
      http.end();
    }
    else {
      Serial.println("WiFi Disconnected");
    }
    lastTime = millis();
  }
}

raus kommt erst der komplette Payload und dann eine leere Zeile

Da wird dein json doc decodiert.
In deinem Fall ist der Wert allerdings eine Zahl ( 240 ) anstelle eines Textes.
Ob's daran liegt?

Was liefert denn
Serial.println( doc["psversion"] ); // sollte "ep105" ausgeben

1 Like

Stimmt, also sollte

int sensor=doc["p1_s"];

die 240 ergeben.
Ich halte aber die <200> etwas kurz für den Payload. Das müsste auch in error stehen.

Gruß Tommy

Edit: Lokal mit RAW-String als Eingabe brauche ich <3500>, damit kein Error "NoMemory" auftritt.

2 Likes

Bei diesem Print Befehl bekomme ich eine Satte Fehler Meldung.

  112 |   size_t println(struct tm *timeinfo, const char *format = NULL);
      |          ^~~~~~~

exit status 1

Compilation error: call of overloaded 'println(ArduinoJson::V704PB2::detail::enable_if<true, ArduinoJson::V704PB2::detail::MemberProxy<ArduinoJson::V704PB2::JsonDocument&, const char*> >::type)' is ambiguous

Ein Traum beide Ratschläge angepasst und bekomme das Erwarteten 240 Zurück :slight_smile: DAAAANNKKEEEE

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.