Browse Source

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

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

28
tools/esp8266/app.cpp

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

Loading…
Cancel
Save