From b513675de1093c31c5df4be5d5135ceaa91746f7 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Mon, 22 May 2023 00:12:59 +0200 Subject: [PATCH] Avoid duplicate publish of config_version when config is updated --- src/app_config.cpp | 2 +- src/app_config.h | 2 ++ src/mqtt.cpp | 8 +++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app_config.cpp b/src/app_config.cpp index 15620d21..633a9324 100644 --- a/src/app_config.cpp +++ b/src/app_config.cpp @@ -31,7 +31,7 @@ #define FACTORY_OFFSET CONFIG_SIZE #define FACTORY_SIZE 1024 -uint32_t config_ver = 1; +uint32_t config_ver = INITIAL_CONFIG_VERSION; // Wifi Network Strings String esid; diff --git a/src/app_config.h b/src/app_config.h index 7b4e1fe1..f4c516e0 100644 --- a/src/app_config.h +++ b/src/app_config.h @@ -128,6 +128,8 @@ extern uint32_t flags; #define CONFIG_WIZARD (1 << 25) #define CONFIG_DEFAULT_STATE (1 << 26) +#define INITIAL_CONFIG_VERSION 1 + inline bool config_emoncms_enabled() { return CONFIG_SERVICE_EMONCMS == (flags & CONFIG_SERVICE_EMONCMS); } diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 83e0ccd5..edcefbbc 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -519,9 +519,11 @@ mqtt_publish_config() { config_serialize(doc, true, false, true); mqtt_publish_json(doc, "/config"); - String fulltopic = mqtt_topic + "/config_version"; - String payload = String(config_version()); - mqttclient.publish(fulltopic, payload, true); + if(config_version() == INITIAL_CONFIG_VERSION) { + String fulltopic = mqtt_topic + "/config_version"; + String payload = String(config_version()); + mqttclient.publish(fulltopic, payload, true); + } return true; }