From 5adef54d4fae32c39ef1778825c3e28ec65ce2d1 Mon Sep 17 00:00:00 2001
From: tictrick <117273857+tictrick@users.noreply.github.com>
Date: Wed, 12 Jun 2024 08:57:24 +0200
Subject: [PATCH 1/8] Update pubMqtt.h - Bugfix #1673

Ahoy reboots because MQTT receives a Topic
---
 src/publisher/pubMqtt.h | 47 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 8 deletions(-)

diff --git a/src/publisher/pubMqtt.h b/src/publisher/pubMqtt.h
index 20317ec6..f80a28bd 100644
--- a/src/publisher/pubMqtt.h
+++ b/src/publisher/pubMqtt.h
@@ -111,7 +111,7 @@ class PubMqtt {
         void loop() {
             std::queue<message_s> queue;
             xSemaphoreTake(mutex, portMAX_DELAY);
-            std::swap(queue, mReceiveQueue);
+            queue.swap(mReceiveQueue);
             xSemaphoreGive(mutex);
 
             while (!queue.empty()) {
@@ -645,28 +645,59 @@ class PubMqtt {
     private:
         enum {MQTT_STATUS_OFFLINE = 0, MQTT_STATUS_PARTIAL, MQTT_STATUS_ONLINE};
 
-        struct message_s {
-            char* topic;
-            uint8_t* payload;
+        struct message_s
+        {
+            char *topic;
+            uint8_t *payload;
             size_t len;
             size_t index;
             size_t total;
 
-            message_s(const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total) {
-                this->topic = new char[strlen(topic) + 1];
+            message_s() : topic { nullptr },  payload { nullptr },  len { 0 }, index { 0 }, total { 0 } {}
+
+            message_s(const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total)
+            {
+                uint8_t topic_len = strlen(topic) + 1;
+                this->topic = new char[topic_len];
                 this->payload = new uint8_t[len];
 
-                memcpy(this->topic, topic, strlen(topic));
+                memcpy(this->topic, topic, topic_len);
                 memcpy(this->payload, payload, len);
                 this->len = len;
                 this->index = index;
                 this->total = total;
             }
 
-            ~message_s() {
+            message_s(const message_s &) = delete;
+
+            message_s(message_s && other) : message_s {}
+            {
+                this->swap( other );
+            }
+
+            ~message_s()
+            {
                 delete[] this->topic;
                 delete[] this->payload;
             }
+
+            message_s  &operator = (const message_s &) = delete;
+
+            message_s  &operator = (message_s &&other)
+            {
+                this->swap(other);
+                return *this;
+            }
+
+            void swap(message_s &other)
+            {
+                std::swap(this->topic, other.topic);
+                std::swap(this->payload, other.payload);
+                std::swap(this->len, other.len);
+                std::swap(this->index, other.index);
+                std::swap(this->total, other.total);
+            }
+
         };
 
     private:

From 29a3843c47de96a3a21a9c4419c69d7ca7e22458 Mon Sep 17 00:00:00 2001
From: lumapu <lp@lufami.de>
Date: Wed, 12 Jun 2024 21:46:12 +0200
Subject: [PATCH 2/8] code formatting

---
 src/publisher/pubMqtt.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/publisher/pubMqtt.h b/src/publisher/pubMqtt.h
index f80a28bd..28cfb358 100644
--- a/src/publisher/pubMqtt.h
+++ b/src/publisher/pubMqtt.h
@@ -653,7 +653,13 @@ class PubMqtt {
             size_t index;
             size_t total;
 
-            message_s() : topic { nullptr },  payload { nullptr },  len { 0 }, index { 0 }, total { 0 } {}
+            message_s() 
+            : topic { nullptr }
+            , payload { nullptr }
+            , len { 0 }
+            , index { 0 }
+            , total { 0 }
+            {}
 
             message_s(const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total)
             {

From d4d97dc7951d73d9efbfef068e27cae9759b36f7 Mon Sep 17 00:00:00 2001
From: lumapu <lp@lufami.de>
Date: Wed, 12 Jun 2024 22:00:01 +0200
Subject: [PATCH 3/8] 0.8.126 * merge PR: Update pubMqtt.h - Bugfix #1673 #1674

---
 src/CHANGES.md | 3 +++
 src/defines.h  | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/CHANGES.md b/src/CHANGES.md
index 91949ced..ac2014e8 100644
--- a/src/CHANGES.md
+++ b/src/CHANGES.md
@@ -1,5 +1,8 @@
 # Development Changes
 
+## 0.8.126 - 2024-06-12
+* merge PR: Update pubMqtt.h - Bugfix #1673 #1674
+
 ## 0.8.125 - 2024-06-09
 * fix ESP8266 compilation
 * merge PR: active_PowerLimit #1663
diff --git a/src/defines.h b/src/defines.h
index 8df76207..b44b9ce1 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -13,7 +13,7 @@
 //-------------------------------------
 #define VERSION_MAJOR       0
 #define VERSION_MINOR       8
-#define VERSION_PATCH       125
+#define VERSION_PATCH       126
 //-------------------------------------
 typedef struct {
     uint8_t ch;

From 8ae03a443f38fda7307956ea0f7a6241de5676e9 Mon Sep 17 00:00:00 2001
From: geronet1 <geronet.bachmaier@gmail.com>
Date: Fri, 14 Jun 2024 23:20:18 +0200
Subject: [PATCH 4/8] Bugfix Inv delete not working with password protection

---
 src/web/html/setup.html | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/web/html/setup.html b/src/web/html/setup.html
index 9452f0e3..95777c45 100644
--- a/src/web/html/setup.html
+++ b/src/web/html/setup.html
@@ -954,6 +954,7 @@
                 function del() {
                     var o = new Object();
                     o.cmd  = "save_iv";
+                    o.token = "*"
                     o.id   = obj.id;
                     o.ser  = 0;
                     o.name = "";

From 75e9022d83e03a1b5a37853433270591b88c1aa2 Mon Sep 17 00:00:00 2001
From: lumapu <lp@lufami.de>
Date: Fri, 21 Jun 2024 23:25:34 +0200
Subject: [PATCH 5/8] 0.8.127 * add grid file #1677

---
 src/CHANGES.md              | 3 +++
 src/defines.h               | 2 +-
 src/web/html/grid_info.json | 1 +
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/CHANGES.md b/src/CHANGES.md
index ac2014e8..f9c90d66 100644
--- a/src/CHANGES.md
+++ b/src/CHANGES.md
@@ -1,5 +1,8 @@
 # Development Changes
 
+## 0.8.127 - 2024-06-21
+* add grid file #1677
+
 ## 0.8.126 - 2024-06-12
 * merge PR: Update pubMqtt.h - Bugfix #1673 #1674
 
diff --git a/src/defines.h b/src/defines.h
index b44b9ce1..202b27cb 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -13,7 +13,7 @@
 //-------------------------------------
 #define VERSION_MAJOR       0
 #define VERSION_MINOR       8
-#define VERSION_PATCH       126
+#define VERSION_PATCH       127
 //-------------------------------------
 typedef struct {
     uint8_t ch;
diff --git a/src/web/html/grid_info.json b/src/web/html/grid_info.json
index efb5651d..5b5d4186 100644
--- a/src/web/html/grid_info.json
+++ b/src/web/html/grid_info.json
@@ -10,6 +10,7 @@
         {"0x0908": "France_VFR2014"},
         {"0x0a00": "DE NF_EN_50549-1:2019"},
         {"0x0c00": "AT_TOR_Erzeuger_default"},
+        {"0x0c03": "AT_TOR_Erzeuger_cosphi=1"},
         {"0x0c04": "AT_TOR_Erzeuger_default"},
         {"0x0d00": "FR_VFR2019"},
         {"0x0d04": "NF_EN_50549-1:2019"},

From 8cdf3644dfa62fbda8b2c1bdef25c18a45a951e0 Mon Sep 17 00:00:00 2001
From: lumapu <lp@lufami.de>
Date: Fri, 21 Jun 2024 23:27:19 +0200
Subject: [PATCH 6/8] 0.8.127

---
 src/CHANGES.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/CHANGES.md b/src/CHANGES.md
index f9c90d66..a035a656 100644
--- a/src/CHANGES.md
+++ b/src/CHANGES.md
@@ -2,6 +2,7 @@
 
 ## 0.8.127 - 2024-06-21
 * add grid file #1677
+* merge PR: Bugfix Inv delete not working with password protection #1678
 
 ## 0.8.126 - 2024-06-12
 * merge PR: Update pubMqtt.h - Bugfix #1673 #1674

From 82e4d84522a2cdef2b17c8da540507ca5cbf8c4f Mon Sep 17 00:00:00 2001
From: lumapu <lp@lufami.de>
Date: Tue, 2 Jul 2024 20:47:11 +0200
Subject: [PATCH 7/8] 0.8.128 * add environments for 16MB flash size ESP32-S3
 aka opendtufusion

---
 .github/workflows/compile_development.yml |  4 +++
 src/CHANGES.md                            |  3 ++
 src/defines.h                             |  2 +-
 src/platformio.ini                        | 36 +++++++++++++++++++++++
 4 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/compile_development.yml b/.github/workflows/compile_development.yml
index b5e0e0e1..223a7a39 100644
--- a/.github/workflows/compile_development.yml
+++ b/.github/workflows/compile_development.yml
@@ -25,6 +25,8 @@ jobs:
         variant:
           - opendtufusion
           - opendtufusion-ethernet
+          - opendtufusion-16MB
+          - opendtufusion-ethernet-16MB
           - esp8266
           - esp8266-all
           - esp8266-minimal
@@ -94,6 +96,8 @@ jobs:
         variant:
           - opendtufusion-de
           - opendtufusion-ethernet-de
+          - opendtufusion-16MB-de
+          - opendtufusion-ethernet-16MB-de
           - esp8266-de
           - esp8266-all-de
           - esp8266-prometheus-de
diff --git a/src/CHANGES.md b/src/CHANGES.md
index a035a656..e93e7f02 100644
--- a/src/CHANGES.md
+++ b/src/CHANGES.md
@@ -1,5 +1,8 @@
 # Development Changes
 
+## 0.8.128 - 2024-07-02
+* add environments for 16MB flash size ESP32-S3 aka opendtufusion
+
 ## 0.8.127 - 2024-06-21
 * add grid file #1677
 * merge PR: Bugfix Inv delete not working with password protection #1678
diff --git a/src/defines.h b/src/defines.h
index 202b27cb..fae033d7 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -13,7 +13,7 @@
 //-------------------------------------
 #define VERSION_MAJOR       0
 #define VERSION_MINOR       8
-#define VERSION_PATCH       127
+#define VERSION_PATCH       128
 //-------------------------------------
 typedef struct {
     uint8_t ch;
diff --git a/src/platformio.ini b/src/platformio.ini
index 69359aa4..7a75420b 100644
--- a/src/platformio.ini
+++ b/src/platformio.ini
@@ -353,3 +353,39 @@ build_flags = ${env:opendtufusion-ethernet.build_flags}
     -DLANG_DE
 monitor_filters =
     esp32_exception_decoder, colorize
+
+[env:opendtufusion-16MB]
+platform = espressif32@6.6.0
+board = esp32-s3-devkitc-1
+board_upload.flash_size = 16MB
+upload_protocol = esp-builtin
+build_flags = ${env:opendtufusion.build_flags}
+monitor_filters =
+    esp32_exception_decoder, colorize
+
+[env:opendtufusion-16MB-de]
+platform = espressif32@6.6.0
+board = esp32-s3-devkitc-1
+upload_protocol = esp-builtin
+build_flags = ${env:opendtufusion-16MB.build_flags}
+    -DLANG_DE
+monitor_filters =
+    esp32_exception_decoder, colorize
+
+[env:opendtufusion-ethernet-16MB]
+platform = espressif32@6.6.0
+board = esp32-s3-devkitc-1
+board_upload.flash_size = 16MB
+upload_protocol = esp-builtin
+build_flags = ${env:opendtufusion-ethernet.build_flags}
+monitor_filters =
+    esp32_exception_decoder, colorize
+
+[env:opendtufusion-ethernet-16MB-de]
+platform = espressif32@6.6.0
+board = esp32-s3-devkitc-1
+upload_protocol = esp-builtin
+build_flags = ${env:opendtufusion-ethernet-16MB.build_flags}
+    -DLANG_DE
+monitor_filters =
+    esp32_exception_decoder, colorize

From dcb4b49fa02909574305abfa7a1422025a34ae18 Mon Sep 17 00:00:00 2001
From: lumapu <lp@lufami.de>
Date: Wed, 10 Jul 2024 23:13:43 +0200
Subject: [PATCH 8/8] 0.8.128 * add environments for 16MB flash size ESP32-S3
 aka opendtufusion * prevent duplicate alarms, update end time once it is
 received

---
 src/CHANGES.md                  |  3 ++-
 src/hm/hmInverter.h             | 21 ++++++++++++++++++++-
 src/web/html/visualization.html |  2 +-
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/CHANGES.md b/src/CHANGES.md
index e93e7f02..dfd4ca2a 100644
--- a/src/CHANGES.md
+++ b/src/CHANGES.md
@@ -1,7 +1,8 @@
 # Development Changes
 
-## 0.8.128 - 2024-07-02
+## 0.8.128 - 2024-07-10
 * add environments for 16MB flash size ESP32-S3 aka opendtufusion
+* prevent duplicate alarms, update end time once it is received
 
 ## 0.8.127 - 2024-06-21
 * add grid file #1677
diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h
index b72ec5ab..e1b99bc8 100644
--- a/src/hm/hmInverter.h
+++ b/src/hm/hmInverter.h
@@ -670,7 +670,6 @@ class Inverter {
             DPRINTLN(DBG_DEBUG, "Alarm #" + String(pyld[startOff+1]) + " '" + String(getAlarmStr(pyld[startOff+1])) + "' start: " + ah::getTimeStr(start) + ", end: " + ah::getTimeStr(endTime));
             addAlarm(pyld[startOff+1], start, endTime);
 
-            alarmCnt++;
             alarmLastId = alarmMesIndex;
 
             return pyld[startOff+1];
@@ -818,6 +817,26 @@ class Inverter {
 
     private:
         inline void addAlarm(uint16_t code, uint32_t start, uint32_t end) {
+            bool found = false;
+            uint8_t i = 0;
+
+            if(start > end)
+                end = 0;
+
+            for(; i < 10; i++) {
+                mAlarmNxtWrPos = (++mAlarmNxtWrPos) % 10;
+
+                if(lastAlarm[mAlarmNxtWrPos].code == code && lastAlarm[mAlarmNxtWrPos].start == start) {
+                    // replace with same or update end time
+                    if(lastAlarm[mAlarmNxtWrPos].end == 0 || lastAlarm[mAlarmNxtWrPos].end == end) {
+                        break;
+                    }
+                }
+            }
+
+            if(alarmCnt < 10 && alarmCnt < mAlarmNxtWrPos)
+                alarmCnt = mAlarmNxtWrPos + 1;
+
             lastAlarm[mAlarmNxtWrPos] = alarm_t(code, start, end);
             if(++mAlarmNxtWrPos >= 10) // rolling buffer
                 mAlarmNxtWrPos = 0;
diff --git a/src/web/html/visualization.html b/src/web/html/visualization.html
index 0fdaf89e..507a6f9f 100644
--- a/src/web/html/visualization.html
+++ b/src/web/html/visualization.html
@@ -276,7 +276,7 @@
                                 ml("div", {class: "col mt-3"}, String(a.str)),
                                 ml("div", {class: "col mt-3"}, String(a.code)),
                                 ml("div", {class: "col mt-3"}, String(toIsoTimeStr(new Date((a.start + offs) * 1000)))),
-                                ml("div", {class: "col mt-3"}, String(toIsoTimeStr(new Date((a.end + offs) * 1000))))
+                                ml("div", {class: "col mt-3"}, (a.end == 0) ? "-" : String(toIsoTimeStr(new Date((a.end + offs) * 1000))))
                             ])
                         );
                     }