diff --git a/src/config/settings.h b/src/config/settings.h index fe7f4694..5412ddc3 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -203,7 +203,7 @@ typedef struct { // Plugin ZeroExport #if defined(PLUGIN_ZEROEXPORT) -#define ZEROEXPORT_DEV_POWERMETER +//#define ZEROEXPORT_DEV_POWERMETER #define ZEROEXPORT_MAX_GROUPS 6 #define ZEROEXPORT_GROUP_MAX_LEN_NAME 25 #define ZEROEXPORT_GROUP_MAX_LEN_PM_URL 100 diff --git a/src/defines.h b/src/defines.h index 43fc63b0..3f586b96 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 1030001 +#define VERSION_PATCH 1030002 //------------------------------------- typedef struct { uint8_t ch; diff --git a/src/plugins/zeroExport/zeroExport.h b/src/plugins/zeroExport/zeroExport.h index 10ffa31f..c3578929 100644 --- a/src/plugins/zeroExport/zeroExport.h +++ b/src/plugins/zeroExport/zeroExport.h @@ -428,83 +428,64 @@ class ZeroExport { mLog["t"] = "onMqttMessage"; if (obj["path"] == "zero" && obj["cmd"] == "set") { -/* - // "topic":"???/zero/set/enabled" - if (topic.indexOf("zero/set/enabled") != -1) { - - } - else - // "topic":"???/zero/set/sleep" - if (topic.indexOf("zero/set/sleep") != -1) { - - } - else - // "topic":"???/zero/set/groups/0/enabled" - if (topic.indexOf("zero/set/groups") != -1) { - String i = topic.substring(topic.length() - 10, topic.length() - 8); - uint8_t group = i.toInt(); - mLog["g"] = group; - if (topic.indexOf("enabled") != -1) { + int8_t topicGroup = getGroupFromTopic(topic.c_str()); + int8_t topicInverter = getInverterFromTopic(topic.c_str()); + + if((topicGroup == -1) && (topicInverter == -1)) { + // "topic":"???/zero/set/enabled" + if (topic.indexOf("zero/set/enabled") != -1) { + mCfg->enabled = (bool)obj["val"]; + mLog["mCfg->enabled"] = mCfg->enabled; + // Initialize groups + for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { + mCfg->groups[group].state = zeroExportState::INIT; + mCfg->groups[group].wait = 0; + } } - if (topic.indexOf("zero/set/groups") != -1) { + else + // "topic":"???/zero/set/sleep" + if (topic.indexOf("zero/set/sleep") != -1) { + mCfg->sleep = (bool)obj["val"]; + mLog["mCfg->sleep"] = mCfg->sleep; } } -*/ - // "topic":"inverter/zero/set/groups/0/enabled" - if (topic.indexOf("groups") != -1) { - // TODO: Topicprüfung - // TODO: Topicprüfung ist 10 und 8 korrekt? - // TODO: Wäre es nicht besser das anhand der / rauszufiltern wenn es 2-stellige Gruppen gibt? - String i = topic.substring(topic.length() - 10, topic.length() - 8); - uint8_t group = i.toInt(); - mLog["g"] = group; - - mCfg->groups[group].enabled = (bool)obj["val"]; - - // Initialize group - mCfg->groups[group].state = zeroExportState::INIT; - mCfg->groups[group].sleep = 0; - } else { - // TODO: Topicprüfung - mCfg->enabled = (bool)obj["val"]; - mLog["mCfg->enabled"] = mCfg->enabled; - - // Initialize groups - for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { - mCfg->groups[group].state = zeroExportState::INIT; - mCfg->groups[group].sleep = 0; - } - } - } - -// Global -// - enabled - -// General -// - enabled - -// Powermeter -/// ? - -// Inverter -// - enabled -// - powerMin -// - powerMax - + else + if((topicGroup != -1) && (topicInverter == -1)) { + uint8_t group = topicGroup; + // "topic":"???/zero/set/groups/0/???" +// if (topic.indexOf("zero/set/groups/") != -1) { +// String i = topic.substring(topic.length() - 10, topic.length() - 8); +// uint8_t group = i.toInt(); + mLog["g"] = group; + // "topic":"???/zero/set/groups/0/enabled" + if (topic.indexOf("enabled") != -1) { + mCfg->groups[group].enabled = (bool)obj["val"]; + // Initialize group + mCfg->groups[group].state = zeroExportState::INIT; + mCfg->groups[group].wait = 0; + } + // "topic":"???/zero/set/groups/0/sleep" + if (topic.indexOf("sleep") != -1) { + mCfg->groups[group].sleep = (bool)obj["val"]; + } +// } // Battery -/// - enabled -/// - voltageOn -/// - voltageOff // - switch // Advanced // - setpoint -/// - refresh // - powerTolerance // - powerMax -/// - Kp -/// - Ki -/// - Kd + } + else + if((topicGroup != -1) && (topicInverter != -1)) { +// Inverter +// - enabled +// - powerMin +// - powerMax + + } + } mLog["Msg"] = obj; sendLog(); @@ -523,6 +504,30 @@ class ZeroExport { return ((!mCfg->groups[group].inverters[inv].enabled) || (mCfg->groups[group].inverters[inv].id < 0)); } + int8_t getGroupFromTopic(const char* topic) { + const char* pGroupSection = strstr(topic, "groups/"); + if (pGroupSection == NULL) return -1; + pGroupSection += 7; + char strGroup[3]; + uint8_t digitsCopied = 0; + while(*pGroupSection != '/' && digitsCopied < 2) strGroup[digitsCopied++] = *pGroupSection++; + strGroup[digitsCopied] = '\0'; + int8_t group = atoi(strGroup); + return group; + } + + int8_t getInverterFromTopic(const char* topic) { + const char* pInverterSection = strstr(topic, "inverters/"); + if (pInverterSection == NULL) return -1; + pInverterSection += 10; + char strInverter[3]; + uint8_t digitsCopied = 0; + while(*pInverterSection != '/' && digitsCopied < 2) strInverter[digitsCopied++] = *pInverterSection++; + strInverter[digitsCopied] = '\0'; + int8_t inverter = atoi(strInverter); + return inverter; + } + /** groupInit * Initialize the group and search the InverterPointer * @param group @@ -1428,16 +1433,36 @@ class ZeroExport { mMqtt->subscribe(gr.c_str(), QOS_2); // Powermeter -// TODO: fehlt // Inverters -// TODO: fehlt + for (uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) { + zeroExportGroupInverter_t *cfgGroupInv = &cfgGroup->inverters[inv]; + gr = "zero/set/groups/" + String(group) + "/inverters/" + String(inv) + "/enabled"; + mMqtt->publish(gr.c_str(), ((cfgGroupInv->enabled) ? dict[STR_TRUE] : dict[STR_FALSE]), false); + mMqtt->subscribe(gr.c_str(), QOS_2); + gr = "zero/set/groups/" + String(group) + "/inverters/" + String(inv) + "/powerMin"; + mMqtt->publish(gr.c_str(), String(cfgGroupInv->powerMin).c_str(), false); + mMqtt->subscribe(gr.c_str(), QOS_2); + gr = "zero/set/groups/" + String(group) + "/inverters/" + String(inv) + "/powerMax"; + mMqtt->publish(gr.c_str(), String(cfgGroupInv->powerMax).c_str(), false); + mMqtt->subscribe(gr.c_str(), QOS_2); + } // Battery -// TODO: fehlt + gr = "zero/set/groups/" + String(group) + "/battery/switch"; + mMqtt->publish(gr.c_str(), ((cfgGroup->battSwitch) ? dict[STR_TRUE] : dict[STR_FALSE]), false); + mMqtt->subscribe(gr.c_str(), QOS_2); // Advanced -// TODO: fehlt + gr = "zero/set/groups/" + String(group) + "/advanced/setPoint"; + mMqtt->publish(gr.c_str(), String(cfgGroup->setPoint).c_str(), false); + mMqtt->subscribe(gr.c_str(), QOS_2); + gr = "zero/set/groups/" + String(group) + "/advanced/powerTolerance"; + mMqtt->publish(gr.c_str(), String(cfgGroup->powerTolerance).c_str(), false); + mMqtt->subscribe(gr.c_str(), QOS_2); + gr = "zero/set/groups/" + String(group) + "/advanced/powerMax"; + mMqtt->publish(gr.c_str(), String(cfgGroup->powerMax).c_str(), false); + mMqtt->subscribe(gr.c_str(), QOS_2); } // Global (zeroExport)