diff --git a/src/mesh/Channels.cpp b/src/mesh/Channels.cpp index 4bdd9e674a..4bc91ce4e6 100644 --- a/src/mesh/Channels.cpp +++ b/src/mesh/Channels.cpp @@ -318,7 +318,7 @@ bool Channels::anyMqttEnabled() { #if USERPREFS_EVENT_MODE // Don't publish messages on the public MQTT broker if we are in event mode - if (strcmp(moduleConfig.mqtt.address, default_mqtt_address) == 0) { + if (mqtt && mqtt.isUsingDefaultServer()) { return false; } #endif diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 6db63762d1..ad4f5f2f91 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -326,7 +326,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE) } String host = parseHostAndPort(moduleConfig.mqtt.address).first; - isDefaultMqttServer = host.length() == 0 || host == default_mqtt_address; + isConfiguredForDefaultServer = host.length() == 0 || host == default_mqtt_address; IPAddress ip; isMqttServerAddressPrivate = ip.fromString(host.c_str()) && isPrivateIpAddress(ip); @@ -635,8 +635,8 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp_encrypted, const meshtastic_Me return; } - if (isDefaultMqttServer && (mp_decoded.decoded.portnum == meshtastic_PortNum_RANGE_TEST_APP || - mp_decoded.decoded.portnum == meshtastic_PortNum_DETECTION_SENSOR_APP)) { + if (isConfiguredForDefaultServer && (mp_decoded.decoded.portnum == meshtastic_PortNum_RANGE_TEST_APP || + mp_decoded.decoded.portnum == meshtastic_PortNum_DETECTION_SENSOR_APP)) { LOG_DEBUG("MQTT onSend - Ignoring range test or detection sensor message on public mqtt"); return; } diff --git a/src/mqtt/MQTT.h b/src/mqtt/MQTT.h index 81892f6f38..cb1fffcc97 100644 --- a/src/mqtt/MQTT.h +++ b/src/mqtt/MQTT.h @@ -79,6 +79,8 @@ class MQTT : private concurrency::OSThread void start() { setIntervalFromNow(0); }; + bool isUsingDefaultServer() { return isConfiguredForDefaultServer; } + protected: struct QueueEntry { std::string topic; @@ -87,6 +89,7 @@ class MQTT : private concurrency::OSThread PointerQueue mqttQueue; int reconnectCount = 0; + bool isConfiguredForDefaultServer = true; virtual int32_t runOnce() override;