|
@ -14,7 +14,6 @@ |
|
|
|
|
|
|
|
|
#include "AsyncJson.h" |
|
|
#include "AsyncJson.h" |
|
|
#include "powermeter.h" |
|
|
#include "powermeter.h" |
|
|
|
|
|
|
|
|
#include "utils/DynamicJsonHandler.h" |
|
|
#include "utils/DynamicJsonHandler.h" |
|
|
|
|
|
|
|
|
template <class HMSYSTEM> |
|
|
template <class HMSYSTEM> |
|
@ -24,7 +23,7 @@ class ZeroExport { |
|
|
/** ZeroExport
|
|
|
/** ZeroExport
|
|
|
* constructor |
|
|
* constructor |
|
|
*/ |
|
|
*/ |
|
|
ZeroExport() { } |
|
|
ZeroExport() {} |
|
|
|
|
|
|
|
|
/** ~ZeroExport
|
|
|
/** ~ZeroExport
|
|
|
* destructor |
|
|
* destructor |
|
@ -52,7 +51,6 @@ class ZeroExport { |
|
|
mIsInitialized = mPowermeter.setup(mApp, mCfg, mqtt, &_log); |
|
|
mIsInitialized = mPowermeter.setup(mApp, mCfg, mqtt, &_log); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*void printJson() {
|
|
|
/*void printJson() {
|
|
|
serializeJson(doc, Serial); |
|
|
serializeJson(doc, Serial); |
|
|
Serial.println(); |
|
|
Serial.println(); |
|
@ -91,19 +89,18 @@ class ZeroExport { |
|
|
zeroExportGroup_t *CfgGroup = &mCfg->groups[group]; |
|
|
zeroExportGroup_t *CfgGroup = &mCfg->groups[group]; |
|
|
zeroExportGroupInverter_t *CfgGroupInv = &CfgGroup->inverters[inv]; |
|
|
zeroExportGroupInverter_t *CfgGroupInv = &CfgGroup->inverters[inv]; |
|
|
Inverter<> *iv = mSys->getInverterByPos(Queue.id); |
|
|
Inverter<> *iv = mSys->getInverterByPos(Queue.id); |
|
|
if(NULL == iv) return; |
|
|
if (NULL == iv) return; |
|
|
|
|
|
|
|
|
if(!CfgGroup->battSwitch && !CfgGroup->battSwitchInit) |
|
|
if (!CfgGroup->battSwitch && !CfgGroup->battSwitchInit) { |
|
|
{ |
|
|
if (!iv->alarmCnt) return; |
|
|
if(!iv->alarmCnt) return; |
|
|
|
|
|
bool stb_flag = false; |
|
|
bool stb_flag = false; |
|
|
|
|
|
|
|
|
for(int16_t i = 0; i < iv->alarmCnt; i++) { |
|
|
for (int16_t i = 0; i < iv->alarmCnt; i++) { |
|
|
if(iv->lastAlarm[i].code == 124) { |
|
|
if (iv->lastAlarm[i].code == 124) { |
|
|
stb_flag = true; |
|
|
stb_flag = true; |
|
|
_log.addProperty("alarm1", stb_flag); |
|
|
_log.addProperty("alarm1", stb_flag); |
|
|
_log.addProperty("start", iv->lastAlarm[i].start ); |
|
|
_log.addProperty("start", iv->lastAlarm[i].start); |
|
|
_log.addProperty("end", iv->lastAlarm[i].end ); |
|
|
_log.addProperty("end", iv->lastAlarm[i].end); |
|
|
|
|
|
|
|
|
if (iv->lastAlarm[i].end > iv->lastAlarm[i].start) { |
|
|
if (iv->lastAlarm[i].end > iv->lastAlarm[i].start) { |
|
|
stb_flag = false; |
|
|
stb_flag = false; |
|
@ -113,7 +110,7 @@ class ZeroExport { |
|
|
clearLog(); |
|
|
clearLog(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if(!stb_flag) CfgGroup->battSwitch = true; |
|
|
if (!stb_flag) CfgGroup->battSwitch = true; |
|
|
CfgGroup->battSwitchInit = true; |
|
|
CfgGroup->battSwitchInit = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -152,7 +149,6 @@ class ZeroExport { |
|
|
_log.addProperty("gL", groupLimit); |
|
|
_log.addProperty("gL", groupLimit); |
|
|
// Wird nur zum debuggen benötigt?
|
|
|
// Wird nur zum debuggen benötigt?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Batteryprotection
|
|
|
// Batteryprotection
|
|
|
_log.addProperty("bEn", (uint8_t)CfgGroup->battCfg); |
|
|
_log.addProperty("bEn", (uint8_t)CfgGroup->battCfg); |
|
|
|
|
|
|
|
@ -172,10 +168,10 @@ class ZeroExport { |
|
|
CfgGroup->battSwitch = true; |
|
|
CfgGroup->battSwitch = true; |
|
|
_log.addProperty("bA", "turn on"); |
|
|
_log.addProperty("bA", "turn on"); |
|
|
} |
|
|
} |
|
|
//if ((CfgGroup->battValue > CfgGroup->battLimitOff) && (CfgGroupInv->power > 0)) {
|
|
|
// if ((CfgGroup->battValue > CfgGroup->battLimitOff) && (CfgGroupInv->power > 0)) {
|
|
|
// CfgGroup->battSwitch = true;
|
|
|
// CfgGroup->battSwitch = true;
|
|
|
// _log.addProperty("bA", "turn on");
|
|
|
// _log.addProperty("bA", "turn on");
|
|
|
//}
|
|
|
// }
|
|
|
} else { |
|
|
} else { |
|
|
if (CfgGroup->battValue < CfgGroup->battLimitOff) { |
|
|
if (CfgGroup->battValue < CfgGroup->battLimitOff) { |
|
|
CfgGroup->battSwitch = false; |
|
|
CfgGroup->battSwitch = false; |
|
@ -649,7 +645,7 @@ class ZeroExport { |
|
|
|
|
|
|
|
|
mPowermeter.onMqttConnect(); |
|
|
mPowermeter.onMqttConnect(); |
|
|
|
|
|
|
|
|
// "topic":"userdefined battSoCTopic"
|
|
|
// "topic":"userdefined battSoCTopic" oder "userdefinedUTopic"
|
|
|
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { |
|
|
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { |
|
|
if (!mCfg->groups[group].enabled) continue; |
|
|
if (!mCfg->groups[group].enabled) continue; |
|
|
|
|
|
|
|
@ -673,7 +669,7 @@ class ZeroExport { |
|
|
|
|
|
|
|
|
String topic = String(obj["topic"]); |
|
|
String topic = String(obj["topic"]); |
|
|
|
|
|
|
|
|
// "topic":"userdefined battSoCTopic"
|
|
|
// "topic":"userdefined battSoCTopic" oder "userdefinedUTopic"
|
|
|
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { |
|
|
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { |
|
|
if (!mCfg->groups[group].enabled) continue; |
|
|
if (!mCfg->groups[group].enabled) continue; |
|
|
|
|
|
|
|
@ -684,7 +680,6 @@ class ZeroExport { |
|
|
if (strcmp(mCfg->groups[group].battTopic, String(topic).c_str())) { |
|
|
if (strcmp(mCfg->groups[group].battTopic, String(topic).c_str())) { |
|
|
mCfg->groups[group].battValue = (bool)obj["val"]; |
|
|
mCfg->groups[group].battValue = (bool)obj["val"]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_log.addProperty("k", mCfg->groups[group].battTopic); |
|
|
_log.addProperty("k", mCfg->groups[group].battTopic); |
|
|
_log.addProperty("v", mCfg->groups[group].battValue); |
|
|
_log.addProperty("v", mCfg->groups[group].battValue); |
|
|
} |
|
|
} |
|
@ -693,7 +688,6 @@ class ZeroExport { |
|
|
// "topic":"ctrl/zero"
|
|
|
// "topic":"ctrl/zero"
|
|
|
if (topic.indexOf("ctrl/zero") == -1) return; |
|
|
if (topic.indexOf("ctrl/zero") == -1) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_log.addProperty("d", obj); |
|
|
_log.addProperty("d", obj); |
|
|
|
|
|
|
|
|
if (obj["path"] == "ctrl" && obj["cmd"] == "zero") { |
|
|
if (obj["path"] == "ctrl" && obj["cmd"] == "zero") { |
|
@ -721,8 +715,7 @@ class ZeroExport { |
|
|
mCfg->sleep = (bool)obj["val"]; |
|
|
mCfg->sleep = (bool)obj["val"]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else if ((topicGroup >= 0) && (topicGroup < ZEROEXPORT_MAX_GROUPS)) |
|
|
else if ((topicGroup >= 0) && (topicGroup < ZEROEXPORT_MAX_GROUPS)) { |
|
|
{ |
|
|
|
|
|
String stopicGroup = String(topicGroup); |
|
|
String stopicGroup = String(topicGroup); |
|
|
|
|
|
|
|
|
// "topic":"ctrl/zero/groups/+/enabled"
|
|
|
// "topic":"ctrl/zero/groups/+/enabled"
|
|
@ -765,8 +758,7 @@ class ZeroExport { |
|
|
mCfg->groups[topicGroup].battSwitch = (bool)obj["val"]; |
|
|
mCfg->groups[topicGroup].battSwitch = (bool)obj["val"]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else if (topic.indexOf("/advanced/") != -1) |
|
|
else if (topic.indexOf("/advanced/") != -1) { |
|
|
{ |
|
|
|
|
|
// "topic":"ctrl/zero/groups/+/advanced/setPoint"
|
|
|
// "topic":"ctrl/zero/groups/+/advanced/setPoint"
|
|
|
if (topic.endsWith("/setPoint")) { |
|
|
if (topic.endsWith("/setPoint")) { |
|
|
_log.addProperty("v", (int16_t)obj["val"]); |
|
|
_log.addProperty("v", (int16_t)obj["val"]); |
|
@ -784,11 +776,8 @@ class ZeroExport { |
|
|
_log.addProperty("v", (uint16_t)obj["val"]); |
|
|
_log.addProperty("v", (uint16_t)obj["val"]); |
|
|
mCfg->groups[topicGroup].powerMax = (uint16_t)obj["val"]; |
|
|
mCfg->groups[topicGroup].powerMax = (uint16_t)obj["val"]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} else if (topic.indexOf("/inverter/") != -1) { |
|
|
else if (topic.indexOf("/inverter/") != -1) |
|
|
if ((topicInverter >= 0) && (topicInverter < ZEROEXPORT_GROUP_MAX_INVERTERS)) { |
|
|
{ |
|
|
|
|
|
if ((topicInverter >= 0) && (topicInverter < ZEROEXPORT_GROUP_MAX_INVERTERS)) |
|
|
|
|
|
{ |
|
|
|
|
|
// "topic":"ctrl/zero/groups/+/inverter/+/enabled"
|
|
|
// "topic":"ctrl/zero/groups/+/inverter/+/enabled"
|
|
|
if (topic.endsWith("/enabled")) { |
|
|
if (topic.endsWith("/enabled")) { |
|
|
_log.addProperty("v", (bool)obj["val"]); |
|
|
_log.addProperty("v", (bool)obj["val"]); |
|
@ -804,14 +793,11 @@ class ZeroExport { |
|
|
else if (topic.endsWith("/powerMax")) { |
|
|
else if (topic.endsWith("/powerMax")) { |
|
|
_log.addProperty("v", (uint16_t)obj["val"]); |
|
|
_log.addProperty("v", (uint16_t)obj["val"]); |
|
|
mCfg->groups[topicGroup].inverters[topicInverter].powerMax = (uint16_t)obj["val"]; |
|
|
mCfg->groups[topicGroup].inverters[topicInverter].powerMax = (uint16_t)obj["val"]; |
|
|
} |
|
|
} else { |
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
_log.addProperty("k", "error"); |
|
|
_log.addProperty("k", "error"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
else { |
|
|
|
|
|
_log.addProperty("k", "error"); |
|
|
_log.addProperty("k", "error"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|