Skip to content

Commit

Permalink
correction shelly Tri
Browse files Browse the repository at this point in the history
  • Loading branch information
xlyric committed Nov 11, 2024
1 parent dd0a1bd commit 80aa8d6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 41 additions & 7 deletions src/functions/shelly.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<String>());
Serial.println(baseurl);

if ( powerValue.isNull() || doc["total_power"].as<String>() == "null") {
config.Shelly_mode = 1;
return shelly_watt;
}

/// protection de la donnée
if (powerValue.is<int>() || powerValue.is<float>()) {
Expand Down

0 comments on commit 80aa8d6

Please sign in to comment.