Skip to content

Commit

Permalink
Start the mqtt thread back up when channels change and we want mqtt
Browse files Browse the repository at this point in the history
  • Loading branch information
thebentern committed Mar 15, 2024
1 parent c04f468 commit 21b09e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/mesh/Channels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <assert.h>

#include "mqtt/MQTT.h"

/// 16 bytes of random PSK for our _public_ default channel that all devices power up on (AES128)
static const uint8_t defaultpsk[] = {0xd4, 0xf1, 0xbb, 0x3a, 0x20, 0x29, 0x07, 0x59,
0xf0, 0xbc, 0xff, 0xab, 0xcf, 0x4e, 0x69, 0x01};
Expand Down Expand Up @@ -193,6 +195,10 @@ void Channels::onConfigChanged()
if (ch.role == meshtastic_Channel_Role_PRIMARY)
primaryIndex = i;
}
if (channels.anyMqttEnabled() && mqtt && !mqtt->isEnabled()) {
LOG_DEBUG("MQTT is enabled on at least one channel, so set MQTT thread to run immediately\n");
mqtt->start();
}
}

meshtastic_Channel &Channels::getByIndex(ChannelIndex chIndex)
Expand Down
4 changes: 2 additions & 2 deletions src/mqtt/MQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ bool MQTT::wantsLink() const

int32_t MQTT::runOnce()
{
if (!moduleConfig.mqtt.enabled)
if (!moduleConfig.mqtt.enabled || !(moduleConfig.mqtt.map_reporting_enabled || channels.anyMqttEnabled()))
return disable();

bool wantConnection = wantsLink();
Expand Down Expand Up @@ -902,4 +902,4 @@ bool MQTT::isValidJsonEnvelope(JSONObject &json)
(json["from"]->AsNumber() == nodeDB.getNodeNum()) && // only accept message if the "from" is us
(json.find("type") != json.end()) && json["type"]->IsString() && // should specify a type
(json.find("payload") != json.end()); // should have a payload
}
}
4 changes: 4 additions & 0 deletions src/mqtt/MQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class MQTT : private concurrency::OSThread

void onClientProxyReceive(meshtastic_MqttClientProxyMessage msg);

bool isEnabled() { return this->enabled; };

void start() { setIntervalFromNow(0); };

protected:
PointerQueue<meshtastic_ServiceEnvelope> mqttQueue;

Expand Down

0 comments on commit 21b09e5

Please sign in to comment.