From 865e2b7bfed5d325b37e721e83d65fb847c4bb5b Mon Sep 17 00:00:00 2001
From: Eric Duminil <eric.duminil@gmail.com>
Date: Mon, 21 Feb 2022 11:38:09 +0100
Subject: [PATCH] Adding AMPEL_CONFIG_VERSION

---
 ampel-firmware/config.public.h | 15 ++++++++++++++-
 ampel-firmware/web_config.cpp  |  2 +-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/ampel-firmware/config.public.h b/ampel-firmware/config.public.h
index a6fbaf7..bcc65e9 100644
--- a/ampel-firmware/config.public.h
+++ b/ampel-firmware/config.public.h
@@ -14,7 +14,14 @@
 
 // This file is a config template, and can be copied to config.h.
 // Please don't save any important password in this template.
-// NOTE: Every parameter can be modified and saved later via the web-config.
+
+// IMPORTANT: Parameters defined in config.h are only default values, and are applied if:
+//   * the ampel is flashed for the first time
+//   * or 'reset_config' command is called
+//   * or AMPEL_CONFIG_VERSION has been changed.
+
+// Once those default values have been applied, uploading the firmware with a modified config.h will not update the ampel configuration!
+// Every parameter can be modified and saved later via the web-config.
 // Some of those parameters can also be modified via commands in the Serial monitor :
 //    e.g. 'wifi 0' to turn WiFi off, or 'csv 60' to log data in csv every minute.
 
@@ -33,6 +40,12 @@
 // In order to be set successfully, it should have at least 8 characters.
 #  define AMPEL_PASSWORD ""
 
+// AMPEL_CONFIG_VERSION should be defined, and have exactly 3 characters.
+// If you modify this string, every parameter saved on the Ampel will be replaced by the ones in config.h.
+// AMPEL_CONFIG_VERSION should also be updated if the configuration structure is modified.
+// The structure of the Ampel configuration has been modified 10 times, so it's called "a10" for now.
+#  define AMPEL_CONFIG_VERSION "a10"
+
 /**
  * SERVICES
  */
diff --git a/ampel-firmware/web_config.cpp b/ampel-firmware/web_config.cpp
index f8aac2d..1012ee3 100644
--- a/ampel-firmware/web_config.cpp
+++ b/ampel-firmware/web_config.cpp
@@ -31,7 +31,7 @@ namespace web_config {
 
   IotWebConf *iotWebConf;
 
-  const char config_version[IOTWEBCONF_CONFIG_VERSION_LENGTH] = "a10"; // -- Configuration specific key. The value should be modified if config structure was changed.
+  const char config_version[IOTWEBCONF_CONFIG_VERSION_LENGTH] = AMPEL_CONFIG_VERSION; // -- Configuration specific key. The value should be modified if config structure was changed.
   using namespace iotwebconf;
 
   /**
-- 
GitLab