mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-20 17:52:35 +00:00
update mqtt root when region is changed via OLED menu handler
This commit is contained in:
@@ -116,6 +116,8 @@ void menuHandler::LoraRegionPicker(uint32_t duration)
|
|||||||
bannerOptions.bannerCallback = [](int selected) -> void {
|
bannerOptions.bannerCallback = [](int selected) -> void {
|
||||||
if (selected != 0 && config.lora.region != _meshtastic_Config_LoRaConfig_RegionCode(selected)) {
|
if (selected != 0 && config.lora.region != _meshtastic_Config_LoRaConfig_RegionCode(selected)) {
|
||||||
config.lora.region = _meshtastic_Config_LoRaConfig_RegionCode(selected);
|
config.lora.region = _meshtastic_Config_LoRaConfig_RegionCode(selected);
|
||||||
|
auto changes = SEGMENT_CONFIG;
|
||||||
|
|
||||||
// This is needed as we wait til picking the LoRa region to generate keys for the first time.
|
// This is needed as we wait til picking the LoRa region to generate keys for the first time.
|
||||||
if (!owner.is_licensed) {
|
if (!owner.is_licensed) {
|
||||||
bool keygenSuccess = false;
|
bool keygenSuccess = false;
|
||||||
@@ -124,6 +126,7 @@ void menuHandler::LoraRegionPicker(uint32_t duration)
|
|||||||
if (crypto->regeneratePublicKey(config.security.public_key.bytes, config.security.private_key.bytes)) {
|
if (crypto->regeneratePublicKey(config.security.public_key.bytes, config.security.private_key.bytes)) {
|
||||||
keygenSuccess = true;
|
keygenSuccess = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO("Generate new PKI keys");
|
LOG_INFO("Generate new PKI keys");
|
||||||
crypto->generateKeyPair(config.security.public_key.bytes, config.security.private_key.bytes);
|
crypto->generateKeyPair(config.security.public_key.bytes, config.security.private_key.bytes);
|
||||||
@@ -141,7 +144,14 @@ void menuHandler::LoraRegionPicker(uint32_t duration)
|
|||||||
if (myRegion->dutyCycle < 100) {
|
if (myRegion->dutyCycle < 100) {
|
||||||
config.lora.ignore_mqtt = true; // Ignore MQTT by default if region has a duty cycle limit
|
config.lora.ignore_mqtt = true; // Ignore MQTT by default if region has a duty cycle limit
|
||||||
}
|
}
|
||||||
service->reloadConfig(SEGMENT_CONFIG);
|
|
||||||
|
if (strncmp(moduleConfig.mqtt.root, default_mqtt_root, 3) == 0) {
|
||||||
|
// Default broker is in use, so subscribe to the appropriate MQTT root topic for this region
|
||||||
|
sprintf(moduleConfig.mqtt.root, "%s/%s", default_mqtt_root, myRegion->name);
|
||||||
|
changes |= SEGMENT_MODULECONFIG;
|
||||||
|
};
|
||||||
|
|
||||||
|
service->reloadConfig(changes);
|
||||||
rebootAtMsec = (millis() + DEFAULT_REBOOT_SECONDS * 1000);
|
rebootAtMsec = (millis() + DEFAULT_REBOOT_SECONDS * 1000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -765,6 +765,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c)
|
|||||||
if (myRegion->dutyCycle < 100) {
|
if (myRegion->dutyCycle < 100) {
|
||||||
config.lora.ignore_mqtt = true; // Ignore MQTT by default if region has a duty cycle limit
|
config.lora.ignore_mqtt = true; // Ignore MQTT by default if region has a duty cycle limit
|
||||||
}
|
}
|
||||||
|
// Compare the entire string, we are sure of the length as a topic has never been set
|
||||||
if (strcmp(moduleConfig.mqtt.root, default_mqtt_root) == 0) {
|
if (strcmp(moduleConfig.mqtt.root, default_mqtt_root) == 0) {
|
||||||
sprintf(moduleConfig.mqtt.root, "%s/%s", default_mqtt_root, myRegion->name);
|
sprintf(moduleConfig.mqtt.root, "%s/%s", default_mqtt_root, myRegion->name);
|
||||||
changes = SEGMENT_CONFIG | SEGMENT_MODULECONFIG;
|
changes = SEGMENT_CONFIG | SEGMENT_MODULECONFIG;
|
||||||
@@ -775,16 +776,10 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c)
|
|||||||
// Additionally as a side-effect, assume a new value under myRegion
|
// Additionally as a side-effect, assume a new value under myRegion
|
||||||
initRegion();
|
initRegion();
|
||||||
|
|
||||||
std::string current = moduleConfig.mqtt.root;
|
if (strncmp(moduleConfig.mqtt.root, default_mqtt_root, 3) == 0) {
|
||||||
size_t location = current.find_first_of('/');
|
// Default broker is in use, so subscribe to the appropriate MQTT root topic for this region
|
||||||
|
sprintf(moduleConfig.mqtt.root, "%s/%s", default_mqtt_root, myRegion->name);
|
||||||
char root[location + 1];
|
}
|
||||||
memset(root, 0, location);
|
|
||||||
memcpy(root, moduleConfig.mqtt.root, location);
|
|
||||||
root[location] = '\0';
|
|
||||||
|
|
||||||
// subscribe to the appropriate MQTT root topic for this region
|
|
||||||
sprintf(moduleConfig.mqtt.root, "%s/%s", root, myRegion->name);
|
|
||||||
|
|
||||||
changes = SEGMENT_CONFIG | SEGMENT_MODULECONFIG;
|
changes = SEGMENT_CONFIG | SEGMENT_MODULECONFIG;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user