Skip to content

Commit

Permalink
Remove 'else'; simpifies #5516
Browse files Browse the repository at this point in the history
  • Loading branch information
esev committed Dec 17, 2024
1 parent a3a077b commit 938d8fe
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/mqtt/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ inline void onReceiveProto(char *topic, byte *payload, size_t length)
LOG_ERROR("Invalid MQTT service envelope, topic %s, len %u!", topic, length);
return;
}
meshtastic_Channel ch = channels.getByName(e.channel_id);
const meshtastic_Channel &ch = channels.getByName(e.channel_id);
if (strcmp(e.gateway_id, owner.id) == 0) {
// Generate an implicit ACK towards ourselves (handled and processed only locally!) for this message.
// We do this because packets are not rebroadcasted back into MQTT anymore and we assume that at least one node
Expand All @@ -75,18 +75,18 @@ inline void onReceiveProto(char *topic, byte *payload, size_t length)
LOG_INFO("Ignore downlink message we originally sent");
return;
}
if (isFromUs(e.packet)) {
LOG_INFO("Ignore downlink message we originally sent");
return;
}

// Find channel by channel_id and check downlink_enabled
if (!(strcmp(e.channel_id, "PKI") == 0 ||
(strcmp(e.channel_id, channels.getGlobalId(ch.index)) == 0 && ch.settings.downlink_enabled))) {
return;
}
LOG_INFO("Received MQTT topic %s, len=%u", topic, length);

if (isFromUs(e.packet)) {
LOG_INFO("Ignore downlink message we originally sent");
return;
}

UniquePacketPoolPacket p = packetPool.allocUniqueCopy(*e.packet);
p->via_mqtt = true; // Mark that the packet was received via MQTT

Expand Down Expand Up @@ -217,6 +217,7 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length)
LOG_WARN("Empty MQTT payload received, topic %s!", topic);
return;
}

// check if this is a json payload message by comparing the topic start
if (moduleConfig.mqtt.json_enabled && (strncmp(topic, jsonTopic.c_str(), jsonTopic.length()) == 0)) {
// parse the channel name from the topic string
Expand All @@ -232,9 +233,10 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length)
return;
}
onReceiveJson(payload, length);
} else {
onReceiveProto(topic, payload, length);
return;
}

onReceiveProto(topic, payload, length);
}

void mqttInit()
Expand Down

0 comments on commit 938d8fe

Please sign in to comment.