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 21, 2023
1 parent f4344ab commit e4c1e5a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
#define FACTORY_OFFSET CONFIG_SIZE
#define FACTORY_SIZE 1024

uint32_t config_ver = 1;
#define INITIAL_CONFIG_VERSION 1

uint32_t config_ver = INITIAL_CONFIG_VERSION;

// Wifi Network Strings
String esid;
Expand Down Expand Up @@ -261,6 +263,11 @@ config_version() {
return config_ver;
}

uint32_t
initial_config_version() {
return INITIAL_CONFIG_VERSION;
}

void
increment_config() {
config_ver++;
Expand Down
1 change: 1 addition & 0 deletions src/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ inline EvseState config_default_state()
extern String ohm;

extern uint32_t config_version();
extern uint32_t initial_config_version();

// -------------------------------------------------------------------
// Load saved settings
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 e4c1e5a

Please sign in to comment.