From 6da58e3505ed1ef79238cc707a335f31527a3fa8 Mon Sep 17 00:00:00 2001
From: lumapu <lp@lufami.de>
Date: Mon, 13 Mar 2023 21:58:48 +0100
Subject: [PATCH] 0.5.100 fix add inverter `setup.html` #766 fix MQTT retained
 flag for total values #726 renamed buttons for import and export `setup.html`
 added serial message `settings saved`

---
 src/CHANGES.md          | 6 ++++++
 src/app.h               | 1 +
 src/config/settings.h   | 1 +
 src/defines.h           | 2 +-
 src/publisher/pubMqtt.h | 6 +++---
 src/web/html/setup.html | 6 +++---
 6 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/CHANGES.md b/src/CHANGES.md
index 65c67bb8..9ec5f85b 100644
--- a/src/CHANGES.md
+++ b/src/CHANGES.md
@@ -2,6 +2,12 @@
 
 (starting from release version `0.5.66`)
 
+## 0.5.100
+* fix add inverter `setup.html` #766
+* fix MQTT retained flag for total values #726
+* renamed buttons for import and export `setup.html`
+* added serial message `settings saved`
+
 ## 0.5.99
 * fix limit in [User_Manual.md](../User_Manual.md)
 * changed `contrast` to `luminance` in `setup.html`
diff --git a/src/app.h b/src/app.h
index 64510eef..a792ffe8 100644
--- a/src/app.h
+++ b/src/app.h
@@ -210,6 +210,7 @@ class app : public IApp, public ah::Scheduler {
             onWifi(false);
             ah::Scheduler::resetTicker();
             WiFi.disconnect();
+            delay(200);
             ESP.restart();
         }
 
diff --git a/src/config/settings.h b/src/config/settings.h
index fab8327e..77bc7a26 100644
--- a/src/config/settings.h
+++ b/src/config/settings.h
@@ -273,6 +273,7 @@ class settings {
             }
             fp.close();
 
+            DPRINTLN(DBG_INFO, F("settings saved"));
             if(stopFs)
                 stop();
 
diff --git a/src/defines.h b/src/defines.h
index 228f7388..b800aaa0 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -13,7 +13,7 @@
 //-------------------------------------
 #define VERSION_MAJOR       0
 #define VERSION_MINOR       5
-#define VERSION_PATCH       99
+#define VERSION_PATCH       100
 
 //-------------------------------------
 typedef struct {
diff --git a/src/publisher/pubMqtt.h b/src/publisher/pubMqtt.h
index 2b2b298e..7922b2e8 100644
--- a/src/publisher/pubMqtt.h
+++ b/src/publisher/pubMqtt.h
@@ -59,7 +59,7 @@ class PubMqtt {
 
             if((strlen(mCfgMqtt->user) > 0) && (strlen(mCfgMqtt->pwd) > 0))
                 mClient.setCredentials(mCfgMqtt->user, mCfgMqtt->pwd);
-            snprintf(mClientId, 26, "%s-", mDevName);
+            snprintf(mClientId, 24, "%s-", mDevName);
             uint8_t pos = strlen(mClientId);
             mClientId[pos++] = WiFi.macAddress().substring( 9, 10).c_str()[0];
             mClientId[pos++] = WiFi.macAddress().substring(10, 11).c_str()[0];
@@ -582,8 +582,8 @@ class PubMqtt {
 
                     if (sendTotals) {
                         uint8_t fieldId;
-                        bool retained = true;
                         for (uint8_t i = 0; i < 4; i++) {
+                            bool retained = true;
                             switch (i) {
                                 default:
                                 case 0:
@@ -635,7 +635,7 @@ class PubMqtt {
         // last will topic and payload must be available trough lifetime of 'espMqttClient'
         char mLwtTopic[MQTT_TOPIC_LEN+5];
         const char *mDevName, *mVersion;
-        char mClientId[26]; // number of chars is limited to 23 up to v3.1 of MQTT
+        char mClientId[24]; // number of chars is limited to 23 up to v3.1 of MQTT
 };
 
 #endif /*__PUB_MQTT_H__*/
diff --git a/src/web/html/setup.html b/src/web/html/setup.html
index ad8506dd..967cccd6 100644
--- a/src/web/html/setup.html
+++ b/src/web/html/setup.html
@@ -295,14 +295,14 @@
                             <div class="col-4 col-sm-9">
                                 <form id="form" method="POST" action="/upload" enctype="multipart/form-data" accept-charset="utf-8">
                                     <input type="file" name="upload">
-                                    <input type="button" class="btn" value="Upload" onclick="hide()">
+                                    <input type="button" class="btn" value="Import" onclick="hide()">
                                 </form>
                             </div>
                         </div>
                         <div class="row mb-4 mt-4">
                             <div class="col-8 col-sm-3">Export</div>
                             <div class="col-4 col-sm-9">
-                                <a class="btn" href="/get_setup" target="_blank">Download settings (JSON file)</a><span> (only values, passwords will be removed!)</span>
+                                <a class="btn" href="/get_setup" target="_blank">Export settings (JSON file)</a><span> (only values, passwords will be removed!)</span>
                             </div>
                         </div>
                     </fieldset>
@@ -368,7 +368,7 @@
 
             document.getElementById("btnAdd").addEventListener("click", function() {
                 if(highestId <= (maxInv-1)) {
-                    ivHtml(JSON.parse('{"enabled":true,"name":"","serial":"","channels":4,"ch_max_power":[0,0,0,0],"ch_name":["","","",""],"ch_yield_cor":[0,0,0,0]}'), highestId);
+                    ivHtml(JSON.parse('{"enabled":true,"name":"","serial":"","channels":4,"ch_max_pwr":[0,0,0,0],"ch_name":["","","",""],"ch_yield_cor":[0,0,0,0]}'), highestId);
                 }
             });