mirror of
https://github.com/lumapu/ahoy.git
synced 2025-06-10 06:31:39 +02:00
0.8.1030009
This commit is contained in:
parent
06b34b16c4
commit
3375d3c8a9
5 changed files with 82 additions and 53 deletions
|
@ -204,7 +204,7 @@ typedef struct {
|
||||||
#if defined(PLUGIN_ZEROEXPORT)
|
#if defined(PLUGIN_ZEROEXPORT)
|
||||||
|
|
||||||
#define ZEROEXPORT_MAX_QUEUE_ENTRIES 64
|
#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_NAME 25
|
||||||
#define ZEROEXPORT_GROUP_MAX_LEN_PM_URL 100
|
#define ZEROEXPORT_GROUP_MAX_LEN_PM_URL 100
|
||||||
#define ZEROEXPORT_GROUP_MAX_LEN_PM_JSONPATH 100
|
#define ZEROEXPORT_GROUP_MAX_LEN_PM_JSONPATH 100
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 8
|
#define VERSION_MINOR 8
|
||||||
#define VERSION_PATCH 1030008
|
#define VERSION_PATCH 1030009
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t ch;
|
uint8_t ch;
|
||||||
|
|
|
@ -88,7 +88,8 @@ class powermeter {
|
||||||
#endif
|
#endif
|
||||||
#if defined(ZEROEXPORT_POWERMETER_MQTT)
|
#if defined(ZEROEXPORT_POWERMETER_MQTT)
|
||||||
case zeroExportPowermeterType_t::Mqtt:
|
case zeroExportPowermeterType_t::Mqtt:
|
||||||
power = getPowermeterWattsMqtt(*mLog, group);
|
/// power = getPowermeterWattsMqtt(*mLog, group);
|
||||||
|
continue;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(ZEROEXPORT_POWERMETER_HICHI)
|
#if defined(ZEROEXPORT_POWERMETER_HICHI)
|
||||||
|
@ -114,16 +115,18 @@ class powermeter {
|
||||||
bufferWrite(power, group);
|
bufferWrite(power, group);
|
||||||
|
|
||||||
// MQTT - Powermeter
|
// MQTT - Powermeter
|
||||||
if (mMqtt->isConnected()) {
|
if (mCfg->debug) {
|
||||||
// P
|
if (mMqtt->isConnected()) {
|
||||||
mqttObj["Sum"] = ah::round1(power.P);
|
// P
|
||||||
mqttObj["L1"] = ah::round1(power.P1);
|
mqttObj["Sum"] = ah::round1(power.P);
|
||||||
mqttObj["L2"] = ah::round1(power.P2);
|
mqttObj["L1"] = ah::round1(power.P1);
|
||||||
mqttObj["L3"] = ah::round1(power.P3);
|
mqttObj["L2"] = ah::round1(power.P2);
|
||||||
mMqtt->publish(String("zero/state/groups/" + String(group) + "/powermeter/P").c_str(), mqttDoc.as<std::string>().c_str(), false);
|
mqttObj["L3"] = ah::round1(power.P3);
|
||||||
mqttDoc.clear();
|
mMqtt->publish(String("zero/state/groups/" + String(group) + "/powermeter/P").c_str(), mqttDoc.as<std::string>().c_str(), false);
|
||||||
|
mqttDoc.clear();
|
||||||
|
|
||||||
// W (TODO)
|
// W (TODO)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,10 +162,13 @@ class powermeter {
|
||||||
#if defined(ZEROEXPORT_POWERMETER_MQTT)
|
#if defined(ZEROEXPORT_POWERMETER_MQTT)
|
||||||
|
|
||||||
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) {
|
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) {
|
||||||
if (mCfg->groups[group].pm_type == zeroExportPowermeterType_t::Mqtt) {
|
if (!strcmp(mCfg->groups[group].pm_jsonPath, "")) continue;
|
||||||
// if (String(mCfg->groups[group].pm_jsonPath) == "") return;
|
|
||||||
|
|
||||||
mMqtt->subscribe(String(mCfg->groups[group].pm_jsonPath).c_str(), QOS_2);
|
if (!mCfg->groups[group].enabled) continue;
|
||||||
|
|
||||||
|
if (mCfg->groups[group].pm_type == zeroExportPowermeterType_t::Mqtt) {
|
||||||
|
|
||||||
|
mMqtt->subscribeExtern(String(mCfg->groups[group].pm_jsonPath).c_str(), QOS_2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,26 +435,26 @@ class powermeter {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ZEROEXPORT_POWERMETER_MQTT)
|
///#if defined(ZEROEXPORT_POWERMETER_MQTT)
|
||||||
/** getPowermeterWattsMqtt
|
/// /** getPowermeterWattsMqtt
|
||||||
* ...
|
/// * ...
|
||||||
* @param logObj
|
/// * @param logObj
|
||||||
* @param group
|
/// * @param group
|
||||||
* @returns true/false
|
/// * @returns true/false
|
||||||
*/
|
/// */
|
||||||
PowermeterBuffer_t getPowermeterWattsMqtt(JsonObject logObj, uint8_t group) {
|
/// PowermeterBuffer_t getPowermeterWattsMqtt(JsonObject logObj, uint8_t group) {
|
||||||
PowermeterBuffer_t result;
|
/// PowermeterBuffer_t result;
|
||||||
result.P = result.P1 = result.P2 = result.P3 = 0;
|
/// result.P = result.P1 = result.P2 = result.P3 = 0;
|
||||||
|
///
|
||||||
logObj["mod"] = "getPowermeterWattsMqtt";
|
/// logObj["mod"] = "getPowermeterWattsMqtt";
|
||||||
|
///
|
||||||
// topic for powermeter?
|
/// // topic for powermeter?
|
||||||
result.P = mCfg->groups[group].pm_P;
|
/// result.P = mCfg->groups[group].pm_P;
|
||||||
result.P1 = result.P2 = result.P3 = mCfg->groups[group].pm_P / 3;
|
/// result.P1 = result.P2 = result.P3 = mCfg->groups[group].pm_P / 3;
|
||||||
|
///
|
||||||
return result;
|
/// return result;
|
||||||
}
|
/// }
|
||||||
#endif
|
///#endif
|
||||||
|
|
||||||
#if defined(ZEROEXPORT_POWERMETER_HICHI)
|
#if defined(ZEROEXPORT_POWERMETER_HICHI)
|
||||||
/** getPowermeterWattsHichi
|
/** getPowermeterWattsHichi
|
||||||
|
|
|
@ -597,12 +597,16 @@ if ((delta > 10) && (CfgGroupInv->power > 0)) {
|
||||||
* @returns void
|
* @returns void
|
||||||
*/
|
*/
|
||||||
void onMqttConnect(void) {
|
void onMqttConnect(void) {
|
||||||
|
if (!mCfg->enabled) return;
|
||||||
|
|
||||||
mPowermeter.onMqttConnect();
|
mPowermeter.onMqttConnect();
|
||||||
|
|
||||||
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) {
|
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) {
|
||||||
// if (String(mCfg->groups[group].battSoC) == "") return;
|
if (!mCfg->groups [group].enabled) continue;
|
||||||
|
|
||||||
mMqtt->subscribe(String(mCfg->groups[group].battSoC).c_str(), QOS_2);
|
if(!strcmp(mCfg->groups[group].battSoC, "")) continue;
|
||||||
|
|
||||||
|
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) {
|
void onMqttMessage(JsonObject obj) {
|
||||||
if (!mIsInitialized) return;
|
if (!mIsInitialized) return;
|
||||||
|
|
||||||
if (mCfg->debug) mLog["d"] = obj;
|
|
||||||
sendLog();
|
|
||||||
clearLog();
|
|
||||||
mPowermeter.onMqttMessage(obj);
|
mPowermeter.onMqttMessage(obj);
|
||||||
|
|
||||||
String topic = String(obj["topic"]);
|
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 (topic.indexOf("ctrl/zero") == -1) return;
|
||||||
|
|
||||||
if (mCfg->debug) mLog["d"] = obj;
|
if (mCfg->debug) mLog["d"] = obj;
|
||||||
|
@ -661,19 +670,27 @@ if ((delta > 10) && (CfgGroupInv->power > 0)) {
|
||||||
mLog["v"] = mCfg->groups[topicGroup].sleep;
|
mLog["v"] = mCfg->groups[topicGroup].sleep;
|
||||||
}
|
}
|
||||||
|
|
||||||
// "topic":"ctrl/zero/groups/+/pm_ip"
|
// Auf Eis gelegt, dafür 2 Gruppen mehr
|
||||||
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/pm_ip") != -1) {
|
// 0.8.103008.2
|
||||||
// snprintf(mCfg->groups[topicGroup].pm_url, ZEROEXPORT_GROUP_MAX_LEN_PM_URL, "%s", obj[F("val")].as<const char *>());
|
// // "topic":"ctrl/zero/groups/+/pm_ip"
|
||||||
// mLog["g_powermeter_pm_ip"] = mCfg->groups[topicGroup].pm_url;
|
// if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/pm_ip") != -1) {
|
||||||
// snprintf(mCfg->groups[5].pm_url, ZEROEXPORT_GROUP_MAX_LEN_PM_URL, "%s", obj[F("val")].as<const char *>());
|
// 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[5].pm_url;
|
/// 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);
|
||||||
// "topic":"ctrl/zero/groups/+/pm_jsonPath"
|
// strncpy(mCfg->groups[topicGroup].pm_url, String(obj[F("val")]).c_str(), ZEROEXPORT_GROUP_MAX_LEN_PM_URL);
|
||||||
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/pm_jsonPath") != -1) {
|
// snprintf(mCfg->groups[topicGroup].pm_url, ZEROEXPORT_GROUP_MAX_LEN_PM_URL, "%s", String(obj[F("val")]).c_str());
|
||||||
// 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_ip";
|
||||||
// mLog["g_powermeter_pm_jsonPath"] = mCfg->groups[topicGroup].pm_jsonPath;
|
// 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"
|
// "topic":"ctrl/zero/groups/+/battery/switch"
|
||||||
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/battery/switch") != -1) {
|
if (topic.indexOf("ctrl/zero/groups/" + String(topicGroup) + "/battery/switch") != -1) {
|
||||||
|
|
|
@ -217,6 +217,12 @@ class PubMqtt {
|
||||||
mClient.subscribe(topic, qos);
|
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) {
|
void setConnectionCb(connectionCb cb) {
|
||||||
mConnectionCb = cb;
|
mConnectionCb = cb;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue