Browse Source

fix mqtt json output

pull/1541/head
geronet1 10 months ago
parent
commit
d373fbb49d
  1. 26
      src/publisher/pubMqttIvData.h

26
src/publisher/pubMqttIvData.h

@ -212,24 +212,28 @@ class PubMqttIvData {
mPos++; mPos++;
} else { } else {
if (MqttSentStatus::LAST_SUCCESS_SENT == rec->mqttSentStatus) { if (MqttSentStatus::LAST_SUCCESS_SENT == rec->mqttSentStatus) {
if (mJson) { if (mJson && RealTimeRunData_Debug == mCmd) {
DynamicJsonDocument doc(300); DynamicJsonDocument doc(300);
std::array<char, 300> buf; std::array<char, 300> buf;
int ch = rec->assign[0].ch;
for (mPos = 0; mPos <= rec->length; mPos++) { for (mPos = 0; mPos < rec->length; mPos++) {
if (rec->assign[mPos].ch != ch) { doc[fields[rec->assign[mPos].fieldId]] = ah::round3(mIv->getValue(mPos, rec));
// if next channel.. publish
bool publish = false;
if (mPos != rec->length - 1) { // not last one
if (rec->assign[mPos].ch != rec->assign[mPos+1].ch)
publish = true;
} else
publish = true;
if (publish) {
publish = false;
// if next channel or end->publish
serializeJson(doc, buf.data(), buf.size()); serializeJson(doc, buf.data(), buf.size());
doc.clear(); doc.clear();
snprintf(mSubTopic.data(), mSubTopic.size(), "%s/ch%d", mIv->config->name, ch); snprintf(mSubTopic.data(), mSubTopic.size(), "%s/ch%d", mIv->config->name, rec->assign[mPos].ch);
mPublish(mSubTopic.data(), buf.data(), false, QOS_0); mPublish(mSubTopic.data(), buf.data(), false, QOS_0);
ch = rec->assign[mPos].ch;
} }
if (mPos == rec->length)
break;
doc[fields[rec->assign[mPos].fieldId]] = ah::round3(mIv->getValue(mPos, rec));
} }
} }

Loading…
Cancel
Save