mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-14 06:42:34 +00:00
Merge branch 'develop' into multi-message-Storage
This commit is contained in:
@@ -51,6 +51,7 @@ constexpr int reconnectMax = 5;
|
|||||||
static uint8_t bytes[meshtastic_MqttClientProxyMessage_size + 30]; // 12 for channel name and 16 for nodeid
|
static uint8_t bytes[meshtastic_MqttClientProxyMessage_size + 30]; // 12 for channel name and 16 for nodeid
|
||||||
|
|
||||||
static bool isMqttServerAddressPrivate = false;
|
static bool isMqttServerAddressPrivate = false;
|
||||||
|
static bool isConnected = false;
|
||||||
|
|
||||||
inline void onReceiveProto(char *topic, byte *payload, size_t length)
|
inline void onReceiveProto(char *topic, byte *payload, size_t length)
|
||||||
{
|
{
|
||||||
@@ -320,8 +321,10 @@ bool connectPubSub(const PubSubConfig &config, PubSubClient &pubSub, Client &cli
|
|||||||
std::string nodeId = nodeDB->getNodeId();
|
std::string nodeId = nodeDB->getNodeId();
|
||||||
const bool connected = pubSub.connect(nodeId.c_str(), config.mqttUsername, config.mqttPassword);
|
const bool connected = pubSub.connect(nodeId.c_str(), config.mqttUsername, config.mqttPassword);
|
||||||
if (connected) {
|
if (connected) {
|
||||||
|
isConnected = true;
|
||||||
LOG_INFO("MQTT connected");
|
LOG_INFO("MQTT connected");
|
||||||
} else {
|
} else {
|
||||||
|
isConnected = false;
|
||||||
LOG_WARN("Failed to connect to MQTT server");
|
LOG_WARN("Failed to connect to MQTT server");
|
||||||
}
|
}
|
||||||
return connected;
|
return connected;
|
||||||
@@ -507,6 +510,7 @@ bool MQTT::publish(const char *topic, const uint8_t *payload, size_t length, boo
|
|||||||
|
|
||||||
void MQTT::reconnect()
|
void MQTT::reconnect()
|
||||||
{
|
{
|
||||||
|
isConnected = false;
|
||||||
if (wantsLink()) {
|
if (wantsLink()) {
|
||||||
if (moduleConfig.mqtt.proxy_to_client_enabled) {
|
if (moduleConfig.mqtt.proxy_to_client_enabled) {
|
||||||
LOG_INFO("MQTT connect via client proxy instead");
|
LOG_INFO("MQTT connect via client proxy instead");
|
||||||
@@ -534,7 +538,7 @@ void MQTT::reconnect()
|
|||||||
runASAP = true;
|
runASAP = true;
|
||||||
reconnectCount = 0;
|
reconnectCount = 0;
|
||||||
isMqttServerAddressPrivate = isPrivateIpAddress(clientConnection->remoteIP());
|
isMqttServerAddressPrivate = isPrivateIpAddress(clientConnection->remoteIP());
|
||||||
|
isConnected = true;
|
||||||
publishNodeInfo();
|
publishNodeInfo();
|
||||||
sendSubscriptions();
|
sendSubscriptions();
|
||||||
} else {
|
} else {
|
||||||
@@ -688,7 +692,7 @@ void MQTT::publishNodeInfo()
|
|||||||
}
|
}
|
||||||
void MQTT::publishQueuedMessages()
|
void MQTT::publishQueuedMessages()
|
||||||
{
|
{
|
||||||
if (mqttQueue.isEmpty())
|
if (mqttQueue.isEmpty() || !isConnected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LOG_DEBUG("Publish enqueued MQTT message");
|
LOG_DEBUG("Publish enqueued MQTT message");
|
||||||
@@ -895,4 +899,4 @@ void MQTT::perhapsReportToMap()
|
|||||||
|
|
||||||
// Update the last report time
|
// Update the last report time
|
||||||
last_report_to_map = millis();
|
last_report_to_map = millis();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user