Channels::anyMqttEnabled() uses same logic

This commit is contained in:
Eric Severance 2024-12-24 15:03:50 -08:00
parent e9197da8a9
commit 72a7ed06d3
No known key found for this signature in database
GPG Key ID: F19AABB5E1EA1B5F
3 changed files with 7 additions and 4 deletions

View File

@ -318,7 +318,7 @@ bool Channels::anyMqttEnabled()
{ {
#if USERPREFS_EVENT_MODE #if USERPREFS_EVENT_MODE
// Don't publish messages on the public MQTT broker if we are in 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; return false;
} }
#endif #endif

View File

@ -326,7 +326,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), mqttQueue(MAX_MQTT_QUEUE)
} }
String host = parseHostAndPort(moduleConfig.mqtt.address).first; 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; IPAddress ip;
isMqttServerAddressPrivate = ip.fromString(host.c_str()) && isPrivateIpAddress(ip); isMqttServerAddressPrivate = ip.fromString(host.c_str()) && isPrivateIpAddress(ip);
@ -635,7 +635,7 @@ void MQTT::onSend(const meshtastic_MeshPacket &mp_encrypted, const meshtastic_Me
return; return;
} }
if (isDefaultMqttServer && (mp_decoded.decoded.portnum == meshtastic_PortNum_RANGE_TEST_APP || if (isConfiguredForDefaultServer && (mp_decoded.decoded.portnum == meshtastic_PortNum_RANGE_TEST_APP ||
mp_decoded.decoded.portnum == meshtastic_PortNum_DETECTION_SENSOR_APP)) { mp_decoded.decoded.portnum == meshtastic_PortNum_DETECTION_SENSOR_APP)) {
LOG_DEBUG("MQTT onSend - Ignoring range test or detection sensor message on public mqtt"); LOG_DEBUG("MQTT onSend - Ignoring range test or detection sensor message on public mqtt");
return; return;

View File

@ -79,6 +79,8 @@ class MQTT : private concurrency::OSThread
void start() { setIntervalFromNow(0); }; void start() { setIntervalFromNow(0); };
bool isUsingDefaultServer() { return isConfiguredForDefaultServer; }
protected: protected:
struct QueueEntry { struct QueueEntry {
std::string topic; std::string topic;
@ -87,6 +89,7 @@ class MQTT : private concurrency::OSThread
PointerQueue<QueueEntry> mqttQueue; PointerQueue<QueueEntry> mqttQueue;
int reconnectCount = 0; int reconnectCount = 0;
bool isConfiguredForDefaultServer = true;
virtual int32_t runOnce() override; virtual int32_t runOnce() override;