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

This commit is contained in:
lumapu 2022-08-25 09:59:21 +02:00
parent 8bf539aea4
commit 3212aeb142

View file

@ -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();
}
} }
} }
} }
@ -968,4 +970,4 @@ void app::resetPayload(Inverter<>* iv)
mPayload[iv->id].complete = false; mPayload[iv->id].complete = false;
mPayload[iv->id].requested = true; mPayload[iv->id].requested = true;
mPayload[iv->id].ts = mTimestamp; mPayload[iv->id].ts = mTimestamp;
} }