feat(mqtt): clarify custom endpoint requirements in code and documentation
Updated MQTT configuration to succeed when port is defined in mqttN.server but not explicitly set in mqttN.port. Updated documentation to specify that when a full URL with a scheme is provided, the port setting is optional. Added an example for local development using a plain WebSocket URL, enhancing clarity for users configuring custom MQTT brokers.
This commit is contained in:
1 parent
706d1c7ea2
commit
7e0ffdbea3
2 files changed
+22
-3
No files matched your search
@@ -107,13 +107,20 @@ static bool isWiFiConfigValid(const NodePrefs* prefs) {
|
||||
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
|
||||
// A custom slot endpoint is complete if a port is set, or if the host is a
|
||||
// full URI with a scheme (esp-mqtt applies scheme default ports, and the URI
|
||||
// builder in setupSlot() preserves any embedded port/path).
|
||||
static bool customEndpointComplete(const char* host, uint16_t port) {
|
||||
return host[0] != '\0' && (port != 0 || strstr(host, "://") != nullptr);
|
||||
}
|
||||
|
||||
bool MQTTBridge::isConfigValid(const NodePrefs* prefs) {
|
||||
if (!prefs || !isWiFiConfigValid(prefs)) return false;
|
||||
for (int i = 0; i < RUNTIME_MQTT_SLOTS; i++) {
|
||||
const char* preset_name = prefs->mqtt_slot_preset[i];
|
||||
if (preset_name[0] == '\0' || strcmp(preset_name, MQTT_PRESET_NONE) == 0) continue;
|
||||
if (strcmp(preset_name, MQTT_PRESET_CUSTOM) == 0) {
|
||||
if (prefs->mqtt_slot_host[i][0] != '\0' && prefs->mqtt_slot_port[i] != 0) return true;
|
||||
if (customEndpointComplete(prefs->mqtt_slot_host[i], prefs->mqtt_slot_port[i])) return true;
|
||||
} else if (findMQTTPreset(preset_name) != nullptr) {
|
||||
return true;
|
||||
}
|
||||
@@ -1925,7 +1932,7 @@ void MQTTBridge::applySlotPreset(int slot_index, const char* preset_name) {
|
||||
slot.enabled = true;
|
||||
slot.preset = nullptr;
|
||||
// Custom broker settings should already be set via setSlotCustomBroker
|
||||
if (_initialized && strlen(slot.host) > 0 && slot.port > 0) {
|
||||
if (_initialized && customEndpointComplete(slot.host, slot.port)) {
|
||||
setupSlot(slot_index);
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user