From 042604a63911180e1e01f5a39ffdc59dc5b800db Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 18 Jul 2025 06:07:17 -0500 Subject: [PATCH 1/2] If default mqtt host / root, ensure lora region suffix on boot --- src/mesh/NodeDB.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 185ea0744..ef3c9330d 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -371,11 +371,18 @@ NodeDB::NodeDB() if (moduleConfig.telemetry.health_update_interval > MAX_INTERVAL) moduleConfig.telemetry.health_update_interval = MAX_INTERVAL; - if (moduleConfig.mqtt.has_map_report_settings && + if (moduleConfig.has_mqtt && moduleConfig.mqtt.has_map_report_settings && moduleConfig.mqtt.map_report_settings.publish_interval_secs < default_map_publish_interval_secs) { moduleConfig.mqtt.map_report_settings.publish_interval_secs = default_map_publish_interval_secs; } + // If we are using the default MQTT server, then we need to ensure that the root topic is set to msh/region name + if (moduleConfig.has_mqtt && config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_UNSET && + strncmp(moduleConfig.mqtt.address, default_mqtt_address, sizeof(default_mqtt_address)) == 0 && + strcmp(moduleConfig.mqtt.root, default_mqtt_root) == 0) { + sprintf(moduleConfig.mqtt.root, "%s/%s", default_mqtt_root, myRegion->name); + } + // Ensure that the neighbor info update interval is coerced to the minimum moduleConfig.neighbor_info.update_interval = Default::getConfiguredOrMinimumValue(moduleConfig.neighbor_info.update_interval, min_neighbor_info_broadcast_secs); @@ -436,8 +443,8 @@ NodeDB::NodeDB() } /** - * Most (but not always) of the time we want to treat packets 'from' the local phone (where from == 0), as if they originated on - * the local node. If from is zero this function returns our node number instead + * Most (but not always) of the time we want to treat packets 'from' the local phone (where from == 0), as if they originated + * on the local node. If from is zero this function returns our node number instead */ NodeNum getFrom(const meshtastic_MeshPacket *p) { @@ -1191,11 +1198,10 @@ void NodeDB::loadFromDisk() &meshtastic_DeviceState_msg, &devicestate); // See https://github.com/meshtastic/firmware/issues/4184#issuecomment-2269390786 - // It is very important to try and use the saved prefs even if we fail to read meshtastic_DeviceState. Because most of our - // critical config may still be valid (in the other files - loaded next). - // Also, if we did fail on reading we probably failed on the enormous (and non critical) nodeDB. So DO NOT install default - // device state. - // if (state != LoadFileResult::LOAD_SUCCESS) { + // It is very important to try and use the saved prefs even if we fail to read meshtastic_DeviceState. Because most of + // our critical config may still be valid (in the other files - loaded next). Also, if we did fail on reading we probably + // failed on the enormous (and non critical) nodeDB. So DO NOT install default device state. if (state != + // LoadFileResult::LOAD_SUCCESS) { // installDefaultDeviceState(); // Our in RAM copy might now be corrupt //} else { if ((state != LoadFileResult::LOAD_SUCCESS) || (devicestate.version < DEVICESTATE_MIN_VER)) { From e000653c795bf47c648ec6d71510a15d686601d9 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 18 Jul 2025 20:30:31 -0500 Subject: [PATCH 2/2] Update src/mesh/NodeDB.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/mesh/NodeDB.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index ef3c9330d..526710f83 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -380,7 +380,11 @@ NodeDB::NodeDB() if (moduleConfig.has_mqtt && config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_UNSET && strncmp(moduleConfig.mqtt.address, default_mqtt_address, sizeof(default_mqtt_address)) == 0 && strcmp(moduleConfig.mqtt.root, default_mqtt_root) == 0) { - sprintf(moduleConfig.mqtt.root, "%s/%s", default_mqtt_root, myRegion->name); + if (myRegion == nullptr) { + logError("myRegion is null. Cannot set MQTT root topic."); + } else { + sprintf(moduleConfig.mqtt.root, "%s/%s", default_mqtt_root, myRegion->name); + } } // Ensure that the neighbor info update interval is coerced to the minimum