Skip to content

Commit

Permalink
Avoid duplicate publish of config_version when config is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed May 22, 2023
1 parent f4344ab commit b513675
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 5 additions & 3 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b513675

Please sign in to comment.