From 437173854f073c4b07b75f0bacae19e6d458115c Mon Sep 17 00:00:00 2001 From: lumapu Date: Sat, 18 May 2024 14:04:17 +0200 Subject: [PATCH 1/6] 0.8.120 * fix crash if invalid serial number was set --- src/CHANGES.md | 3 +++ src/defines.h | 2 +- src/hm/hmSystem.h | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index 1cef0a8a..8bdd6c40 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,8 @@ # Development Changes +## 0.8.120 - 2024-05-18 +* fix crash if invalid serial number was set + ## 0.8.119 - 2024-05-17 * fix reset values at midnight if WiFi isn't available #1620 * fix typo in English versions diff --git a/src/defines.h b/src/defines.h index 3e7adc01..7a91ac1d 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 119 +#define VERSION_PATCH 120 //------------------------------------- typedef struct { uint8_t ch; diff --git a/src/hm/hmSystem.h b/src/hm/hmSystem.h index 0e86881d..e6274696 100644 --- a/src/hm/hmSystem.h +++ b/src/hm/hmSystem.h @@ -74,6 +74,7 @@ class HmSystem { iv->ivRadioType = INV_RADIO_TYPE_CMT; } else if(iv->config->serial.u64 != 0ULL) { DPRINTLN(DBG_ERROR, F("inverter type can't be detected!")); + iv->config = nullptr; return; } else iv->ivGen = IV_UNKNOWN; @@ -116,6 +117,8 @@ class HmSystem { DPRINTLN(DBG_VERBOSE, F("hmSystem.h:getInverterByPos")); if(pos >= MAX_INVERTER) return nullptr; + else if(nullptr == mInverter[pos].config) + return nullptr; else if((mInverter[pos].config->serial.u64 != 0ULL) || (false == check)) return &mInverter[pos]; else From c0713a263deb72e337d2abb50b5b1990babc5659 Mon Sep 17 00:00:00 2001 From: lumapu Date: Sat, 18 May 2024 23:14:29 +0200 Subject: [PATCH 2/6] 0.8.120 * fix factory generation for ESP32-S3 --- manual/factory_firmware.md | 4 ++-- scripts/add_littlefs_binary.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/manual/factory_firmware.md b/manual/factory_firmware.md index f5cd3d91..354bbeb9 100644 --- a/manual/factory_firmware.md +++ b/manual/factory_firmware.md @@ -49,10 +49,10 @@ Windows: ### ESP32-S3 (OpenDTU Fusion Board) Python: -`esptool.py -b 921600 write_flash --flash_mode dio --flash_size detect 0x0 firmware.factory.bin` +`esptool.py -b 921600 write_flash --flash_mode dio --flash_size detect 0x10000 firmware.factory.bin` Windows: -`esptool.exe -b 921600 write_flash --flash_mode dio --flash_size detect 0x0 firmware.factory.bin` +`esptool.exe -b 921600 write_flash --flash_mode dio --flash_size detect 0x10000 firmware.factory.bin` For a 4MB flash size the upload should be finished within 22 seconds. diff --git a/scripts/add_littlefs_binary.py b/scripts/add_littlefs_binary.py index 7afc3391..db766f45 100644 --- a/scripts/add_littlefs_binary.py +++ b/scripts/add_littlefs_binary.py @@ -13,17 +13,18 @@ def build_littlefs(): print("LittleFS build successful") def merge_bins(): - flash_size = int(env.get("BOARD_FLASH_SIZE", "4MB").replace("MB", "")) + flash_size = int(env.BoardConfig().get("upload.maximum_size", "4194304")) app0_offset = 0x10000 if env['PIOENV'][:7] == "esp8266": app0_offset = 0 elif env['PIOENV'][:7] == "esp8285": app0_offset = 0 + print(flash_size) littlefs_offset = 0x290000 - if flash_size == 8: + if flash_size == 0x330000: littlefs_offset = 0x670000 - elif flash_size == 16: + elif flash_size == 0x640000: littlefs_offset = 0xc90000 # save current wd From b51ba5639b40ca3640932e645d1a91dd296d19bb Mon Sep 17 00:00:00 2001 From: lumapu Date: Sun, 19 May 2024 00:20:53 +0200 Subject: [PATCH 3/6] 0.8.120 * fix crash if invalid serial number was set -> inverter will be disabled automatically * improved and fixed factory image generation --- src/CHANGES.md | 3 ++- src/hm/hmSystem.h | 2 +- src/platformio.ini | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index 8bdd6c40..34ced30b 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,7 +1,8 @@ # Development Changes ## 0.8.120 - 2024-05-18 -* fix crash if invalid serial number was set +* fix crash if invalid serial number was set -> inverter will be disabled automatically +* improved and fixed factory image generation ## 0.8.119 - 2024-05-17 * fix reset values at midnight if WiFi isn't available #1620 diff --git a/src/hm/hmSystem.h b/src/hm/hmSystem.h index e6274696..cb4103bd 100644 --- a/src/hm/hmSystem.h +++ b/src/hm/hmSystem.h @@ -74,7 +74,7 @@ class HmSystem { iv->ivRadioType = INV_RADIO_TYPE_CMT; } else if(iv->config->serial.u64 != 0ULL) { DPRINTLN(DBG_ERROR, F("inverter type can't be detected!")); - iv->config = nullptr; + iv->config->enabled = false; return; } else iv->ivGen = IV_UNKNOWN; diff --git a/src/platformio.ini b/src/platformio.ini index 9f226af0..30436414 100644 --- a/src/platformio.ini +++ b/src/platformio.ini @@ -23,7 +23,7 @@ extra_scripts = pre:../scripts/convertHtml.py pre:../scripts/applyPatches.py pre:../scripts/reduceGxEPD2.py - #post:../scripts/add_littlefs_binary.py + post:../scripts/add_littlefs_binary.py lib_deps = https://github.com/esphome/ESPAsyncWebServer @ ^3.2.0 From 8c7bb9358e9f9e5ee8c18e6e40160446f4236ab5 Mon Sep 17 00:00:00 2001 From: lumapu Date: Sun, 19 May 2024 01:33:29 +0200 Subject: [PATCH 4/6] 0.8.120 * improved and fixed factory image generation * fix HMT-1800-4T number of inputs #1628 --- manual/factory_firmware.md | 35 ++++++++++------------------------ scripts/add_littlefs_binary.py | 28 +++++++++++++++++++++++---- src/CHANGES.md | 1 + src/hm/hmSystem.h | 8 ++++++-- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/manual/factory_firmware.md b/manual/factory_firmware.md index 354bbeb9..a4025eea 100644 --- a/manual/factory_firmware.md +++ b/manual/factory_firmware.md @@ -10,7 +10,7 @@ First install on the requested platform the standard firmware and configure ever First create a directory `data` inside the following project path: `src/`. -As the export removes all your password you need to add them again to the `json` file. Open the `json` file with a text editor and search for all the `"pwd": ""`. Between the second bunch of quotation marks you have to place the password. +As the export removes all your passwords you need to add them again to the `json` file. Open the `json` file with a text editor and search for all the `"pwd":""` sections. Between the second bunch of quotation marks you have to place the password. *Note: It's recommended to keep all information in one line to save space on the ESP littlefs partition* @@ -26,35 +26,21 @@ ahoy ... ``` -## modify platform.ini to build factory binary - -Open the file `src/platformio.ini` and uncomment the following line `#post:../scripts/add_littlefs_binary.py` (remove the `#`) - ## build firmware Choose your prefered environment and build firmware as usual. Once the process is finished you should find along with the standard `firmware.bin` an additional file called `firmware.factory.bin`. Both files are located here: `src/.pio/build/[ENVIRONMENT]/` ## Upload to device -Navigate to the firmware output directory `src/.pio/build/[ENVIRONMENT]/` and open a terminal. - -### ESP32 - -Python: -`esptool.py -b 921600 write_flash --flash_mode dio --flash_size detect 0x1000 bootloader.bin 0x8000 partitions.bin 0x10000 firmware.factory.bin` - -Windows: -`esptool.exe -b 921600 write_flash --flash_mode dio --flash_size detect 0x1000 bootloader.bin 0x8000 partitions.bin 0x10000 firmware.factory.bin` - -### ESP32-S3 (OpenDTU Fusion Board) +Navigate to the firmware output directory `src/.pio/build/[ENVIRONMENT]/` and open a terminal or vice versa. Python: -`esptool.py -b 921600 write_flash --flash_mode dio --flash_size detect 0x10000 firmware.factory.bin` +`esptool.py -b 921600 write_flash --flash_mode dio --flash_size detect 0x0 firmware.factory.bin` Windows: -`esptool.exe -b 921600 write_flash --flash_mode dio --flash_size detect 0x10000 firmware.factory.bin` +`esptool.exe -b 921600 write_flash --flash_mode dio --flash_size detect 0x0 firmware.factory.bin` -For a 4MB flash size the upload should be finished within 22 seconds. +The upload should be finished within one minute. ## Testing @@ -62,10 +48,9 @@ Reboot your ESP an check if all your settings are present. ## Keep updated with 'Mainline' -From time to time a new version of AhoyDTU will be published. To get this changes into your alread prepared factory binary generation environment you have to do only a few steps: +From time to time a new version of AhoyDTU will be published. To get the changes into your already prepared factory binary generation environment you have to do only a few steps: -1. revert the changes of `platformio.ini` by executing from repository root: `git checkout src/platformio.ini` -2. pull new changes from remote: `git pull` -3. modify the `platformio.ini` again as you can read above (remove comment) -4. build and upload -5. enjoy +1. pull new changes from remote: `git pull` +2. check if the `data` folder is still there and contains the `settings.json` +3. build and upload +4. enjoy diff --git a/scripts/add_littlefs_binary.py b/scripts/add_littlefs_binary.py index db766f45..8f6556f9 100644 --- a/scripts/add_littlefs_binary.py +++ b/scripts/add_littlefs_binary.py @@ -1,10 +1,13 @@ import os import subprocess import shutil +from SCons.Script import DefaultEnvironment Import("env") def build_littlefs(): + if os.path.isfile('data/settings.json') == False: + return # nothing to do result = subprocess.run(["pio", "run", "--target", "buildfs", "--environment", env['PIOENV']]) if result.returncode != 0: print("Error building LittleFS:") @@ -13,6 +16,13 @@ def build_littlefs(): print("LittleFS build successful") def merge_bins(): + if os.path.isfile('data/settings.json') == False: + return # nothing to do + + BOOTLOADER_OFFSET = 0x0000 + PARTITIONS_OFFSET = 0x8000 + FIRMWARE_OFFSET = 0x10000 + flash_size = int(env.BoardConfig().get("upload.maximum_size", "4194304")) app0_offset = 0x10000 if env['PIOENV'][:7] == "esp8266": @@ -31,6 +41,12 @@ def merge_bins(): start = os.getcwd() os.chdir('.pio/build/' + env['PIOENV'] + '/') + with open("bootloader.bin", "rb") as bootloader_file: + bootloader_data = bootloader_file.read() + + with open("partitions.bin", "rb") as partitions_file: + partitions_data = partitions_file.read() + with open("firmware.bin", "rb") as firmware_file: firmware_data = firmware_file.read() @@ -38,11 +54,16 @@ def merge_bins(): littlefs_data = littlefs_file.read() with open("firmware.factory.bin", "wb") as merged_file: - # fill gap with 0xff + merged_file.write(b'\xFF' * BOOTLOADER_OFFSET) + merged_file.write(bootloader_data) + + merged_file.write(b'\xFF' * (PARTITIONS_OFFSET - (BOOTLOADER_OFFSET + len(bootloader_data)))) + merged_file.write(partitions_data) + + merged_file.write(b'\xFF' * (FIRMWARE_OFFSET - (PARTITIONS_OFFSET + len(partitions_data)))) merged_file.write(firmware_data) - if len(firmware_data) < (littlefs_offset - app0_offset): - merged_file.write(b'\xFF' * ((littlefs_offset - app0_offset) - len(firmware_data))) + merged_file.write(b'\xFF' * (littlefs_offset - (FIRMWARE_OFFSET + len(firmware_data)))) merged_file.write(littlefs_data) os.chdir(start) @@ -51,6 +72,5 @@ def main(target, source, env): build_littlefs() merge_bins() - # ensure that script is called once firmeware was compiled env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", main) diff --git a/src/CHANGES.md b/src/CHANGES.md index 34ced30b..93e0d834 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -3,6 +3,7 @@ ## 0.8.120 - 2024-05-18 * fix crash if invalid serial number was set -> inverter will be disabled automatically * improved and fixed factory image generation +* fix HMT-1800-4T number of inputs #1628 ## 0.8.119 - 2024-05-17 * fix reset values at midnight if WiFi isn't available #1620 diff --git a/src/hm/hmSystem.h b/src/hm/hmSystem.h index cb4103bd..81507105 100644 --- a/src/hm/hmSystem.h +++ b/src/hm/hmSystem.h @@ -69,9 +69,13 @@ class HmSystem { iv->ivRadioType = INV_RADIO_TYPE_NRF; } } else if(iv->config->serial.b[5] == 0x13) { - iv->ivGen = IV_HMT; + iv->ivGen = IV_HMT; + if(iv->config->serial.b[4] == 0x61) + iv->type = INV_TYPE_4CH; + else iv->type = INV_TYPE_6CH; - iv->ivRadioType = INV_RADIO_TYPE_CMT; + + iv->ivRadioType = INV_RADIO_TYPE_CMT; } else if(iv->config->serial.u64 != 0ULL) { DPRINTLN(DBG_ERROR, F("inverter type can't be detected!")); iv->config->enabled = false; From 267d2dae26b8e3714d43ff52c2b330120ee892c4 Mon Sep 17 00:00:00 2001 From: lumapu Date: Mon, 20 May 2024 12:09:43 +0200 Subject: [PATCH 5/6] 0.8.121 * fix ESP32 factory image generation --- scripts/add_littlefs_binary.py | 7 +++++-- src/CHANGES.md | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/add_littlefs_binary.py b/scripts/add_littlefs_binary.py index 8f6556f9..ffc948cb 100644 --- a/scripts/add_littlefs_binary.py +++ b/scripts/add_littlefs_binary.py @@ -8,6 +8,7 @@ Import("env") def build_littlefs(): if os.path.isfile('data/settings.json') == False: return # nothing to do + result = subprocess.run(["pio", "run", "--target", "buildfs", "--environment", env['PIOENV']]) if result.returncode != 0: print("Error building LittleFS:") @@ -23,14 +24,16 @@ def merge_bins(): PARTITIONS_OFFSET = 0x8000 FIRMWARE_OFFSET = 0x10000 - flash_size = int(env.BoardConfig().get("upload.maximum_size", "4194304")) + if env['PIOENV'][:13] == "esp32-wroom32": + BOOTLOADER_OFFSET = 0x1000 + + flash_size = int(env.BoardConfig().get("upload.maximum_size", "1310720")) # 0x140000 app0_offset = 0x10000 if env['PIOENV'][:7] == "esp8266": app0_offset = 0 elif env['PIOENV'][:7] == "esp8285": app0_offset = 0 - print(flash_size) littlefs_offset = 0x290000 if flash_size == 0x330000: littlefs_offset = 0x670000 diff --git a/src/CHANGES.md b/src/CHANGES.md index 93e0d834..9bc01cd3 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -1,5 +1,8 @@ # Development Changes +## 0.8.121 - 2024-05-20 +* fix ESP32 factory image generation + ## 0.8.120 - 2024-05-18 * fix crash if invalid serial number was set -> inverter will be disabled automatically * improved and fixed factory image generation From 6b7914624daab75b329714690ccc10ac1b659913 Mon Sep 17 00:00:00 2001 From: lumapu Date: Mon, 20 May 2024 13:35:48 +0200 Subject: [PATCH 6/6] 0.8.121 * fix plot of history graph #1635 --- src/CHANGES.md | 1 + src/defines.h | 2 +- src/web/html/history.html | 20 ++++++++------------ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index 9bc01cd3..a1b23dbc 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -2,6 +2,7 @@ ## 0.8.121 - 2024-05-20 * fix ESP32 factory image generation +* fix plot of history graph #1635 ## 0.8.120 - 2024-05-18 * fix crash if invalid serial number was set -> inverter will be disabled automatically diff --git a/src/defines.h b/src/defines.h index 7a91ac1d..a83d4e89 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 120 +#define VERSION_PATCH 121 //------------------------------------- typedef struct { uint8_t ch; diff --git a/src/web/html/history.html b/src/web/html/history.html index 08227b1f..9e15daa8 100644 --- a/src/web/html/history.html +++ b/src/web/html/history.html @@ -43,13 +43,10 @@ function calcScale(obj) { let s = {} s.x_mul = 60 - s.ts_start = obj.lastValueTs - (obj.refresh * obj.value.length) - s.ts_dur = obj.lastValueTs - s.ts_start - s.ts_pad = (s.ts_dur < 1800) ? 0 : s.ts_start % 1800 - s.ts_dur += s.ts_pad + s.ts_dur = obj.refresh * obj.value.length + s.ts_start = obj.lastValueTs - s.ts_dur while(s.x_mul * 10 <= s.ts_dur) s.x_mul += (s.x_mul == 60) ? 240 : ((s.x_mul < 1800) ? 300 : 1800) - s.x_step = Math.ceil(s.ts_dur / s.x_mul) s.y_mul = 10 while(s.y_mul * 10 <= obj.max) @@ -91,8 +88,8 @@ } div = x2 / scale.ts_dur for(let i = 0; i < scale.ts_dur; i++) { - if(i % scale.x_mul == 0) { - let d = new Date((scale.ts_start - scale.ts_pad + i) * 1000) + if((i + scale.ts_start) % scale.x_mul == 0) { + let d = new Date((scale.ts_start + i) * 1000) g.push(mlNs("text", {x: (i*div)+17, y: height+20}, ("0"+d.getHours()).slice(-2) + ":" + ("0"+d.getMinutes()).slice(-2))) } } @@ -107,7 +104,7 @@ } div = x2 / scale.ts_dur for(let i = 0; i <= scale.ts_dur; i++) { - if(i % scale.x_mul == 0) { + if((i + scale.ts_start) % scale.x_mul == 0) { g.push(mlNs("line", {x1: (i*div), x2: (i*div), y1: 0, y2: height, "stroke-width": 1, "stroke-dasharray": "1,3", stroke: "#aaa"})) } } @@ -118,16 +115,15 @@ let pts = "" let i = 0, first = -1, last = -1, lastVal = 0 let div = scale.y_max / height - let xOff = x2 / scale.ts_dur * scale.ts_pad if(div == 0) div = 1 for (val of obj.value) { if(val > 0) { lastVal = val - pts += " " + String(i + xOff) + "," + String(height - val / div) + pts += " " + String(i) + "," + String(height - val / div) if(first < 0) - first = i + xOff - last = i + xOff + first = i + last = i } i += 2 }