mirror of
https://github.com/lumapu/ahoy.git
synced 2025-07-05 18:47:15 +02:00
ZE MQTT
This commit is contained in:
parent
8067c48bad
commit
58a5cc43ab
1 changed files with 93 additions and 76 deletions
|
@ -387,7 +387,8 @@ class ZeroExport {
|
||||||
|
|
||||||
// Calculate
|
// Calculate
|
||||||
int32_t ivLp = iv->actPowerLimit;
|
int32_t ivLp = iv->actPowerLimit;
|
||||||
int32_t ivPm = iv->getMaxPower();;
|
int32_t ivPm = iv->getMaxPower();
|
||||||
|
;
|
||||||
int32_t ivL = (ivPm * ivLp) / 100;
|
int32_t ivL = (ivPm * ivLp) / 100;
|
||||||
int32_t zeL = mCfg->groups[group].inverters[inv].limit;
|
int32_t zeL = mCfg->groups[group].inverters[inv].limit;
|
||||||
|
|
||||||
|
@ -432,11 +433,13 @@ class ZeroExport {
|
||||||
|
|
||||||
if (obj["path"] == "zero" && obj["cmd"] == "set") {
|
if (obj["path"] == "zero" && obj["cmd"] == "set") {
|
||||||
int8_t topicGroup = getGroupFromTopic(topic.c_str());
|
int8_t topicGroup = getGroupFromTopic(topic.c_str());
|
||||||
|
mLog["topicGroup"] = topicGroup;
|
||||||
int8_t topicInverter = getInverterFromTopic(topic.c_str());
|
int8_t topicInverter = getInverterFromTopic(topic.c_str());
|
||||||
|
mLog["topicInverter"] = topicInverter;
|
||||||
|
|
||||||
if ((topicGroup == -1) && (topicInverter == -1)) {
|
if ((topicGroup == -1) && (topicInverter == -1)) {
|
||||||
// "topic":"???/zero/set/enabled"
|
// "topic":"???/zero/set/enabled"
|
||||||
if (topic.indexOf("zero/set/enabled") != -1) {
|
if (topic.indexOf("/zero/set/enabled") != -1) {
|
||||||
mCfg->enabled = (bool)obj["val"];
|
mCfg->enabled = (bool)obj["val"];
|
||||||
mLog["mCfg->enabled"] = mCfg->enabled;
|
mLog["mCfg->enabled"] = mCfg->enabled;
|
||||||
// Initialize groups
|
// Initialize groups
|
||||||
|
@ -445,48 +448,54 @@ class ZeroExport {
|
||||||
mCfg->groups[group].wait = 0;
|
mCfg->groups[group].wait = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
// "topic":"???/zero/set/sleep"
|
// "topic":"???/zero/set/sleep"
|
||||||
if (topic.indexOf("zero/set/sleep") != -1) {
|
if (topic.indexOf("/zero/set/sleep") != -1) {
|
||||||
mCfg->sleep = (bool)obj["val"];
|
mCfg->sleep = (bool)obj["val"];
|
||||||
mLog["mCfg->sleep"] = mCfg->sleep;
|
mLog["mCfg->sleep"] = mCfg->sleep;
|
||||||
}
|
}
|
||||||
}
|
} else if ((topicGroup != -1) && (topicInverter == -1)) {
|
||||||
else
|
|
||||||
if((topicGroup != -1) && (topicInverter == -1)) {
|
|
||||||
uint8_t group = topicGroup;
|
|
||||||
// "topic":"???/zero/set/groups/0/???"
|
// "topic":"???/zero/set/groups/0/???"
|
||||||
// if (topic.indexOf("zero/set/groups/") != -1) {
|
mLog["g"] = topicGroup;
|
||||||
// String i = topic.substring(topic.length() - 10, topic.length() - 8);
|
|
||||||
// uint8_t group = i.toInt();
|
|
||||||
mLog["g"] = group;
|
|
||||||
// "topic":"???/zero/set/groups/0/enabled"
|
// "topic":"???/zero/set/groups/0/enabled"
|
||||||
if (topic.indexOf("enabled") != -1) {
|
if (topic.indexOf("enabled") != -1) {
|
||||||
mCfg->groups[group].enabled = (bool)obj["val"];
|
mCfg->groups[topicGroup].enabled = (bool)obj["val"];
|
||||||
// Initialize group
|
// Initialize group
|
||||||
mCfg->groups[group].state = zeroExportState::INIT;
|
mCfg->groups[topicGroup].state = zeroExportState::INIT;
|
||||||
mCfg->groups[group].wait = 0;
|
mCfg->groups[topicGroup].wait = 0;
|
||||||
}
|
}
|
||||||
// "topic":"???/zero/set/groups/0/sleep"
|
// "topic":"???/zero/set/groups/0/sleep"
|
||||||
if (topic.indexOf("sleep") != -1) {
|
if (topic.indexOf("sleep") != -1) {
|
||||||
mCfg->groups[group].sleep = (bool)obj["val"];
|
mCfg->groups[topicGroup].sleep = (bool)obj["val"];
|
||||||
}
|
}
|
||||||
// }
|
// "topic":"???/zero/set/groups/0/battery/switch"
|
||||||
// Battery
|
if (topic.indexOf("battery/switch") != -1) {
|
||||||
// - switch
|
mCfg->groups[topicGroup].battSwitch = (bool)obj["val"];
|
||||||
|
}
|
||||||
// Advanced
|
// "topic":"???/zero/set/groups/0/advanced/setPoint"
|
||||||
// - setpoint
|
if (topic.indexOf("advanced/setPoint") != -1) {
|
||||||
// - powerTolerance
|
mCfg->groups[topicGroup].setPoint = (int32_t)obj["val"];
|
||||||
// - powerMax
|
}
|
||||||
|
// "topic":"???/zero/set/groups/0/advanced/powerTolerance"
|
||||||
|
if (topic.indexOf("advanced/powerTolerance") != -1) {
|
||||||
|
mCfg->groups[topicGroup].powerTolerance = (uint16_t)obj["val"];
|
||||||
|
}
|
||||||
|
// "topic":"???/zero/set/groups/0/advanced/powerMax"
|
||||||
|
if (topic.indexOf("advanced/powerMax") != -1) {
|
||||||
|
mCfg->groups[topicGroup].powerMax = (uint16_t)obj["val"];
|
||||||
|
}
|
||||||
|
} else if ((topicGroup != -1) && (topicInverter != -1)) {
|
||||||
|
// "topic":"???/zero/set/groups/0/inverter/0/enabled"
|
||||||
|
if (topic.indexOf("enabled") != -1) {
|
||||||
|
mCfg->groups[topicGroup].inverters[topicInverter].enabled = (bool)obj["val"];
|
||||||
|
}
|
||||||
|
// "topic":"???/zero/set/groups/0/inverter/0/powerMin"
|
||||||
|
if (topic.indexOf("powerMin") != -1) {
|
||||||
|
mCfg->groups[topicGroup].inverters[topicInverter].powerMin = (uint16_t)obj["val"];
|
||||||
|
}
|
||||||
|
// "topic":"???/zero/set/groups/0/inverter/0/powerMax"
|
||||||
|
if (topic.indexOf("powerMax") != -1) {
|
||||||
|
mCfg->groups[topicGroup].inverters[topicInverter].powerMax = (uint16_t)obj["val"];
|
||||||
}
|
}
|
||||||
else
|
|
||||||
if((topicGroup != -1) && (topicInverter != -1)) {
|
|
||||||
// Inverter
|
|
||||||
// - enabled
|
|
||||||
// - powerMin
|
|
||||||
// - powerMax
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,6 +516,11 @@ class ZeroExport {
|
||||||
return ((!mCfg->groups[group].inverters[inv].enabled) || (mCfg->groups[group].inverters[inv].id < 0));
|
return ((!mCfg->groups[group].inverters[inv].enabled) || (mCfg->groups[group].inverters[inv].id < 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** getGroupFromTopic
|
||||||
|
*
|
||||||
|
* @param
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
int8_t getGroupFromTopic(const char *topic) {
|
int8_t getGroupFromTopic(const char *topic) {
|
||||||
const char *pGroupSection = strstr(topic, "groups/");
|
const char *pGroupSection = strstr(topic, "groups/");
|
||||||
if (pGroupSection == NULL) return -1;
|
if (pGroupSection == NULL) return -1;
|
||||||
|
@ -519,6 +533,11 @@ class ZeroExport {
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** getInverterFromTopic
|
||||||
|
*
|
||||||
|
* @param
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
int8_t getInverterFromTopic(const char *topic) {
|
int8_t getInverterFromTopic(const char *topic) {
|
||||||
const char *pInverterSection = strstr(topic, "inverters/");
|
const char *pInverterSection = strstr(topic, "inverters/");
|
||||||
if (pInverterSection == NULL) return -1;
|
if (pInverterSection == NULL) return -1;
|
||||||
|
@ -537,7 +556,6 @@ class ZeroExport {
|
||||||
* @returns true/false
|
* @returns true/false
|
||||||
* @todo getInverterById statt getInverterByPos, dann würde die Variable *iv und die Schleife nicht gebraucht.
|
* @todo getInverterById statt getInverterByPos, dann würde die Variable *iv und die Schleife nicht gebraucht.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool groupInit(uint8_t group, unsigned long *tsp, bool *doLog) {
|
bool groupInit(uint8_t group, unsigned long *tsp, bool *doLog) {
|
||||||
uint8_t result = false;
|
uint8_t result = false;
|
||||||
|
|
||||||
|
@ -1539,7 +1557,6 @@ class ZeroExport {
|
||||||
obj["Kd"] = cfgGroup->Kd;
|
obj["Kd"] = cfgGroup->Kd;
|
||||||
mMqtt->publish(gr.c_str(), doc.as<std::string>().c_str(), false);
|
mMqtt->publish(gr.c_str(), doc.as<std::string>().c_str(), false);
|
||||||
doc.clear();
|
doc.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue