Hej, poniżej lekko przycięty kod kolegi z 2/3 strony tematu, odczytuje moc z każdej fazy osobno i je sumuje, w json nie widzę aby była łączna wartość przesyłana do użytkownika, o tyle dziwnie że po mqtt można to pobrać jedną wartością. Chyba że ktoś ma sztuczkę na to

Ten kawałek wyciąłem z przykładu który ma dodatkowo obsługę wyświetlacza TFT. Czasami mi się resetowało esp i okazało się że brakuje po prostu pamięci, obciąłem buffor JSON do tej wartości poniżej i resetu ustały jednak niektóre wartości poszły właśnie w 0, więc może zwróć uwagę jak to u ciebie wygląda czy to nie kwestia pamięci. Przykład działa, wyświetla to samo co apka.
Code: Select all
#include <Arduino.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
const char* ssid = "<<<wifi>>>";
const char* password = "<<<pass>>>";
WiFiClientSecure client;
String serverName = "<<<link>>>"; //Direct Link mew-01
unsigned long lastTime = 0;
// Set timer to 5 seconds (5000)
unsigned long timerDelay = 5000;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
client.setInsecure();
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.");
}
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(client, serverPath.c_str());
// Send HTTP GET request
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String json = http.getString();
StaticJsonDocument<600> filter;
filter["phases"][0]["totalForwardActiveEnergy"] = true;
StaticJsonDocument<600> doc;
deserializeJson(doc, json, DeserializationOption::Filter(filter));
double val15 = doc["phases"][0]["totalForwardActiveEnergy"];
double val16 = doc["phases"][1]["totalForwardActiveEnergy"];
double val17 = doc["phases"][2]["totalForwardActiveEnergy"];
Serial.println("Energia Czynna Pobrana:");
Serial.println(val15);
Serial.println(val16);
Serial.println(val17);
Serial.print("Razem:");
Serial.print(val15 + val16 + val17);
Serial.println(" kWh");
Serial.println(" ");
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}
You do not have the required permissions to view the files attached to this post.