mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-21 01:04:01 +00:00
Compare commits
No commits in common. "f39a9c5083e061e5919495df3814e058b13bd263" and "df63423cdcc5b41e8a7b900a21807817c7dc488f" have entirely different histories.
f39a9c5083
...
df63423cdc
@ -19,10 +19,8 @@
|
|||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
#include "Default.h"
|
#include "Default.h"
|
||||||
#if !defined(ARCH_NRF52) || 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>
|
||||||
#include <pb_decode.h>
|
#include <pb_decode.h>
|
||||||
@ -121,7 +119,6 @@ inline void onReceiveProto(char *topic, byte *payload, size_t length)
|
|||||||
router->enqueueReceivedMessage(p.release());
|
router->enqueueReceivedMessage(p.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(ARCH_NRF52) || 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
|
||||||
inline bool isValidJsonEnvelope(JSONObject &json)
|
inline bool isValidJsonEnvelope(JSONObject &json)
|
||||||
{
|
{
|
||||||
@ -207,7 +204,6 @@ inline void onReceiveJson(byte *payload, size_t length)
|
|||||||
LOG_DEBUG("JSON ignore downlink message with unsupported type");
|
LOG_DEBUG("JSON ignore downlink message with unsupported type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Determines if the given IPAddress is a private IPv4 address, i.e. not routable on the public internet.
|
/// Determines if the given IPAddress is a private IPv4 address, i.e. not routable on the public internet.
|
||||||
bool isPrivateIpAddress(const IPAddress &ip)
|
bool isPrivateIpAddress(const IPAddress &ip)
|
||||||
@ -231,16 +227,6 @@ bool isPrivateIpAddress(const IPAddress &ip)
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::string, uint16_t> parseHostAndPort(std::string address, uint16_t port = 0)
|
|
||||||
{
|
|
||||||
const size_t delimIndex = address.find_first_of(':');
|
|
||||||
if (delimIndex > 0) {
|
|
||||||
port = std::stoul(address.substr(delimIndex + 1, address.length()));
|
|
||||||
address.resize(delimIndex);
|
|
||||||
}
|
|
||||||
return std::make_pair(std::move(address), port);
|
|
||||||
}
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void MQTT::mqttCallback(char *topic, byte *payload, unsigned int length)
|
void MQTT::mqttCallback(char *topic, byte *payload, unsigned int length)
|
||||||
@ -262,7 +248,6 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length)
|
|||||||
|
|
||||||
// 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
|
||||||
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 !defined(ARCH_NRF52) || NRF52_USE_JSON
|
|
||||||
// parse the channel name from the topic string
|
// parse the channel name from the topic string
|
||||||
// the topic has been checked above for having jsonTopic prefix, so just move past it
|
// the topic has been checked above for having jsonTopic prefix, so just move past it
|
||||||
char *channelName = topic + jsonTopic.length();
|
char *channelName = topic + jsonTopic.length();
|
||||||
@ -276,7 +261,6 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onReceiveJson(payload, length);
|
onReceiveJson(payload, length);
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,8 +302,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
|
|||||||
}
|
}
|
||||||
|
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
isMqttServerAddressPrivate =
|
isMqttServerAddressPrivate = ip.fromString(moduleConfig.mqtt.address) && isPrivateIpAddress(ip);
|
||||||
ip.fromString(parseHostAndPort(moduleConfig.mqtt.address).first.c_str()) && isPrivateIpAddress(ip);
|
|
||||||
|
|
||||||
#if HAS_NETWORKING
|
#if HAS_NETWORKING
|
||||||
if (!moduleConfig.mqtt.proxy_to_client_enabled)
|
if (!moduleConfig.mqtt.proxy_to_client_enabled)
|
||||||
@ -435,9 +418,14 @@ void MQTT::reconnect()
|
|||||||
pubSub.setClient(mqttClient);
|
pubSub.setClient(mqttClient);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::pair<std::string, uint16_t> hostAndPort = parseHostAndPort(serverAddr, serverPort);
|
String server = String(serverAddr);
|
||||||
serverAddr = hostAndPort.first.c_str();
|
int delimIndex = server.indexOf(':');
|
||||||
serverPort = hostAndPort.second;
|
if (delimIndex > 0) {
|
||||||
|
String port = server.substring(delimIndex + 1, server.length());
|
||||||
|
server[delimIndex] = 0;
|
||||||
|
serverPort = port.toInt();
|
||||||
|
serverAddr = server.c_str();
|
||||||
|
}
|
||||||
pubSub.setServer(serverAddr, serverPort);
|
pubSub.setServer(serverAddr, serverPort);
|
||||||
pubSub.setBufferSize(512);
|
pubSub.setBufferSize(512);
|
||||||
|
|
||||||
@ -760,4 +748,4 @@ void MQTT::perhapsReportToMap()
|
|||||||
|
|
||||||
// Update the last report time
|
// Update the last report time
|
||||||
last_report_to_map = millis();
|
last_report_to_map = millis();
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,7 @@
|
|||||||
#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 !defined(ARCH_NRF52) || 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)
|
||||||
@ -129,4 +127,4 @@ class MQTT : private concurrency::OSThread
|
|||||||
|
|
||||||
void mqttInit();
|
void mqttInit();
|
||||||
|
|
||||||
extern MQTT *mqtt;
|
extern MQTT *mqtt;
|
||||||
|
Loading…
Reference in New Issue
Block a user