mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-19 16:29:31 +00:00
Remove MQTT JSON for all but NRF52_USE_JSON target
This commit is contained in:
parent
6d8be13266
commit
bb1b05d18a
@ -19,8 +19,11 @@
|
|||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
#include "Default.h"
|
#include "Default.h"
|
||||||
|
|
||||||
|
#if NRF52_USE_JSON
|
||||||
#include "serialization/JSON.h"
|
#include "serialization/JSON.h"
|
||||||
#include "serialization/MeshPacketSerializer.h"
|
#include "serialization/MeshPacketSerializer.h"
|
||||||
|
#endif
|
||||||
#include <Throttle.h>
|
#include <Throttle.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
@ -52,6 +55,7 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length)
|
|||||||
meshtastic_ServiceEnvelope e = meshtastic_ServiceEnvelope_init_default;
|
meshtastic_ServiceEnvelope e = meshtastic_ServiceEnvelope_init_default;
|
||||||
|
|
||||||
if (moduleConfig.mqtt.json_enabled && (strncmp(topic, jsonTopic.c_str(), jsonTopic.length()) == 0)) {
|
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
|
// check if this is a json payload message by comparing the topic start
|
||||||
char payloadStr[length + 1];
|
char payloadStr[length + 1];
|
||||||
memcpy(payloadStr, payload, length);
|
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");
|
LOG_ERROR("JSON received payload on MQTT but not a valid JSON");
|
||||||
}
|
}
|
||||||
delete json_value;
|
delete json_value;
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
LOG_WARN("Empty MQTT payload received, topic %s!", topic);
|
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) {
|
if (*moduleConfig.mqtt.root) {
|
||||||
cryptTopic = moduleConfig.mqtt.root + cryptTopic;
|
cryptTopic = moduleConfig.mqtt.root + cryptTopic;
|
||||||
|
#if NRF52_USE_JSON
|
||||||
jsonTopic = moduleConfig.mqtt.root + jsonTopic;
|
jsonTopic = moduleConfig.mqtt.root + jsonTopic;
|
||||||
|
#endif
|
||||||
mapTopic = moduleConfig.mqtt.root + mapTopic;
|
mapTopic = moduleConfig.mqtt.root + mapTopic;
|
||||||
} else {
|
} else {
|
||||||
cryptTopic = "msh" + cryptTopic;
|
cryptTopic = "msh" + cryptTopic;
|
||||||
|
#if NRF52_USE_JSON
|
||||||
jsonTopic = "msh" + jsonTopic;
|
jsonTopic = "msh" + jsonTopic;
|
||||||
|
#endif
|
||||||
mapTopic = "msh" + mapTopic;
|
mapTopic = "msh" + mapTopic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -705,6 +714,7 @@ void MQTT::perhapsReportToMap()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NRF52_USE_JSON
|
||||||
bool MQTT::isValidJsonEnvelope(JSONObject &json)
|
bool MQTT::isValidJsonEnvelope(JSONObject &json)
|
||||||
{
|
{
|
||||||
// if "sender" is provided, avoid processing packets we uplinked
|
// 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("type") != json.end()) && json["type"]->IsString() && // should specify a type
|
||||||
(json.find("payload") != json.end()); // should have a payload
|
(json.find("payload") != json.end()); // should have a payload
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool MQTT::isPrivateIpAddress(const char address[])
|
bool MQTT::isPrivateIpAddress(const char address[])
|
||||||
{
|
{
|
||||||
@ -780,4 +791,4 @@ bool MQTT::isPrivateIpAddress(const char address[])
|
|||||||
|
|
||||||
int octet2Num = atoi(octet2);
|
int octet2Num = atoi(octet2);
|
||||||
return octet2Num >= 16 && octet2Num <= 31;
|
return octet2Num >= 16 && octet2Num <= 31;
|
||||||
}
|
}
|
@ -5,7 +5,9 @@
|
|||||||
#include "concurrency/OSThread.h"
|
#include "concurrency/OSThread.h"
|
||||||
#include "mesh/Channels.h"
|
#include "mesh/Channels.h"
|
||||||
#include "mesh/generated/meshtastic/mqtt.pb.h"
|
#include "mesh/generated/meshtastic/mqtt.pb.h"
|
||||||
|
#if NRF52_USE_JSON
|
||||||
#include "serialization/JSON.h"
|
#include "serialization/JSON.h"
|
||||||
|
#endif
|
||||||
#if HAS_WIFI
|
#if HAS_WIFI
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#if !defined(ARCH_PORTDUINO)
|
#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
|
// Check if we should report unencrypted information about our node for consumption by a map
|
||||||
void perhapsReportToMap();
|
void perhapsReportToMap();
|
||||||
|
|
||||||
|
#if NRF52_USE_JSON
|
||||||
// returns true if this is a valid JSON envelope which we accept on downlink
|
// returns true if this is a valid JSON envelope which we accept on downlink
|
||||||
bool isValidJsonEnvelope(JSONObject &json);
|
bool isValidJsonEnvelope(JSONObject &json);
|
||||||
|
#endif
|
||||||
/// Determines if the given address is a private IPv4 address, i.e. not routable on the public internet.
|
/// 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.
|
/// 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[]);
|
bool isPrivateIpAddress(const char address[]);
|
||||||
@ -130,4 +133,4 @@ class MQTT : private concurrency::OSThread
|
|||||||
|
|
||||||
void mqttInit();
|
void mqttInit();
|
||||||
|
|
||||||
extern MQTT *mqtt;
|
extern MQTT *mqtt;
|
Loading…
Reference in New Issue
Block a user