mirror of
https://github.com/meshtastic/firmware.git
synced 2026-09-21 05:45:27 -04:00
fix(mqtt): count the regional roots as the default root topic
This commit is contained in:
1 parent
ea8a1320b5
commit
8936fc6007
2 files changed
+22
-6
No files matched your search
+7
-6
@@ -247,11 +247,6 @@ bool isDefaultServer(const String &host)
|
||||
return host.length() == 0 || host == default_mqtt_address;
|
||||
}
|
||||
|
||||
bool isDefaultRootTopic(const String &root)
|
||||
{
|
||||
return root.length() == 0 || root == default_mqtt_root;
|
||||
}
|
||||
|
||||
// "msh/<region>" is what the default broker's convention produces; any other suffix is the user's own.
|
||||
bool isRegionRootTopic(const char *root)
|
||||
{
|
||||
@@ -264,6 +259,12 @@ bool isRegionRootTopic(const char *root)
|
||||
return false;
|
||||
}
|
||||
|
||||
// The regional roots count as default: they are what a region change writes on the default broker.
|
||||
bool isDefaultRootTopic(const String &root)
|
||||
{
|
||||
return root.length() == 0 || root == default_mqtt_root || isRegionRootTopic(root.c_str());
|
||||
}
|
||||
|
||||
struct PubSubConfig {
|
||||
explicit PubSubConfig(const meshtastic_ModuleConfig_MQTTConfig &config)
|
||||
{
|
||||
@@ -385,7 +386,7 @@ bool MQTT::applyRegionRootTopic(const char *regionName)
|
||||
(void)parsedPort;
|
||||
if (!isDefaultServer(host))
|
||||
return false;
|
||||
if (!isDefaultRootTopic(moduleConfig.mqtt.root) && !isRegionRootTopic(moduleConfig.mqtt.root))
|
||||
if (!isDefaultRootTopic(moduleConfig.mqtt.root))
|
||||
return false; // the user picked their own root
|
||||
snprintf(moduleConfig.mqtt.root, sizeof(moduleConfig.mqtt.root), "%s/%s", default_mqtt_root, regionName);
|
||||
return true;
|
||||
|
||||
@@ -1427,6 +1427,20 @@ void test_applyRegionRootTopic_rewritesDefaultBrokerRootsOnly(void)
|
||||
TEST_ASSERT_EQUAL_STRING("msh/US", moduleConfig.mqtt.root);
|
||||
}
|
||||
|
||||
// USERPREFS_EVENT_MODE gates the public broker on isUsingDefaultRootTopic() (Channels::anyMqttEnabled()).
|
||||
// A "msh/<region>" root is what a region change writes on the default broker, so it has to keep counting as
|
||||
// the default root; otherwise an event build silently loses that guard the first time the region changes.
|
||||
void test_regionRootTopic_countsAsTheDefaultRoot(void)
|
||||
{
|
||||
strcpy(moduleConfig.mqtt.root, "msh/EU_868");
|
||||
MQTTUnitTest::restart();
|
||||
TEST_ASSERT_TRUE(mqtt->isUsingDefaultRootTopic());
|
||||
|
||||
strcpy(moduleConfig.mqtt.root, "msh/home");
|
||||
MQTTUnitTest::restart();
|
||||
TEST_ASSERT_FALSE(mqtt->isUsingDefaultRootTopic());
|
||||
}
|
||||
|
||||
// Empty configuration is valid.
|
||||
void test_configEmptyIsValid(void)
|
||||
{
|
||||
@@ -1624,6 +1638,7 @@ void setup()
|
||||
RUN_TEST(test_customMqttRoot);
|
||||
RUN_TEST(test_rootChange_rebuildsTopics);
|
||||
RUN_TEST(test_applyRegionRootTopic_rewritesDefaultBrokerRootsOnly);
|
||||
RUN_TEST(test_regionRootTopic_countsAsTheDefaultRoot);
|
||||
RUN_TEST(test_configEmptyIsValid);
|
||||
RUN_TEST(test_configEnabledEmptyIsValid);
|
||||
RUN_TEST(test_configWithDefaultServer);
|
||||
|
||||
Reference in new issue
Block a user