Browse Source

0.8.1030002-zero

0.8.1030002-zero
pull/1581/head
tictrick 10 months ago
committed by GitHub
parent
commit
7ca8585d58
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      src/config/settings.h
  2. 2
      src/defines.h
  3. 167
      src/plugins/zeroExport/zeroExport.h

2
src/config/settings.h

@ -203,7 +203,7 @@ typedef struct {
// Plugin ZeroExport // Plugin ZeroExport
#if defined(PLUGIN_ZEROEXPORT) #if defined(PLUGIN_ZEROEXPORT)
#define ZEROEXPORT_DEV_POWERMETER //#define ZEROEXPORT_DEV_POWERMETER
#define ZEROEXPORT_MAX_GROUPS 6 #define ZEROEXPORT_MAX_GROUPS 6
#define ZEROEXPORT_GROUP_MAX_LEN_NAME 25 #define ZEROEXPORT_GROUP_MAX_LEN_NAME 25
#define ZEROEXPORT_GROUP_MAX_LEN_PM_URL 100 #define ZEROEXPORT_GROUP_MAX_LEN_PM_URL 100

2
src/defines.h

@ -13,7 +13,7 @@
//------------------------------------- //-------------------------------------
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 8 #define VERSION_MINOR 8
#define VERSION_PATCH 1030001 #define VERSION_PATCH 1030002
//------------------------------------- //-------------------------------------
typedef struct { typedef struct {
uint8_t ch; uint8_t ch;

167
src/plugins/zeroExport/zeroExport.h

@ -428,83 +428,64 @@ class ZeroExport {
mLog["t"] = "onMqttMessage"; mLog["t"] = "onMqttMessage";
if (obj["path"] == "zero" && obj["cmd"] == "set") { if (obj["path"] == "zero" && obj["cmd"] == "set") {
/* int8_t topicGroup = getGroupFromTopic(topic.c_str());
// "topic":"???/zero/set/enabled" int8_t topicInverter = getInverterFromTopic(topic.c_str());
if (topic.indexOf("zero/set/enabled") != -1) {
if((topicGroup == -1) && (topicInverter == -1)) {
} // "topic":"???/zero/set/enabled"
else if (topic.indexOf("zero/set/enabled") != -1) {
// "topic":"???/zero/set/sleep" mCfg->enabled = (bool)obj["val"];
if (topic.indexOf("zero/set/sleep") != -1) { mLog["mCfg->enabled"] = mCfg->enabled;
// Initialize groups
} for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) {
else mCfg->groups[group].state = zeroExportState::INIT;
// "topic":"???/zero/set/groups/0/enabled" mCfg->groups[group].wait = 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;
if (topic.indexOf("enabled") != -1) {
} }
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;
} }
} }
*/ else
// "topic":"inverter/zero/set/groups/0/enabled" if((topicGroup != -1) && (topicInverter == -1)) {
if (topic.indexOf("groups") != -1) { uint8_t group = topicGroup;
// TODO: Topicprüfung // "topic":"???/zero/set/groups/0/???"
// TODO: Topicprüfung ist 10 und 8 korrekt? // if (topic.indexOf("zero/set/groups/") != -1) {
// 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);
String i = topic.substring(topic.length() - 10, topic.length() - 8); // uint8_t group = i.toInt();
uint8_t group = i.toInt(); mLog["g"] = group;
mLog["g"] = group; // "topic":"???/zero/set/groups/0/enabled"
if (topic.indexOf("enabled") != -1) {
mCfg->groups[group].enabled = (bool)obj["val"]; mCfg->groups[group].enabled = (bool)obj["val"];
// Initialize group
// Initialize group mCfg->groups[group].state = zeroExportState::INIT;
mCfg->groups[group].state = zeroExportState::INIT; mCfg->groups[group].wait = 0;
mCfg->groups[group].sleep = 0; }
} else { // "topic":"???/zero/set/groups/0/sleep"
// TODO: Topicprüfung if (topic.indexOf("sleep") != -1) {
mCfg->enabled = (bool)obj["val"]; mCfg->groups[group].sleep = (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
// Battery // Battery
/// - enabled
/// - voltageOn
/// - voltageOff
// - switch // - switch
// Advanced // Advanced
// - setpoint // - setpoint
/// - refresh
// - powerTolerance // - powerTolerance
// - powerMax // - powerMax
/// - Kp }
/// - Ki else
/// - Kd if((topicGroup != -1) && (topicInverter != -1)) {
// Inverter
// - enabled
// - powerMin
// - powerMax
}
}
mLog["Msg"] = obj; mLog["Msg"] = obj;
sendLog(); sendLog();
@ -523,6 +504,30 @@ 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));
} }
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 /** groupInit
* Initialize the group and search the InverterPointer * Initialize the group and search the InverterPointer
* @param group * @param group
@ -1428,16 +1433,36 @@ class ZeroExport {
mMqtt->subscribe(gr.c_str(), QOS_2); mMqtt->subscribe(gr.c_str(), QOS_2);
// Powermeter // Powermeter
// TODO: fehlt
// Inverters // 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 // 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 // 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) // Global (zeroExport)

Loading…
Cancel
Save