mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-06 21:55:54 +02:00
fix mqtt json output
This commit is contained in:
parent
6a5227bd0a
commit
d373fbb49d
1 changed files with 15 additions and 11 deletions
|
@ -212,24 +212,28 @@ class PubMqttIvData {
|
|||
mPos++;
|
||||
} else {
|
||||
if (MqttSentStatus::LAST_SUCCESS_SENT == rec->mqttSentStatus) {
|
||||
if (mJson) {
|
||||
if (mJson && RealTimeRunData_Debug == mCmd) {
|
||||
DynamicJsonDocument doc(300);
|
||||
std::array<char, 300> buf;
|
||||
int ch = rec->assign[0].ch;
|
||||
|
||||
for (mPos = 0; mPos <= rec->length; mPos++) {
|
||||
if (rec->assign[mPos].ch != ch) {
|
||||
// if next channel.. publish
|
||||
for (mPos = 0; mPos < rec->length; mPos++) {
|
||||
doc[fields[rec->assign[mPos].fieldId]] = ah::round3(mIv->getValue(mPos, rec));
|
||||
|
||||
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());
|
||||
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);
|
||||
ch = rec->assign[mPos].ch;
|
||||
}
|
||||
if (mPos == rec->length)
|
||||
break;
|
||||
|
||||
doc[fields[rec->assign[mPos].fieldId]] = ah::round3(mIv->getValue(mPos, rec));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue