updated code logic to pic FW/App version from appversion instead of hard-coding in js/html/cpp files

This commit is contained in:
Shailen Sobhee 2026-03-30 22:41:08 +02:00
parent bb61a1703d
commit fe4aa83ed2
8 changed files with 78 additions and 155 deletions

32
app_version.py Normal file
View file

@ -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)
])

View file

@ -1 +1 @@
2.4.8
2.5.0

View file

@ -8,9 +8,9 @@
<meta name="apple-mobile-web-app-title" content="ESPSomfy RTS App">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet" href="main.css?v=2.4.8c" type="text/css" />
<link rel="stylesheet" href="widgets.css?v=2.4.8c" type="text/css" />
<link rel="stylesheet" href="icons.css?v=2.4.8c" type="text/css" />
<link rel="stylesheet" href="main.css" type="text/css" />
<link rel="stylesheet" href="widgets.css" type="text/css" />
<link rel="stylesheet" href="icons.css" type="text/css" />
<link rel="icon" type="image/png" href="favicon.png" />
<!-- iPad retina icon -->
@ -114,7 +114,7 @@
rel="apple-touch-startup-image">
<script type="text/javascript" src="index.js?v=2.4.8c"></script>
<script type="text/javascript" src="index.js"></script>
</head>
<body>
<div id="divContainer" class="container main" data-auth="false">

View file

@ -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.");
});

View file

@ -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}

View file

@ -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,

View file

@ -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

View file

@ -1,147 +0,0 @@
# 1 "C:\\Users\\oem\\AppData\\Local\\Temp\\tmpahrx2jqr"
#include <Arduino.h>
# 1 "C:/Users/oem/Documents/PlatformIO/Projects/ESPSomfy-RTS/src/SomfyController.ino"
#include "esp_log.h"
#include <WiFi.h>
#include <LittleFS.h>
#include <esp_task_wdt.h>
#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();
}