Skip to content

Commit b513675

Browse files
committed
Avoid duplicate publish of config_version when config is updated
1 parent f4344ab commit b513675

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/app_config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#define FACTORY_OFFSET CONFIG_SIZE
3232
#define FACTORY_SIZE 1024
3333

34-
uint32_t config_ver = 1;
34+
uint32_t config_ver = INITIAL_CONFIG_VERSION;
3535

3636
// Wifi Network Strings
3737
String esid;

src/app_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ extern uint32_t flags;
128128
#define CONFIG_WIZARD (1 << 25)
129129
#define CONFIG_DEFAULT_STATE (1 << 26)
130130

131+
#define INITIAL_CONFIG_VERSION 1
132+
131133
inline bool config_emoncms_enabled() {
132134
return CONFIG_SERVICE_EMONCMS == (flags & CONFIG_SERVICE_EMONCMS);
133135
}

src/mqtt.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,11 @@ mqtt_publish_config() {
519519
config_serialize(doc, true, false, true);
520520
mqtt_publish_json(doc, "/config");
521521

522-
String fulltopic = mqtt_topic + "/config_version";
523-
String payload = String(config_version());
524-
mqttclient.publish(fulltopic, payload, true);
522+
if(config_version() == INITIAL_CONFIG_VERSION) {
523+
String fulltopic = mqtt_topic + "/config_version";
524+
String payload = String(config_version());
525+
mqttclient.publish(fulltopic, payload, true);
526+
}
525527

526528
return true;
527529
}

0 commit comments

Comments
 (0)