From 80aa8d689fef8af6eeb958a7e535df1d0ff2ea2a Mon Sep 17 00:00:00 2001 From: xlyric Date: Mon, 11 Nov 2024 20:32:21 +0100 Subject: [PATCH] correction shelly Tri --- src/config/config.h | 2 +- src/functions/shelly.h | 48 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/config/config.h b/src/config/config.h index 68fe895..fabb796 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -158,7 +158,7 @@ bool discovery_temp = false; // #define ARDUINO_RUNNING_CORE 1 #endif -#define RELEASE "Version 20240708" +#define RELEASE "Version 20241111" constexpr const int FS_RELEASE= 20240704 ; #ifdef LIGHT_FIRMWARE diff --git a/src/functions/shelly.h b/src/functions/shelly.h index f4d072a..61177c1 100644 --- a/src/functions/shelly.h +++ b/src/functions/shelly.h @@ -17,18 +17,41 @@ int shelly_get_data(String url) { /// récupération en wget des informations du shelly HTTPClient shelly_http; int shelly_watt = 0; + int port = 80; if (WiFi.status() == WL_CONNECTED) { // si connecté on wget String baseurl = "/emeter/0" ; /// mode triphasé - if ( config.Shelly_tri ) { - baseurl = "/rpc/EM.GetStatus?id=0" ; + if ( config.Shelly_tri && config.Shelly_mode == 0) { + baseurl = "/rpc/EM.GetStatus?id=0" ; // pour le 3EM } - shelly_http.begin(String(url),80,baseurl); - - int httpResponseCode = shelly_http.GET(); + if ( config.Shelly_tri && config.Shelly_mode == 1) { + baseurl = "/status" ; // pour le 3EM + } + + // détection de si l'url à un :port + // if (url.indexOf(":") > 0) { + // port = url.substring(url.indexOf(":")+1).toInt(); + // url = url.substring(0,url.indexOf(":")); + // } + + // Serial.println("info shelly"); + // Serial.println(url); + // Serial.println(port); +//Serial.println(baseurl); + + shelly_http.begin(String(url),port,baseurl); + int httpResponseCode = shelly_http.GET(); + + if (httpResponseCode==404) { + config.Shelly_mode = 1; + return shelly_watt; + } + + //Serial.println(httpResponseCode); + String shelly_state = "0"; shelly_state = shelly_http.getString(); shelly_http.end(); @@ -48,11 +71,22 @@ HTTPClient shelly_http; auto powerValue = doc["power"]; /// mode triphasé - if (config.Shelly_tri ) { + if (config.Shelly_tri && config.Shelly_mode == 0) { powerValue = doc["total_act_power"]; } - + if (config.Shelly_tri && config.Shelly_mode == 1) { + powerValue = doc["total_power"]; + } + // affichage dans le sérial de doc["total_power"] en tant que string ; + Serial.println("Shelly Watt : "); + Serial.println(doc["total_power"].as()); + Serial.println(baseurl); + + if ( powerValue.isNull() || doc["total_power"].as() == "null") { + config.Shelly_mode = 1; + return shelly_watt; + } /// protection de la donnée if (powerValue.is() || powerValue.is()) {