Browse Source

code review: added check if mqtt is enabled before sending out values

pull/202/head
lumapu 3 years ago
parent
commit
3212aeb142
  1. 26
      tools/esp8266/app.cpp

26
tools/esp8266/app.cpp

@ -376,21 +376,23 @@ void app::processPayload(bool retransmit) {
iv->setQueuedCmdFinished(); iv->setQueuedCmdFinished();
// send out // MQTT send out
char topic[30], val[10]; if(mMqttActive) {
for (uint8_t id = 0; id < mSys->getNumInverters(); id++) char topic[30], val[10];
{ for (uint8_t id = 0; id < mSys->getNumInverters(); id++)
Inverter<> *iv = mSys->getInverterByPos(id);
if (NULL != iv)
{ {
if (iv->isAvailable(mTimestamp)) Inverter<> *iv = mSys->getInverterByPos(id);
if (NULL != iv)
{ {
for (uint8_t i = 0; i < iv->listLen; i++) if (iv->isAvailable(mTimestamp))
{ {
snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]); for (uint8_t i = 0; i < iv->listLen; i++)
snprintf(val, 10, "%.3f", iv->getValue(i)); {
mMqtt.sendMsg(topic, val); snprintf(topic, 30, "%s/ch%d/%s", iv->name, iv->assign[i].ch, fields[iv->assign[i].fieldId]);
yield(); snprintf(val, 10, "%.3f", iv->getValue(i));
mMqtt.sendMsg(topic, val);
yield();
}
} }
} }
} }

Loading…
Cancel
Save