diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 967db04d61..c8db6cf9c2 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -19,8 +19,11 @@ #include #endif #include "Default.h" + +#if NRF52_USE_JSON #include "serialization/JSON.h" #include "serialization/MeshPacketSerializer.h" +#endif #include #include @@ -52,6 +55,7 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length) meshtastic_ServiceEnvelope e = meshtastic_ServiceEnvelope_init_default; if (moduleConfig.mqtt.json_enabled && (strncmp(topic, jsonTopic.c_str(), jsonTopic.length()) == 0)) { +#if NRF52_USE_JSON // check if this is a json payload message by comparing the topic start char payloadStr[length + 1]; memcpy(payloadStr, payload, length); @@ -135,6 +139,7 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length) LOG_ERROR("JSON received payload on MQTT but not a valid JSON"); } delete json_value; +#endif } else { if (length == 0) { LOG_WARN("Empty MQTT payload received, topic %s!", topic); @@ -234,11 +239,15 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE) if (*moduleConfig.mqtt.root) { cryptTopic = moduleConfig.mqtt.root + cryptTopic; +#if NRF52_USE_JSON jsonTopic = moduleConfig.mqtt.root + jsonTopic; +#endif mapTopic = moduleConfig.mqtt.root + mapTopic; } else { cryptTopic = "msh" + cryptTopic; +#if NRF52_USE_JSON jsonTopic = "msh" + jsonTopic; +#endif mapTopic = "msh" + mapTopic; } @@ -705,6 +714,7 @@ void MQTT::perhapsReportToMap() } } +#if NRF52_USE_JSON bool MQTT::isValidJsonEnvelope(JSONObject &json) { // if "sender" is provided, avoid processing packets we uplinked @@ -715,6 +725,7 @@ bool MQTT::isValidJsonEnvelope(JSONObject &json) (json.find("type") != json.end()) && json["type"]->IsString() && // should specify a type (json.find("payload") != json.end()); // should have a payload } +#endif bool MQTT::isPrivateIpAddress(const char address[]) { @@ -780,4 +791,4 @@ bool MQTT::isPrivateIpAddress(const char address[]) int octet2Num = atoi(octet2); return octet2Num >= 16 && octet2Num <= 31; -} +} \ No newline at end of file diff --git a/src/mqtt/MQTT.h b/src/mqtt/MQTT.h index 7e0378238d..10cac467a0 100644 --- a/src/mqtt/MQTT.h +++ b/src/mqtt/MQTT.h @@ -5,7 +5,9 @@ #include "concurrency/OSThread.h" #include "mesh/Channels.h" #include "mesh/generated/meshtastic/mqtt.pb.h" +#if NRF52_USE_JSON #include "serialization/JSON.h" +#endif #if HAS_WIFI #include #if !defined(ARCH_PORTDUINO) @@ -117,9 +119,10 @@ class MQTT : private concurrency::OSThread // Check if we should report unencrypted information about our node for consumption by a map void perhapsReportToMap(); +#if NRF52_USE_JSON // returns true if this is a valid JSON envelope which we accept on downlink bool isValidJsonEnvelope(JSONObject &json); - +#endif /// Determines if the given address is a private IPv4 address, i.e. not routable on the public internet. /// These are the ranges: 127.0.0.1, 10.0.0.0-10.255.255.255, 172.16.0.0-172.31.255.255, 192.168.0.0-192.168.255.255. bool isPrivateIpAddress(const char address[]); @@ -130,4 +133,4 @@ class MQTT : private concurrency::OSThread void mqttInit(); -extern MQTT *mqtt; +extern MQTT *mqtt; \ No newline at end of file