diff --git a/src/config/settings.h b/src/config/settings.h index 1b70161b..64375ec3 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -203,7 +203,6 @@ typedef struct { enum class zeroExportState : uint8_t { INIT, - WAIT, WAITREFRESH, GETINVERTERACKS, GETINVERTERDATA, @@ -301,7 +300,7 @@ typedef struct { // zeroExportState state; - zeroExportState stateNext; +// zeroExportState stateNext; unsigned long lastRun; unsigned long lastRefresh; uint16_t sleep; diff --git a/src/plugins/zeroExport/zeroExport.h b/src/plugins/zeroExport/zeroExport.h index c2bacfc1..60373a20 100644 --- a/src/plugins/zeroExport/zeroExport.h +++ b/src/plugins/zeroExport/zeroExport.h @@ -57,9 +57,7 @@ class ZeroExport { * @todo emergency */ void loop(void) { - if ((!mIsInitialized) || (!mCfg->enabled)) { - return; - } + if ((!mIsInitialized) || (!mCfg->enabled)) return; mPowermeter.loop(); @@ -67,206 +65,126 @@ class ZeroExport { bool DoLog = false; for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { - if (!mCfg->groups[group].enabled) { - continue; - } + zeroExportGroup_t *cfgGroup = &mCfg->groups[group]; + + if (!cfgGroup->enabled) continue; // sleep - if (Tsp <= (mCfg->groups[group].lastRun + mCfg->groups[group].sleep)) { - continue; - } - mCfg->groups[group].sleep = 0; + if (Tsp <= (cfgGroup->lastRun + cfgGroup->sleep)) continue; + cfgGroup->sleep = 0; mLog["g"] = group; - mLog["s"] = (uint8_t)mCfg->groups[group].state; - mLog["s2"] = (uint8_t)mCfg->groups[group].stateNext; + mLog["s"] = (uint8_t)cfgGroup->state; - switch (mCfg->groups[group].state) { + switch (cfgGroup->state) { case zeroExportState::INIT: if (groupInit(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - // OK -> Wait, WaitRefresh - mCfg->groups[group].state = zeroExportState::WAIT; - mCfg->groups[group].stateNext = zeroExportState::WAITREFRESH; + cfgGroup->state = zeroExportState::WAITREFRESH; + cfgGroup->sleep = 60000; } else { - // Error -> Wait, Init - mCfg->groups[group].state = zeroExportState::WAIT; - mCfg->groups[group].stateNext = zeroExportState::INIT; - } - break; - case zeroExportState::WAIT: - if (groupWait(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - // OK - if (mCfg->groups[group].state != mCfg->groups[group].stateNext) { - // OK -> Next - mCfg->groups[group].state = mCfg->groups[group].stateNext; - } else { - // OK -> Init - mCfg->groups[group].state = zeroExportState::INIT; - mCfg->groups[group].stateNext = zeroExportState::INIT; - } + cfgGroup->state = zeroExportState::INIT; + cfgGroup->sleep = 60000; +#if defined(ZEROEXPORT_DEV_POWERMETER) + cfgGroup->state = zeroExportState::WAITREFRESH; + cfgGroup->sleep = 10000; +#endif } break; case zeroExportState::WAITREFRESH: if (groupWaitRefresh(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - // OK + cfgGroup->state = zeroExportState::GETINVERTERACKS; #if defined(ZEROEXPORT_DEV_POWERMETER) - mCfg->groups[group].state = zeroExportState::GETPOWERMETER; - mCfg->groups[group].stateNext = zeroExportState::GETPOWERMETER; -#else - mCfg->groups[group].state = zeroExportState::GETINVERTERACKS; - mCfg->groups[group].stateNext = zeroExportState::GETINVERTERACKS; + cfgGroup->state = zeroExportState::GETPOWERMETER; #endif } break; case zeroExportState::GETINVERTERACKS: if (groupGetInverterAcks(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - // OK - mCfg->groups[group].state = zeroExportState::GETINVERTERDATA; - mCfg->groups[group].stateNext = zeroExportState::GETINVERTERDATA; + cfgGroup->state = zeroExportState::GETINVERTERDATA; } else { - // Error - Sleep - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].sleep = 1000; + cfgGroup->sleep = 1000; } break; case zeroExportState::GETINVERTERDATA: if (groupGetInverterData(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - // OK - mCfg->groups[group].state = zeroExportState::BATTERYPROTECTION; - mCfg->groups[group].stateNext = zeroExportState::BATTERYPROTECTION; + cfgGroup->state = zeroExportState::BATTERYPROTECTION; } else { - // Error - Sleep - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].sleep = 500; + cfgGroup->sleep = 500; } break; case zeroExportState::BATTERYPROTECTION: if (groupBatteryprotection(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - // OK - mCfg->groups[group].state = zeroExportState::GETPOWERMETER; - mCfg->groups[group].stateNext = zeroExportState::GETPOWERMETER; + cfgGroup->state = zeroExportState::GETPOWERMETER; } else { - // Error - Sleep - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].sleep = 1000; + cfgGroup->sleep = 1000; } break; case zeroExportState::GETPOWERMETER: if (groupGetPowermeter(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - // OK + cfgGroup->state = zeroExportState::CONTROLLER; #if defined(ZEROEXPORT_DEV_POWERMETER) - mCfg->groups[group].lastRefresh = millis(); - mCfg->groups[group].state = zeroExportState::PUBLISH; - mCfg->groups[group].stateNext = zeroExportState::PUBLISH; -#else - mCfg->groups[group].state = zeroExportState::CONTROLLER; - mCfg->groups[group].stateNext = zeroExportState::CONTROLLER; + cfgGroup->lastRefresh = millis(); + cfgGroup->state = zeroExportState::PUBLISH; #endif } else { - // Error - Sleep - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].sleep = 3000; + cfgGroup->sleep = 3000; } break; case zeroExportState::CONTROLLER: if (groupController(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].lastRefresh = Tsp; - // OK - mCfg->groups[group].state = zeroExportState::PROGNOSE; - mCfg->groups[group].stateNext = zeroExportState::PROGNOSE; + cfgGroup->lastRefresh = Tsp; + cfgGroup->state = zeroExportState::PROGNOSE; } else { - // Error - WaitRefresh - mCfg->groups[group].state = zeroExportState::WAITREFRESH; - mCfg->groups[group].stateNext = zeroExportState::WAITREFRESH; + cfgGroup->state = zeroExportState::WAITREFRESH; } break; case zeroExportState::PROGNOSE: if (groupPrognose(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - // OK - mCfg->groups[group].state = zeroExportState::AUFTEILEN; - mCfg->groups[group].stateNext = zeroExportState::AUFTEILEN; + cfgGroup->state = zeroExportState::AUFTEILEN; } else { - // Error - Sleep - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].sleep = 500; + cfgGroup->sleep = 500; } break; case zeroExportState::AUFTEILEN: if (groupAufteilen(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - // OK - mCfg->groups[group].state = zeroExportState::SETREBOOT; - mCfg->groups[group].stateNext = zeroExportState::SETREBOOT; + cfgGroup->state = zeroExportState::SETREBOOT; } else { - // Error - Sleep - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].sleep = 500; + cfgGroup->sleep = 500; } break; case zeroExportState::SETREBOOT: if (groupSetReboot(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].lastRefresh = Tsp; - // OK - mCfg->groups[group].state = zeroExportState::SETPOWER; - mCfg->groups[group].stateNext = zeroExportState::SETPOWER; + cfgGroup->state = zeroExportState::SETPOWER; } else { - // Error - Sleep - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].sleep = 1000; + cfgGroup->sleep = 1000; } break; case zeroExportState::SETPOWER: if (groupSetPower(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].lastRefresh = Tsp; - // OK - mCfg->groups[group].state = zeroExportState::SETLIMIT; - mCfg->groups[group].stateNext = zeroExportState::SETLIMIT; + cfgGroup->lastRefresh = Tsp; + cfgGroup->state = zeroExportState::SETLIMIT; } else { - // Error - Sleep - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].sleep = 1000; + cfgGroup->sleep = 1000; } break; case zeroExportState::SETLIMIT: if (groupSetLimit(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - // OK - mCfg->groups[group].state = zeroExportState::PUBLISH; - mCfg->groups[group].stateNext = zeroExportState::PUBLISH; + cfgGroup->state = zeroExportState::PUBLISH; } else { - // Error - Sleep - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].sleep = 1000; + cfgGroup->sleep = 1000; } break; case zeroExportState::PUBLISH: if (groupPublish(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - // OK - mCfg->groups[group].state = zeroExportState::WAITREFRESH; - mCfg->groups[group].stateNext = zeroExportState::WAITREFRESH; + cfgGroup->state = zeroExportState::WAITREFRESH; //} else { // TODO: fehlt } break; case zeroExportState::EMERGENCY: - if (groupEmergency(group, &Tsp, &DoLog)) { - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].lastRefresh = Tsp; - // OK - mCfg->groups[group].state = zeroExportState::INIT; - mCfg->groups[group].stateNext = zeroExportState::INIT; + if (groupEmergency(cfgGroup, &Tsp, &DoLog)) { + cfgGroup->lastRefresh = Tsp; + cfgGroup->state = zeroExportState::INIT; //} else { // TODO: fehlt } @@ -274,11 +192,10 @@ class ZeroExport { case zeroExportState::FINISH: case zeroExportState::ERROR: default: - mCfg->groups[group].lastRun = Tsp; - mCfg->groups[group].lastRefresh = Tsp; - mCfg->groups[group].sleep = 1000; - mCfg->groups[group].state = zeroExportState::INIT; - mCfg->groups[group].stateNext = zeroExportState::INIT; + cfgGroup->lastRun = Tsp; + cfgGroup->lastRefresh = Tsp; + cfgGroup->sleep = 1000; + cfgGroup->state = zeroExportState::INIT; break; } @@ -297,12 +214,12 @@ class ZeroExport { } /** tickSecond - * Zeitimpuls + * Time pulse every second + * @param void + * @returns void */ void tickSecond() { - if ((!mIsInitialized) || (!mCfg->enabled)) { - return; - } + if ((!mIsInitialized) || (!mCfg->enabled)) return; // Wait for ACK for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { @@ -324,30 +241,28 @@ class ZeroExport { } /** tickerMidnight - * Zeitimpuls + * Time pulse Midnicht + * @param void + * @returns void */ void tickMidnight(void) { - if ((!mIsInitialized) || (!mCfg->enabled)) { - return; - } + if ((!mIsInitialized) || (!mCfg->enabled)) return; - // Reboot + // Select all Inverter to reboot for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { for (uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) { - // Reboot mCfg->groups[group].inverters[inv].doReboot = true; } } } /** resetWaitLimitAck - * - * @param + * Reset waiting time limit + * @param iv + * @returns void */ void resetWaitLimitAck(Inverter<> *iv) { - if ((!mIsInitialized) || (!mCfg->enabled)) { - return; - } + if ((!mIsInitialized) || (!mCfg->enabled)) return; for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { for (uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) { @@ -368,20 +283,20 @@ class ZeroExport { mLog["D"] = eTsp - bTsp; } sendLog(); + clearLog(); return; } } } } - /** setPowerAck - * - * @param + /** resetPowerAck + * Reset waiting time power + * @param iv + * @returns void */ void resetWaitPowerAck(Inverter<> *iv) { - if ((!mIsInitialized) || (!mCfg->enabled)) { - return; - } + if ((!mIsInitialized) || (!mCfg->enabled)) return; for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { for (uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) { @@ -410,13 +325,12 @@ class ZeroExport { } /** resetWaitRebootAck - * - * @param + * Reset waiting time reboot + * @param iv + * @returns void */ void resetWaitRebootAck(Inverter<> *iv) { - if ((!mIsInitialized) || (!mCfg->enabled)) { - return; - } + if ((!mIsInitialized) || (!mCfg->enabled)) return; for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { for (uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) { @@ -446,52 +360,46 @@ class ZeroExport { /** newDataAvailable * + * @param iv + * @returns void */ void newDataAvailable(Inverter<> *iv) { - if ((!mIsInitialized) || (!mCfg->enabled)) { - return; - } + if ((!mIsInitialized) || (!mCfg->enabled)) return; - if (!iv->isAvailable()) { - return; - } + if (!iv->isAvailable()) return; - if (!iv->isProducing()) { - return; - } + if (!iv->isProducing()) return; - if (iv->actPowerLimit == 65535) { - return; - } + if (iv->actPowerLimit == 65535) return; for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { for (uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) { - if (iv->id == mCfg->groups[group].inverters[inv].id) { - unsigned long bTsp = millis(); - - mLog["t"] = "newDataAvailable"; - mLog["g"] = group; - mLog["i"] = inv; - mLog["id"] = iv->id; - // mLog["a"] = iv->isAvailable(); - // mLog["p"] = iv->isProducing(); - mLog["ivL%"] = iv->actPowerLimit; - mLog["ivPm"] = iv->getMaxPower(); - uint16_t ivL = (iv->getMaxPower() * iv->actPowerLimit) / 100; - mLog["ivL"] = ivL; - mLog["zeL"] = (uint16_t)mCfg->groups[group].inverters[inv].limit; - mCfg->groups[group].inverters[inv].limit = ivL; - - if (mCfg->debug) { - unsigned long eTsp = millis(); - mLog["B"] = bTsp; - mLog["E"] = eTsp; - mLog["D"] = eTsp - bTsp; - } - sendLog(); - clearLog(); - return; + if (!mCfg->groups[group].inverters[inv].enabled) continue; + + if (iv->id != mCfg->groups[group].inverters[inv].id) continue; + + unsigned long bTsp = millis(); + + mLog["t"] = "newDataAvailable"; + mLog["g"] = group; + mLog["i"] = inv; + mLog["id"] = iv->id; + mLog["ivL%"] = iv->actPowerLimit; + mLog["ivPm"] = iv->getMaxPower(); + uint16_t ivL = (iv->getMaxPower() * iv->actPowerLimit) / 100; + mLog["ivL"] = ivL; + mLog["zeL"] = (uint16_t)mCfg->groups[group].inverters[inv].limit; + mCfg->groups[group].inverters[inv].limit = ivL; + + if (mCfg->debug) { + unsigned long eTsp = millis(); + mLog["B"] = bTsp; + mLog["E"] = eTsp; + mLog["D"] = eTsp - bTsp; } + sendLog(); + clearLog(); + return; } } } @@ -500,7 +408,7 @@ class ZeroExport { * Subscribe section */ void onMqttMessage(JsonObject obj) { - if ((!mIsInitialized) || (!mCfg->enabled)) return; + if (!mIsInitialized) return; String topic = String(obj["topic"]); if(!topic.indexOf("/zero/set/")) return; @@ -522,6 +430,7 @@ class ZeroExport { mCfg->enabled = (bool)obj["val"]; mLog["zero_enable"] = mCfg->enabled; } + return; } mLog["Msg"] = obj; @@ -530,20 +439,20 @@ class ZeroExport { } private: + /** NotEnabledOrNotSelected + * Inverter not enabled -> ignore || Inverter not selected -> ignore + */ + bool NotEnabledOrNotSelected(uint8_t group, uint8_t inv) { + return ((!mCfg->groups[group].inverters[inv].enabled) || (mCfg->groups[group].inverters[inv].id < 0)); + } + /** groupInit - * initialisiert die Gruppe und sucht die ivPointer + * Initialize the group and search the InverterPointer * @param group * @returns true/false * @todo getInverterById statt getInverterByPos, dann würde die Variable *iv und die Schleife nicht gebraucht. */ - /* EnabledSelected - * Inverter not enabled -> ignore || Inverter not selected -> ignore - */ - bool NotEnabledOrNotSelected(uint8_t group, uint8_t inv) { - return !mCfg->groups[group].inverters[inv].enabled || mCfg->groups[group].inverters[inv].id < 0; - } - bool groupInit(uint8_t group, unsigned long *tsp, bool *doLog) { uint8_t result = false; @@ -567,7 +476,7 @@ class ZeroExport { mIv[group][inv] = nullptr; - // Inverter not enabled -> ignore + // Inverter not enabled or not selected -> ignore if (NotEnabledOrNotSelected(group, inv)) continue; // Load Config @@ -602,28 +511,8 @@ class ZeroExport { return result; } - /** groupWait - * pausiert die Gruppe bis die Wartezeit 60s seit dem lastRun abgelaufen ist. - * @param group - * @returns true/false - */ - bool groupWait(uint8_t group, unsigned long *tsp, bool *doLog) { - if (mCfg->debug) mLog["t"] = "groupWait"; - - // Wait 60s - if (*tsp <= (mCfg->groups[group].lastRun + 60000UL)) { - return false; - } - - mCfg->groups[group].lastRun = *tsp; - - *doLog = true; - - return true; - } - /** groupWaitRefresh - * pausiert die Gruppe bis die Wartezeit refresh seit dem lastRefresh abgelaufen ist. + * Pauses the group until the wait time since the lastRefresh has expired. * @param group * @returns true/false */ @@ -631,9 +520,7 @@ class ZeroExport { if (mCfg->debug) mLog["t"] = "groupWaitRefresh"; // Wait Refreshtime - if (*tsp <= (mCfg->groups[group].lastRefresh + (mCfg->groups[group].refresh * 1000UL))) { - return false; - } + if (*tsp <= (mCfg->groups[group].lastRefresh + (mCfg->groups[group].refresh * 1000UL))) return false; mCfg->groups[group].lastRun = *tsp; @@ -662,7 +549,7 @@ class ZeroExport { JsonObject logObj = logArr.createNestedObject(); logObj["i"] = inv; - // Inverter not enabled -> ignore + // Inverter not enabled or not selected -> ignore if (NotEnabledOrNotSelected(group, inv)) continue; // Inverter is not available -> wait @@ -675,18 +562,6 @@ class ZeroExport { logObj["wL"] = mCfg->groups[group].inverters[inv].waitLimitAck; wait = true; } - // TODO: Remove -> is moved to groupSetPower - // // waitPowerAck - // if (mCfg->groups[group].inverters[inv].waitPowerAck > 0) { - // logObj["wP"] = mCfg->groups[group].inverters[inv].waitPowerAck; - // wait = true; - // } - // TODO: Remove -> is moved to groupSetReboot - // // waitRebootAck - // if (mCfg->groups[group].inverters[inv].waitRebootAck > 0) { - // logObj["wR"] = mCfg->groups[group].inverters[inv].waitRebootAck; - // wait = true; - // } } mLog["w"] = wait; @@ -714,12 +589,10 @@ class ZeroExport { JsonObject logObj = logArr.createNestedObject(); logObj["i"] = inv; - // Inverter not enabled -> ignore + // Inverter not enabled or not selected -> ignore if (NotEnabledOrNotSelected(group, inv)) continue; - if (!mIv[group][inv]->isAvailable()) { - continue; - } + if (!mIv[group][inv]->isAvailable()) continue; // Get Pac record_t<> *rec; @@ -776,17 +649,12 @@ class ZeroExport { zeroExportGroupInverter_t *cfgGroupInv = &mCfg->groups[group].inverters[inv]; // Ignore disabled Inverter - if (!cfgGroupInv->enabled) { - continue; - } - if (cfgGroupInv->id <= 0) { - continue; - } + if (!cfgGroupInv->enabled) continue; + + if (cfgGroupInv->id < 0) continue; if (!mIv[group][inv]->isAvailable()) { - if (U > 0) { - continue; - } + if (U > 0) continue; U = 0; id = cfgGroupInv->id; continue; @@ -817,7 +685,7 @@ class ZeroExport { for (uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) { // zeroExportGroupInverter_t *cfgGroupInv = &mCfg->groups[group].inverters[inv]; - // Inverter not enabled -> ignore + // Inverter not enabled or not selected -> ignore if (NotEnabledOrNotSelected(group, inv)) continue; // Abbruch weil Inverter nicht verfügbar @@ -833,7 +701,6 @@ class ZeroExport { } mCfg->groups[group].state = zeroExportState::SETPOWER; - mCfg->groups[group].stateNext = zeroExportState::SETPOWER; } } @@ -845,7 +712,7 @@ class ZeroExport { for (uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) { // zeroExportGroupInverter_t *cfgGroupInv = &mCfg->groups[group].inverters[inv]; - // Inverter not enabled -> ignore + // Inverter not enabled or not selected -> ignore if (NotEnabledOrNotSelected(group, inv)) continue; // Abbruch weil Inverter nicht verfügbar @@ -861,7 +728,6 @@ class ZeroExport { } mCfg->groups[group].state = zeroExportState::SETPOWER; - mCfg->groups[group].stateNext = zeroExportState::SETPOWER; } } } else { @@ -922,7 +788,6 @@ class ZeroExport { // Führungsgröße w in Watt float w = mCfg->groups[group].setPoint; - mLog["w"] = w; // Regelgröße x in Watt @@ -930,7 +795,6 @@ class ZeroExport { float x1 = mCfg->groups[group].pmPowerL1; float x2 = mCfg->groups[group].pmPowerL2; float x3 = mCfg->groups[group].pmPowerL3; - mLog["x"] = x; mLog["x1"] = x1; mLog["x2"] = x2; @@ -941,12 +805,10 @@ class ZeroExport { float e1 = w - x1; float e2 = w - x2; float e3 = w - x3; - mLog["e"] = e; mLog["e1"] = e1; mLog["e2"] = e2; mLog["e3"] = e3; - if ( (e < mCfg->groups[group].powerTolerance) && (e > -mCfg->groups[group].powerTolerance) && (e1 < mCfg->groups[group].powerTolerance) && (e1 > -mCfg->groups[group].powerTolerance) && @@ -1021,7 +883,6 @@ class ZeroExport { mLog["y1"] = y1; mLog["y2"] = y2; mLog["y3"] = y3; - mCfg->groups[group].grpPower = y; mCfg->groups[group].grpPowerL1 = y1; mCfg->groups[group].grpPowerL2 = y2; @@ -1219,7 +1080,7 @@ class ZeroExport { JsonObject logObj = logArr.createNestedObject(); logObj["i"] = inv; - // Inverter not enabled -> ignore + // Inverter not enabled or not selected -> ignore if (NotEnabledOrNotSelected(group, inv)) continue; *doLog = true; @@ -1288,7 +1149,7 @@ class ZeroExport { JsonObject logObj = logArr.createNestedObject(); logObj["i"] = inv; - // Inverter not enabled -> ignore + // Inverter not enabled or not selected -> ignore if (NotEnabledOrNotSelected(group, inv)) continue; if (mCfg->debug) *doLog = true; @@ -1323,7 +1184,7 @@ class ZeroExport { if ( ( (mCfg->groups[group].battSwitch == false) || - (mCfg->groups[group].inverters[inv].limitNew < mCfg->groups[group].inverters[inv].powerMin)) && + (mCfg->groups[group].inverters[inv].limitNew < (mCfg->groups[group].inverters[inv].powerMin - 50))) && (mIv[group][inv]->isProducing() == true)) { // Off mCfg->groups[group].inverters[inv].doPower = false; @@ -1383,7 +1244,7 @@ class ZeroExport { JsonObject logObj = logArr.createNestedObject(); logObj["i"] = inv; - // Inverter not enabled -> ignore + // Inverter not enabled or not selected -> ignore if (NotEnabledOrNotSelected(group, inv)) continue; // if isOff -> Limit Pmin @@ -1392,14 +1253,10 @@ class ZeroExport { } // Nothing todo - if (mCfg->groups[group].inverters[inv].limit == mCfg->groups[group].inverters[inv].limitNew) { - continue; - } + if (mCfg->groups[group].inverters[inv].limit == mCfg->groups[group].inverters[inv].limitNew) continue; // Abbruch weil Inverter nicht verfügbar - if (!mIv[group][inv]->isAvailable()) { - continue; - } + if (!mIv[group][inv]->isAvailable()) continue; // Abbruch weil Inverter produziert nicht /// if (!mIv[group][inv]->isProducing()) { @@ -1433,9 +1290,7 @@ class ZeroExport { } // Nothing todo - if (mCfg->groups[group].inverters[inv].limit == mCfg->groups[group].inverters[inv].limitNew) { - continue; - } + if (mCfg->groups[group].inverters[inv].limit == mCfg->groups[group].inverters[inv].limitNew) continue; *doLog = true; @@ -1526,10 +1381,10 @@ class ZeroExport { * @returns true/false * @todo Hier ist noch keine Funktion */ - bool groupEmergency(uint8_t group, unsigned long *tsp, bool *doLog) { + bool groupEmergency(zeroExportGroup_t *cfgGroup, unsigned long *tsp, bool *doLog) { if (mCfg->debug) mLog["t"] = "groupEmergency"; - mCfg->groups[group].lastRun = *tsp; + cfgGroup->lastRun = *tsp; *doLog = true; @@ -1546,7 +1401,7 @@ class ZeroExport { */ void sendLog(void) { if (mCfg->log_over_webserial) { -// DBGPRINTLN(String("ze: ") + mDocLog.as()); + // DBGPRINTLN(String("ze: ") + mDocLog.as()); DPRINTLN(DBG_INFO, String("ze: ") + mDocLog.as()); } @@ -1581,4 +1436,4 @@ class ZeroExport { #endif /*__ZEROEXPORT__*/ -#endif /* #if defined(PLUGIN_ZEROEXPORT) */ \ No newline at end of file +#endif /* #if defined(PLUGIN_ZEROEXPORT) */ diff --git a/src/web/RestApi.h b/src/web/RestApi.h index 045eb2d8..70a30a48 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -1159,7 +1159,6 @@ class RestApi { mConfig->plugin.zeroExport.groups[group].Kd = jsonIn[F("Kd")]; // Global mConfig->plugin.zeroExport.groups[group].state = zeroExportState::INIT; - mConfig->plugin.zeroExport.groups[group].stateNext = zeroExportState::INIT; mApp->saveSettings(false); // without reboot } #endif