Browse Source

0.8.1030009

pull/1615/head
Patrick Amrhein 9 months ago
parent
commit
3375d3c8a9
  1. 2
      src/config/settings.h
  2. 2
      src/defines.h
  3. 72
      src/plugins/zeroExport/powermeter.h
  4. 53
      src/plugins/zeroExport/zeroExport.h
  5. 6
      src/publisher/pubMqtt.h

2
src/config/settings.h

@ -204,7 +204,7 @@ typedef struct {
#if defined(PLUGIN_ZEROEXPORT)
#define ZEROEXPORT_MAX_QUEUE_ENTRIES 64
#define ZEROEXPORT_MAX_GROUPS 6
#define ZEROEXPORT_MAX_GROUPS 8
#define ZEROEXPORT_GROUP_MAX_LEN_NAME 25
#define ZEROEXPORT_GROUP_MAX_LEN_PM_URL 100
#define ZEROEXPORT_GROUP_MAX_LEN_PM_JSONPATH 100

2
src/defines.h

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

72
src/plugins/zeroExport/powermeter.h

@ -88,7 +88,8 @@ class powermeter {
#endif
#if defined(ZEROEXPORT_POWERMETER_MQTT)
case zeroExportPowermeterType_t::Mqtt:
power = getPowermeterWattsMqtt(*mLog, group);
/// power = getPowermeterWattsMqtt(*mLog, group);
continue;
break;
#endif
#if defined(ZEROEXPORT_POWERMETER_HICHI)
@ -114,16 +115,18 @@ class powermeter {
bufferWrite(power, group);
// MQTT - Powermeter
if (mMqtt->isConnected()) {
// P
mqttObj["Sum"] = ah::round1(power.P);
mqttObj["L1"] = ah::round1(power.P1);
mqttObj["L2"] = ah::round1(power.P2);
mqttObj["L3"] = ah::round1(power.P3);
mMqtt->publish(String("zero/state/groups/" + String(group) + "/powermeter/P").c_str(), mqttDoc.as<std::string>().c_str(), false);
mqttDoc.clear();
// W (TODO)
if (mCfg->debug) {
if (mMqtt->isConnected()) {
// P
mqttObj["Sum"] = ah::round1(power.P);
mqttObj["L1"] = ah::round1(power.P1);
mqttObj["L2"] = ah::round1(power.P2);
mqttObj["L3"] = ah::round1(power.P3);
mMqtt->publish(String("zero/state/groups/" + String(group) + "/powermeter/P").c_str(), mqttDoc.as<std::string>().c_str(), false);
mqttDoc.clear();
// W (TODO)
}
}
}
}
@ -159,10 +162,13 @@ class powermeter {
#if defined(ZEROEXPORT_POWERMETER_MQTT)
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) {
if (!strcmp(mCfg->groups[group].pm_jsonPath, "")) continue;
if (!mCfg->groups[group].enabled) continue;
if (mCfg->groups[group].pm_type == zeroExportPowermeterType_t::Mqtt) {
// if (String(mCfg->groups[group].pm_jsonPath) == "") return;
mMqtt->subscribe(String(mCfg->groups[group].pm_jsonPath).c_str(), QOS_2);
mMqtt->subscribeExtern(String(mCfg->groups[group].pm_jsonPath).c_str(), QOS_2);
}
}
@ -429,26 +435,26 @@ class powermeter {
}
#endif
#if defined(ZEROEXPORT_POWERMETER_MQTT)
/** getPowermeterWattsMqtt
* ...
* @param logObj
* @param group
* @returns true/false
*/
PowermeterBuffer_t getPowermeterWattsMqtt(JsonObject logObj, uint8_t group) {
PowermeterBuffer_t result;
result.P = result.P1 = result.P2 = result.P3 = 0;
logObj["mod"] = "getPowermeterWattsMqtt";
// topic for powermeter?
result.P = mCfg->groups[group].pm_P;
result.P1 = result.P2 = result.P3 = mCfg->groups[group].pm_P / 3;
return result;
}
#endif
///#if defined(ZEROEXPORT_POWERMETER_MQTT)
/// /** getPowermeterWattsMqtt
/// * ...
/// * @param logObj
/// * @param group
/// * @returns true/false
/// */
/// PowermeterBuffer_t getPowermeterWattsMqtt(JsonObject logObj, uint8_t group) {
/// PowermeterBuffer_t result;
/// result.P = result.P1 = result.P2 = result.P3 = 0;
///
/// logObj["mod"] = "getPowermeterWattsMqtt";
///
/// // topic for powermeter?
/// result.P = mCfg->groups[group].pm_P;
/// result.P1 = result.P2 = result.P3 = mCfg->groups[group].pm_P / 3;
///
/// return result;
/// }
///#endif
#if defined(ZEROEXPORT_POWERMETER_HICHI)
/** getPowermeterWattsHichi

53
src/plugins/zeroExport/zeroExport.h

@ -597,12 +597,16 @@ if ((delta > 10) && (CfgGroupInv->power > 0)) {
* @returns void
*/
void onMqttConnect(void) {
if (!mCfg->enabled) return;
mPowermeter.onMqttConnect();
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) {
// if (String(mCfg->groups[group].battSoC) == "") return;
if (!mCfg->groups [group].enabled) continue;
if(!strcmp(mCfg->groups[group].battSoC, "")) continue;
mMqtt->subscribe(String(mCfg->groups[group].battSoC).c_str(), QOS_2);
mMqtt->subscribeExtern(String(mCfg->groups[group].battSoC).c_str(), QOS_2);
}
}
@ -614,12 +618,17 @@ if ((delta > 10) && (CfgGroupInv->power > 0)) {
void onMqttMessage(JsonObject obj) {
if (!mIsInitialized) return;
if (mCfg->debug) mLog["d"] = obj;
sendLog();
clearLog();
mPowermeter.onMqttMessage(obj);
String topic = String(obj["topic"]);
/// TODO: Receive Message für SoC
// if ((topicGroup >= 0) && (topicGroup < ZEROEXPORT_MAX_GROUPS)) {
// if (topic.indexOf("xxx") != -1) {
// }
// }
if (topic.indexOf("ctrl/zero") == -1) return;
if (mCfg->debug) mLog["d"] = obj;
@ -661,19 +670,27 @@ if ((delta > 10) && (CfgGroupInv->power > 0)) {
mLog["v"] = mCfg->groups[topicGroup].sleep;
}
// "topic":"ctrl/zero/groups/+/pm_ip"
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/pm_ip") != -1) {
// snprintf(mCfg->groups[topicGroup].pm_url, ZEROEXPORT_GROUP_MAX_LEN_PM_URL, "%s", obj[F("val")].as<const char *>());
// mLog["g_powermeter_pm_ip"] = mCfg->groups[topicGroup].pm_url;
// snprintf(mCfg->groups[5].pm_url, ZEROEXPORT_GROUP_MAX_LEN_PM_URL, "%s", obj[F("val")].as<const char *>());
// mLog["g_powermeter_pm_ip"] = mCfg->groups[5].pm_url;
}
// "topic":"ctrl/zero/groups/+/pm_jsonPath"
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/pm_jsonPath") != -1) {
// snprintf(mCfg->groups[topicGroup].pm_jsonPath, ZEROEXPORT_GROUP_MAX_LEN_PM_JSONPATH, "%s", obj[F("val")].as<const char *>());
// mLog["g_powermeter_pm_jsonPath"] = mCfg->groups[topicGroup].pm_jsonPath;
}
// Auf Eis gelegt, dafür 2 Gruppen mehr
// 0.8.103008.2
// // "topic":"ctrl/zero/groups/+/pm_ip"
// if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/pm_ip") != -1) {
// snprintf(mCfg->groups[topicGroup].pm_url, ZEROEXPORT_GROUP_MAX_LEN_PM_URL, "%s", obj[F("val")].as<const char *>());
/// TODO:
// snprintf(mCfg->groups[topicGroup].pm_url, ZEROEXPORT_GROUP_MAX_LEN_PM_URL, "%s", obj[F("val")].as<const char *>());
// strncpy(mCfg->groups[topicGroup].pm_url, obj[F("val")], ZEROEXPORT_GROUP_MAX_LEN_PM_URL);
// strncpy(mCfg->groups[topicGroup].pm_url, String(obj[F("val")]).c_str(), ZEROEXPORT_GROUP_MAX_LEN_PM_URL);
// snprintf(mCfg->groups[topicGroup].pm_url, ZEROEXPORT_GROUP_MAX_LEN_PM_URL, "%s", String(obj[F("val")]).c_str());
// mLog["k"] = "ctrl/zero/groups/" + String(topicGroup) + "/pm_ip";
// mLog["v"] = mCfg->groups[topicGroup].pm_url;
// }
//
// // "topic":"ctrl/zero/groups/+/pm_jsonPath"
// if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/pm_jsonPath") != -1) {
/// TODO:
// snprintf(mCfg->groups[topicGroup].pm_jsonPath, ZEROEXPORT_GROUP_MAX_LEN_PM_JSONPATH, "%s", obj[F("val")].as<const char *>());
// mLog["k"] = "ctrl/zero/groups/" + String(topicGroup) + "/pm_jsonPath";
// mLog["v"] = mCfg->groups[topicGroup].pm_jsonPath;
// }
// "topic":"ctrl/zero/groups/+/battery/switch"
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/battery/switch") != -1) {

6
src/publisher/pubMqtt.h

@ -217,6 +217,12 @@ class PubMqtt {
mClient.subscribe(topic, qos);
}
void subscribeExtern(const char *subTopic, uint8_t qos = QOS_0) {
char topic[MQTT_TOPIC_LEN + 20];
snprintf(topic, (MQTT_TOPIC_LEN + 20), "%s", subTopic);
mClient.subscribe(topic, qos);
}
void setConnectionCb(connectionCb cb) {
mConnectionCb = cb;
}

Loading…
Cancel
Save