Fix MQTT config bugs (#7446)
* Fix mqtt config bugs * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add client notification * Verbiage * Update src/mqtt/MQTT.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/mqtt/MQTT.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/mqtt/MQTT.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/mqtt/MQTT.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove test that is no longer true * This test no longer exists * Fix client notification crap * Suppress false positive * Revert "Suppress false positive" This reverts commit bead96eaee31f11ed631c016eb0424055e923a29. * Try macro exclusion * Derp * Fix --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jason P <applewiz@mac.com>
This commit is contained in:
co-authored by
GitHub
Copilot
Jason P
parent
fc1e6ccb8c
commit
a506dc6b65
+21
-6
@@ -39,6 +39,7 @@
|
||||
#include <machine/endian.h>
|
||||
#define ntohl __ntohl
|
||||
#endif
|
||||
#include <RTC.h>
|
||||
|
||||
MQTT *mqtt;
|
||||
|
||||
@@ -624,18 +625,32 @@ bool MQTT::isValidConfig(const meshtastic_ModuleConfig_MQTTConfig &config, MQTTC
|
||||
return connectPubSub(parsed, *pubSub, (client != nullptr) ? *client : *clientConnection);
|
||||
}
|
||||
#else
|
||||
LOG_ERROR("Invalid MQTT config: proxy_to_client_enabled must be enabled on nodes that do not have a network");
|
||||
const char *warning = "Invalid MQTT config: proxy_to_client_enabled must be enabled on nodes that do not have a network";
|
||||
LOG_ERROR(warning);
|
||||
#if !IS_RUNNING_TESTS
|
||||
meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed();
|
||||
cn->level = meshtastic_LogRecord_Level_ERROR;
|
||||
cn->time = getValidTime(RTCQualityFromNet);
|
||||
strncpy(cn->message, warning, sizeof(cn->message) - 1);
|
||||
cn->message[sizeof(cn->message) - 1] = '\0'; // Ensure null termination
|
||||
service->sendClientNotification(cn);
|
||||
#endif
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
const bool defaultServer = isDefaultServer(parsed.serverAddr);
|
||||
if (defaultServer && config.tls_enabled) {
|
||||
LOG_ERROR("Invalid MQTT config: TLS was enabled, but the default server does not support TLS");
|
||||
return false;
|
||||
}
|
||||
if (defaultServer && parsed.serverPort != PubSubConfig::defaultPort) {
|
||||
LOG_ERROR("Invalid MQTT config: Unsupported port '%d' for the default MQTT server", parsed.serverPort);
|
||||
const char *warning = "Invalid MQTT config: default server address must not have a port specified";
|
||||
LOG_ERROR(warning);
|
||||
#if !IS_RUNNING_TESTS
|
||||
meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed();
|
||||
cn->level = meshtastic_LogRecord_Level_ERROR;
|
||||
cn->time = getValidTime(RTCQualityFromNet);
|
||||
strncpy(cn->message, warning, sizeof(cn->message) - 1);
|
||||
cn->message[sizeof(cn->message) - 1] = '\0'; // Ensure null termination
|
||||
service->sendClientNotification(cn);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user