Keep MQTT command persistence in common prefs

This commit is contained in:
mikecarper committed 2026-09-17 07:49:40 -07:00
1 parent 1610a654fe
commit 0aaa64d41b
4 files changed
+21 -15

No files matched your search

+19
View File
@@ -3396,6 +3396,25 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
}
return;
}
#endif
#ifdef WITH_MQTT_BRIDGE
// bridge_enabled is stored with the common node preferences. Keep its
// MQTT-specific switch here rather than in the observer preferences
// handler, which must only write its own store.
if (strncmp(config, "mqtt.enabled ", 13) == 0) {
const char* value = config + 13;
if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
strcpy(reply, "Error: use set mqtt.enabled on|off");
} else {
const bool enable = strcmp(value, "on") == 0;
_prefs->bridge_enabled = enable ? 1 : 0;
const bool applied = _callbacks->setMqttBridgeState(enable);
savePrefs();
strcpy(reply, applied ? "OK"
: "Error: MQTT runtime change failed; setting saved");
}
return;
}
#endif
// Observer/MQTT/WiFi/timezone/alert/SNMP commands live in CommonCLI_Observer.cpp.
if (handleObserverSetCmd(sender_timestamp, config, reply)) return;
-14
View File
@@ -182,20 +182,6 @@ static void formatMQTTPresetListReply(char* reply, size_t reply_size, int start)
bool CommonCLI::handleObserverSetCmd(uint32_t sender_timestamp, const char* config, char* reply) {
#ifdef WITH_MQTT_BRIDGE
bool handled = true;
if (strncmp(config, "mqtt.enabled ", 13) == 0) {
const char* value = config + 13;
if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
strcpy(reply, "Error: use set mqtt.enabled on|off");
} else {
const bool enable = strcmp(value, "on") == 0;
_prefs->bridge_enabled = enable ? 1 : 0;
const bool applied = _callbacks->setMqttBridgeState(enable);
savePrefs();
strcpy(reply, applied ? "OK"
: "Error: MQTT runtime change failed; setting saved");
}
return true;
}
const auto restart_observer_bridge = [this]() {
return mesh::cli::restartBridgeIfEnabled(
_prefs->bridge_enabled != 0,
+1
View File
@@ -63,6 +63,7 @@ COMMON_QUERY_EXCEPTIONS = {
}
OBSERVER_QUERY_EXCEPTIONS = {
'mqtt.config.valid': 'Configuration validation result',
'mqtt.enabled': 'Stored in common NodePrefs; set mqtt.enabled is handled by CommonCLI',
'mqtt.ntp.diag': 'NTP diagnostics',
'mqtt.presets': 'List of available presets',
'mqtt.running': 'Live state; set mqtt.enabled controls intent',
+1 -1
View File
@@ -120,7 +120,7 @@ class EspNowLifecycleTests(unittest.TestCase):
self.assertIn('uint8_t espnow_bridge_enabled = 1;', prefs)
self.assertIn('setEspNowBridgeState(enable)', common)
self.assertIn('_prefs->espnow_bridge_enabled', common)
self.assertIn('setMqttBridgeState(enable)', observer)
self.assertIn('setMqttBridgeState(enable)', common)
self.assertIn('isMqttBridgeRunning()', observer)
for role in ('simple_repeater', 'simple_room_server'):
header = (ROOT/f'examples/{role}/MyMesh.h').read_text()