Skip to content

Commit

Permalink
Merge branch 'geronet1-development03' into development03
Browse files Browse the repository at this point in the history
  • Loading branch information
lumapu committed Oct 7, 2024
2 parents 3afc165 + e1a4741 commit ed28c29
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/publisher/pubMqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class PubMqtt {
doc[F("mdl")] = node_id;
}

doc[F("cu")] = F("http://") + String(WiFi.localIP().toString());
doc[F("cu")] = F("http://") + mApp->getIp();
doc[F("mf")] = F("Hoymiles");
JsonObject deviceObj = doc.as<JsonObject>(); // deviceObj is only pointer!?

Expand All @@ -449,13 +449,15 @@ class PubMqtt {
snprintf(name.data(), name.size(), "%s", iv->getFieldName(mDiscovery.sub, rec));
else
snprintf(name.data(), name.size(), "CH%d_%s", rec->assign[mDiscovery.sub].ch, iv->getFieldName(mDiscovery.sub, rec));
snprintf(topic.data(), name.size(), "/ch%d/%s", rec->assign[mDiscovery.sub].ch, iv->getFieldName(mDiscovery.sub, rec));
if (!mCfgMqtt->json)
snprintf(topic.data(), name.size(), "/ch%d/%s", rec->assign[mDiscovery.sub].ch, iv->getFieldName(mDiscovery.sub, rec));
else
snprintf(topic.data(), name.size(), "/ch%d", rec->assign[mDiscovery.sub].ch);
snprintf(uniq_id.data(), uniq_id.size(), "ch%d_%s", rec->assign[mDiscovery.sub].ch, iv->getFieldName(mDiscovery.sub, rec));

devCls = getFieldDeviceClass(rec->assign[mDiscovery.sub].fieldId);
stateCls = getFieldStateClass(rec->assign[mDiscovery.sub].fieldId);
}

else { // total values
snprintf(name.data(), name.size(), "Total %s", fields[fldTotal[mDiscovery.sub]]);
snprintf(topic.data(), topic.size(), "/%s", fields[fldTotal[mDiscovery.sub]]);
Expand All @@ -467,7 +469,20 @@ class PubMqtt {
DynamicJsonDocument doc2(512);
constexpr static const char* unitTotal[] = {"W", "kWh", "Wh", "W"};
doc2[F("name")] = String(name.data());
doc2[F("stat_t")] = String(mCfgMqtt->topic) + "/" + ((!total) ? String(iv->config->name) : "total" ) + String(topic.data());

if (mCfgMqtt->json) {
if (total) {
doc2[F("val_tpl")] = String("{{ value_json.") + fields[fldTotal[mDiscovery.sub]] + String(" }}");
doc2[F("stat_t")] = String(mCfgMqtt->topic) + "/" + "total";
}
else {
doc2[F("val_tpl")] = String("{{ value_json.") + iv->getFieldName(mDiscovery.sub, rec) + String(" }}");
doc2[F("stat_t")] = String(mCfgMqtt->topic) + "/" + String(iv->config->name) + String(topic.data());
}
}
else {
doc2[F("stat_t")] = String(mCfgMqtt->topic) + "/" + ((!total) ? String(iv->config->name) : "total" ) + String(topic.data());
}
doc2[F("unit_of_meas")] = ((!total) ? (iv->getUnit(mDiscovery.sub, rec)) : (unitTotal[mDiscovery.sub]));
doc2[F("uniq_id")] = ((!total) ? (String(iv->config->serial.u64, HEX)) : (node_id)) + "_" + uniq_id.data();
doc2[F("dev")] = deviceObj;
Expand Down

0 comments on commit ed28c29

Please sign in to comment.