From fe4aa83ed2353ea741af5347119365b1859a5b95 Mon Sep 17 00:00:00 2001 From: Shailen Sobhee Date: Mon, 30 Mar 2026 22:41:08 +0200 Subject: [PATCH] updated code logic to pic FW/App version from appversion instead of hard-coding in js/html/cpp files --- app_version.py | 32 ++++++++ data-src/appversion | 2 +- data-src/index.html | 8 +- data-src/index.js | 32 +++++++- platformio.ini | 4 +- src/ConfigSettings.h | 6 +- src/SomfyController.ino | 2 + src/SomfyController.ino.cpp | 147 ------------------------------------ 8 files changed, 78 insertions(+), 155 deletions(-) create mode 100644 app_version.py delete mode 100644 src/SomfyController.ino.cpp diff --git a/app_version.py b/app_version.py new file mode 100644 index 0000000..533442a --- /dev/null +++ b/app_version.py @@ -0,0 +1,32 @@ +import os +Import("env") + +# Define the folder and filename +DATA_FOLDER = "data-src" +FILENAME = "appversion" + +# Construct the full path: /your/project/path/data-src/appversion +project_dir = env.get("PROJECT_DIR") +version_file_path = os.path.join(project_dir, DATA_FOLDER, FILENAME) + +# Default fallback if something goes wrong +version = "0.0.0" + +if os.path.exists(version_file_path): + try: + with open(version_file_path, "r") as f: + version = f.read().strip() + # Clean output for the PlatformIO console + print(f"--- SUCCESS: Found version {version} in {version_file_path} ---") + except Exception as e: + print(f"--- ERROR: could not read version file: {e} ---") +else: + print(f"--- ERROR: File NOT FOUND at {version_file_path} ---") + +# Apply to the build environment +# We use escaped quotes so C++ treats it as a string literal "vX.X.X" +full_version_str = f'\\"v{version}\\"' + +env.Append(CPPDEFINES=[ + ("FW_VERSION", full_version_str) +]) \ No newline at end of file diff --git a/data-src/appversion b/data-src/appversion index 752a79e..fad066f 100644 --- a/data-src/appversion +++ b/data-src/appversion @@ -1 +1 @@ -2.4.8 \ No newline at end of file +2.5.0 \ No newline at end of file diff --git a/data-src/index.html b/data-src/index.html index e46ab30..4e3383b 100644 --- a/data-src/index.html +++ b/data-src/index.html @@ -8,9 +8,9 @@ - - - + + + @@ -114,7 +114,7 @@ rel="apple-touch-startup-image"> - +
diff --git a/data-src/index.js b/data-src/index.js index 244816e..b7654a1 100644 --- a/data-src/index.js +++ b/data-src/index.js @@ -1267,9 +1267,27 @@ class Security { } var security = new Security(); +// let appVersion = 'v0.0.0'; // Default placeholder +async function getAppVersion() { + try { + const response = await fetch('/appversion'); + if (!response.ok) throw new Error('File not found'); + + const data = await response.text(); + appVersion = `v${data.trim()}`; + + console.log("Loaded Version:", appVersion); + // Trigger any UI updates here + } catch (error) { + console.error("Error loading App version:", error); + appVersion = 'v0.0.0'; // Default placeholder + } + return appVersion; +} + class General { initialized = false; - appVersion = 'v2.4.8'; + appVersion = getAppVersion(); reloadApp = false; init() { if (this.initialized) return; @@ -4815,3 +4833,15 @@ class Firmware { } var firmware = new Firmware(); +window.addEventListener('load', async () => { + // 1. Initialize your main application logic + // await init(); + + // 2. Fetch and display the app version + appVersion = await getAppVersion(); + const spanAppVersion = document.getElementById('spanAppVersion'); + spanAppVersion.innerText = `${appVersion.trim()}`; + + console.log("Application fully loaded and version updated."); +}); + diff --git a/platformio.ini b/platformio.ini index 0913212..3f5e5ec 100644 --- a/platformio.ini +++ b/platformio.ini @@ -23,11 +23,12 @@ lib_deps = esp32async/ESPAsyncWebServer@^3.10.3 esp32async/AsyncTCP@^3.4.10 extra_scripts = + pre:app_version.py pre:minify.py post:archive_elf.py board_build.filesystem = littlefs build_flags = - -DCORE_DEBUG_LEVEL=1 + -DCORE_DEBUG_LEVEL=5 -DCONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=1 -DCONFIG_ESP_COREDUMP_DATA_FORMAT_ELF=1 -DCONFIG_ESP_COREDUMP_CHECKSUM_CRC32=1 @@ -57,6 +58,7 @@ board = esp32-s3-devkitc-1 [env:esp32c6] board = seeed_xiao_esp32c6 +build_type = debug board_build.partitions = esp32_huge_app.csv build_flags = ${env.build_flags} diff --git a/src/ConfigSettings.h b/src/ConfigSettings.h index bdd62a7..3fdc33c 100644 --- a/src/ConfigSettings.h +++ b/src/ConfigSettings.h @@ -5,7 +5,11 @@ #ifndef configsettings_h #define configsettings_h #include "WResp.h" -#define FW_VERSION "v2.4.8" +// #define FW_VERSION "v2.4.8" +#ifndef FW_VERSION + #define FW_VERSION "v0.0.0" // Fallback if app_version.py script fails +#endif + enum class conn_types_t : byte { unset = 0x00, wifi = 0x01, diff --git a/src/SomfyController.ino b/src/SomfyController.ino index 976bb44..64840f6 100644 --- a/src/SomfyController.ino +++ b/src/SomfyController.ino @@ -92,8 +92,10 @@ void setup() { #if ESP_ARDUINO_VERSION_MAJOR >= 3 const esp_task_wdt_config_t wdt_config = { .timeout_ms = 15000, .idle_core_mask = 1, .trigger_panic = true }; esp_task_wdt_init(&wdt_config); + ESP_LOGE(TAG, "TEST 1"); #else esp_task_wdt_init(15, true); //enable panic so ESP32 restarts + ESP_LOGE(TAG, "TEST 2"); #endif esp_task_wdt_add(NULL); //add current thread to WDT watch diff --git a/src/SomfyController.ino.cpp b/src/SomfyController.ino.cpp deleted file mode 100644 index ce50111..0000000 --- a/src/SomfyController.ino.cpp +++ /dev/null @@ -1,147 +0,0 @@ -# 1 "C:\\Users\\oem\\AppData\\Local\\Temp\\tmpahrx2jqr" -#include -# 1 "C:/Users/oem/Documents/PlatformIO/Projects/ESPSomfy-RTS/src/SomfyController.ino" -#include "esp_log.h" -#include -#include -#include -#include "ConfigSettings.h" -#include "ESPNetwork.h" -#include "Web.h" -#include "Sockets.h" -#include "Utils.h" -#include "Somfy.h" -#include "MQTT.h" -#include "GitOTA.h" -#include "esp_core_dump.h" - -static const char *TAG = "Main"; - -ConfigSettings settings; -Web webServer; -SocketEmitter sockEmit; -ESPNetwork net; -rebootDelay_t rebootDelay; -SomfyShadeController somfy; -MQTTClass mqtt; -GitUpdater git; - -uint32_t oldheap = 0; -void listDir(const char *dirname, uint8_t levels); -void setup(); -void loop(); -#line 28 "C:/Users/oem/Documents/PlatformIO/Projects/ESPSomfy-RTS/src/SomfyController.ino" -void listDir(const char *dirname, uint8_t levels) { - ESP_LOGI(TAG, "Listing: %s", dirname); - File root = LittleFS.open(dirname); - if (!root || !root.isDirectory()) { - ESP_LOGE(TAG, "Failed to open directory"); - return; - } - File file = root.openNextFile(); - while (file) { - if (file.isDirectory()) { - ESP_LOGI(TAG, " DIR : %s", file.name()); - if (levels) listDir(file.path(), levels - 1); - } else { - ESP_LOGI(TAG, " FILE: %-30s %d bytes", file.name(), file.size()); - } - file = root.openNextFile(); - } -} - -void setup() { - Serial.begin(115200); - ESP_LOGI(TAG, "Startup/Boot...."); - esp_core_dump_summary_t summary; - if (esp_core_dump_get_summary(&summary) == ESP_OK) { - ESP_LOGW(TAG, "*** Previous crash coredump found ***"); - ESP_LOGW(TAG, " Task: %s", summary.exc_task); - ESP_LOGW(TAG, " PC: 0x%08x", summary.exc_pc); -#ifdef CONFIG_IDF_TARGET_ARCH_XTENSA - ESP_LOGW(TAG, " Cause: %d", summary.ex_info.exc_cause); - char bt_buf[256] = {0}; - int pos = 0; - for (int i = 0; i < summary.exc_bt_info.depth; i++) { - pos += snprintf(bt_buf + pos, sizeof(bt_buf) - pos, " 0x%08x", summary.exc_bt_info.bt[i]); - } - ESP_LOGW(TAG, " Backtrace:%s", bt_buf); -#elif CONFIG_IDF_TARGET_ARCH_RISCV - ESP_LOGW(TAG, " Cause: %d", summary.ex_info.mcause); - ESP_LOGW(TAG, " MTVAL: 0x%08x RA: 0x%08x SP: 0x%08x", - summary.ex_info.mtval, summary.ex_info.ra, summary.ex_info.sp); -#endif - } - ESP_LOGI(TAG, "Mounting File System..."); - - - if (LittleFS.begin()) { - ESP_LOGI(TAG, "Total: %d bytes", LittleFS.totalBytes()); - ESP_LOGI(TAG, "Used: %d bytes", LittleFS.usedBytes()); - ESP_LOGI(TAG, "Free: %d bytes", LittleFS.totalBytes() - LittleFS.usedBytes()); - listDir("/", 3); - } else { - ESP_LOGE(TAG, "LittleFS mount failed!"); - } - - if(LittleFS.begin()) ESP_LOGI(TAG, "File system mounted successfully"); - else ESP_LOGE(TAG, "Error mounting file system"); - settings.begin(); - if(WiFi.status() == WL_CONNECTED) WiFi.disconnect(true); - delay(10); - webServer.startup(); - webServer.begin(); - delay(1000); - net.setup(); - somfy.begin(); - -#if ESP_ARDUINO_VERSION_MAJOR >= 3 - const esp_task_wdt_config_t wdt_config = { .timeout_ms = 15000, .idle_core_mask = 1, .trigger_panic = true }; - esp_task_wdt_init(&wdt_config); -#else - esp_task_wdt_init(15, true); -#endif - esp_task_wdt_add(NULL); - -} - -void loop() { - - - if(rebootDelay.reboot && millis() > rebootDelay.rebootTime) { - ESP_LOGI(TAG, "Rebooting after %lums", rebootDelay.rebootTime); - net.end(); - ESP.restart(); - return; - } - uint32_t timing = millis(); - - net.loop(); - if(millis() - timing > 100) ESP_LOGD(TAG, "Timing Net: %ldms", millis() - timing); - timing = millis(); - esp_task_wdt_reset(); - somfy.loop(); - if(millis() - timing > 100) ESP_LOGD(TAG, "Timing Somfy: %ldms", millis() - timing); - timing = millis(); - esp_task_wdt_reset(); - if(net.connected() || net.softAPOpened) { - if(!rebootDelay.reboot && net.connected() && !net.softAPOpened) { - git.loop(); - esp_task_wdt_reset(); - } - webServer.loop(); - esp_task_wdt_reset(); - if(millis() - timing > 100) ESP_LOGD(TAG, "Timing WebServer: %ldms", millis() - timing); - esp_task_wdt_reset(); - timing = millis(); - sockEmit.loop(); - if(millis() - timing > 100) ESP_LOGD(TAG, "Timing Socket: %ldms", millis() - timing); - esp_task_wdt_reset(); - timing = millis(); - } - if(rebootDelay.reboot && millis() > rebootDelay.rebootTime) { - net.end(); - ESP.restart(); - } - esp_task_wdt_reset(); -} \ No newline at end of file