diff --git a/src/app.cpp b/src/app.cpp index f77a45ff..d8ab985b 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -450,6 +450,10 @@ void app::tickSend(void) { } #endif } + + #if defined(ESP32) + if(mConfig->nrf.enabled || mConfig->cmt.enabled) zeroexport(); + #endif } } else { if (mConfig->serial.debug) @@ -458,10 +462,6 @@ void app::tickSend(void) { yield(); updateLed(); - - #if defined(ESP32) - zeroexport(); - #endif } //----------------------------------------------------------------------------- @@ -593,22 +593,29 @@ void app::updateLed(void) { //----------------------------------------------------------------------------- #if defined(ESP32) void app::zeroexport() { - if (!mConfig->plugin.zexport.enabled) return; - if (!mConfig->plugin.zexport.rdytoSend) return; + if (!mConfig->plugin.zexport.enabled && + !mConfig->plugin.zexport.rdytoSend) return; // check if plugin is enabled && indicate to send new value + + Inverter<> *iv = mSys.getInverterByPos(mConfig->plugin.zexport.Iv); DynamicJsonDocument doc(512); JsonObject object = doc.to(); + double nValue = round(mzExport.getPowertoSetnewValue()); + double twoPerVal = nValue <= (iv->getMaxPower() / 100 * 2 ); + if(mConfig->plugin.zexport.two_percent && (nValue <= twoPerVal)) { + object["val"] = twoPerVal; + } else { + object["val"] = nValue; + } - object["path"] = "ctrl"; object["id"] = mConfig->plugin.zexport.Iv; - object["val"] = round(mzExport.getPowertoSetnewValue()); + object["path"] = "ctrl"; object["cmd"] = "limit_nonpersistent_absolute"; String data; serializeJsonPretty(object, data); DPRINTLN(DBG_INFO, data); - mApi.ctrlRequest(object); } #endif \ No newline at end of file diff --git a/src/config/settings.h b/src/config/settings.h index 0fc7cd3a..f75c3689 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -147,6 +147,8 @@ typedef struct { float power_avg; uint8_t count_avg; double total_power; + + bool two_percent; // ask if not go lower then 2% } cfgzeroExport_t; #endif @@ -460,6 +462,7 @@ class settings { mCfg.plugin.zexport.power_avg = 10; mCfg.plugin.zexport.device = 0; mCfg.plugin.zexport.Iv = 0; + mCfg.plugin.zexport.two_percent = true; #endif mCfg.inst.rstYieldMidNight = false; @@ -662,14 +665,20 @@ class settings { obj[F("power_avg")] = mCfg.plugin.zexport.power_avg; obj[F("count_avg")] = mCfg.plugin.zexport.count_avg; obj[F("total_power")] = mCfg.plugin.zexport.total_power; + obj[F("two_percent")] = mCfg.plugin.zexport.two_percent; } else { getVal(obj, F("en_zeroexport"), &mCfg.plugin.zexport.enabled); + getVal(obj, F("two_percent"), &mCfg.plugin.zexport.two_percent); + getChar(obj, F("monitor_ipAddr"), mCfg.plugin.zexport.monitor_ip, ZEXPORT_ADDR_LEN); + getVal(obj, F("Iv"), &mCfg.plugin.zexport.Iv); - getVal(obj, F("power_avg"), &mCfg.plugin.zexport.power_avg); getVal(obj, F("count_avg"), &mCfg.plugin.zexport.count_avg); + + getVal(obj, F("power_avg"), &mCfg.plugin.zexport.power_avg); + getVal(obj, F("total_power"), &mCfg.plugin.zexport.total_power); } } diff --git a/src/web/RestApi.h b/src/web/RestApi.h index fb0d22f1..18ba74e2 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -484,6 +484,7 @@ class RestApi { #if defined(ESP32) void getzeroExport(JsonObject obj) { obj[F("en_zeroexport")] = (bool) mConfig->plugin.zexport.enabled; + obj[F("two_percent")] = (bool) mConfig->plugin.zexport.two_percent; obj[F("monitor_ipAddr")] = String(mConfig->plugin.zexport.monitor_ip); obj[F("count_avg")] = (uint8_t)mConfig->plugin.zexport.count_avg; obj[F("Iv")] = (uint8_t)mConfig->plugin.zexport.Iv; diff --git a/src/web/html/setup.html b/src/web/html/setup.html index d8ed35a7..ea669807 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -332,6 +332,12 @@
Prio Inverter
+ +
+
2% protection:
+
+
+
Refresh rate (sec.)
Power tolerances (Watt)
@@ -959,6 +965,8 @@ } document.getElementsByName("en_zeroexport")[0].checked = obj["en_zeroexport"]; + document.getElementsByName("two_percent")[0].checked = obj["two_percent"]; + getAjax("/api/inverter/list", parseZeroIv); for(var i of [["monitor_ipAddr", "monitor_ipAddr"], ["power_avg", "power_avg"], ["count_avg", "count_avg"]]) diff --git a/src/web/web.h b/src/web/web.h index edc12e16..713ce9e6 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -604,6 +604,7 @@ class Web { // zero-export #if defined(ESP32) mConfig->plugin.zexport.enabled = (request->arg("en_zeroexport") == "on"); + mConfig->plugin.zexport.two_percent = (request->arg("two_percent") == "on"); mConfig->plugin.zexport.Iv = request->arg("Iv").toInt(); mConfig->plugin.zexport.count_avg = request->arg("count_avg").toInt(); mConfig->plugin.zexport.power_avg = request->arg("power_avg").toFloat();