From 8199b283c07a2607f71fc8361885deb57580062a Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Fri, 21 Feb 2025 11:53:59 +0100 Subject: [PATCH 1/5] feat: add API endpoint for version retrieval and update HTML to display dynamic version --- .github/workflows/providers/gitea-release.yml | 88 +++++++++-------- .../workflows/providers/github-release.yml | 95 +++++++++++-------- html/header.html | 15 ++- html/index.html | 15 ++- html/rfid.html | 15 ++- html/spoolman.html | 15 ++- html/upgrade.html | 15 ++- html/waage.html | 15 ++- html/wifi.html | 15 ++- platformio.ini | 33 ++----- src/website.cpp | 6 ++ 11 files changed, 219 insertions(+), 108 deletions(-) diff --git a/.github/workflows/providers/gitea-release.yml b/.github/workflows/providers/gitea-release.yml index c7ca805..1292af9 100644 --- a/.github/workflows/providers/gitea-release.yml +++ b/.github/workflows/providers/gitea-release.yml @@ -37,44 +37,51 @@ jobs: sudo apt-get update sudo apt-get install xxd + - name: Check for SPIFFS changes + id: check_spiffs + run: | + git fetch --unshallow || true + CHANGED_FILES=$(git diff --name-only HEAD^..HEAD) + if echo "$CHANGED_FILES" | grep -q "^data/\|^html/"; then + echo "SPIFFS_CHANGED=true" >> $GITHUB_OUTPUT + else + echo "SPIFFS_CHANGED=false" >> $GITHUB_OUTPUT + fi + - name: Build Firmware run: | - pio run -e esp32dev -t buildfs # Build SPIFFS - pio run -e esp32dev # Build firmware - cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman.bin - cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/filaman_spiffs.bin + # Get version from platformio.ini + VERSION=$(grep '^version = ' platformio.ini | cut -d'"' -f2) + + # Always build firmware + pio run -e esp32dev + cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman_${VERSION}.bin + + # Only build SPIFFS if changed + if [[ "${{ steps.check_spiffs.outputs.SPIFFS_CHANGED }}" == "true" ]]; then + echo "Building SPIFFS due to changes..." + cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/webpage_${VERSION}.bin + fi - name: Prepare binaries run: | - # Ensure we're in the project root - cd $GITHUB_WORKSPACE - - # Create SPIFFS directory if it doesn't exist - mkdir -p .pio/build/esp32dev/spiffs - - # Copy firmware to SPIFFS directory - cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/spiffs/firmware.bin - - # Build new SPIFFS image with firmware included - pio run -t buildfs - cd .pio/build/esp32dev + VERSION=$(grep '^version = ' ../../platformio.ini | cut -d'"' -f2) - # Create release files - cp spiffs.bin filaman_spiffs.bin - - # Create full binary - echo "Creating full binary..." - esptool.py --chip esp32 merge_bin \ - --fill-flash-size 4MB \ - --flash_mode dio \ - --flash_freq 40m \ - --flash_size 4MB \ - -o filaman_full.bin \ - 0x0000 bootloader.bin \ - 0x8000 partitions.bin \ - 0x10000 firmware.bin \ - 0x390000 spiffs.bin + # Create full binary only if SPIFFS changed + if [[ "${{ steps.check_spiffs.outputs.SPIFFS_CHANGED }}" == "true" ]]; then + echo "Creating full binary..." + esptool.py --chip esp32 merge_bin \ + --fill-flash-size 4MB \ + --flash_mode dio \ + --flash_freq 40m \ + --flash_size 4MB \ + -o filaman_full_${VERSION}.bin \ + 0x0000 bootloader.bin \ + 0x8000 partitions.bin \ + 0x10000 firmware.bin \ + 0x390000 spiffs.bin + fi # Verify file sizes echo "File sizes:" @@ -87,6 +94,7 @@ jobs: TAG="${{ inputs.gitea_ref_name }}" API_URL="${{ inputs.gitea_server_url }}/api/v1" REPO="${{ inputs.gitea_repository }}" + VERSION=$(grep '^version = ' platformio.ini | cut -d'"' -f2) # Create release RESPONSE=$(curl -k -s \ @@ -104,12 +112,20 @@ jobs: if [ -n "$RELEASE_ID" ]; then echo "Release created with ID: $RELEASE_ID" - - # Upload binaries cd .pio/build/esp32dev - # Check if files exist before uploading - for file in filaman_spiffs.bin filaman_full.bin; do + # Always upload firmware + if [ -f "filaman_${VERSION}.bin" ]; then + curl -k -s \ + -X POST \ + -H "Authorization: token ${TOKEN}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary "@filaman_${VERSION}.bin" \ + "${API_URL}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=filaman_${VERSION}.bin" + fi + + # Upload SPIFFS and full binary only if they exist + for file in webpage_${VERSION}.bin filaman_full_${VERSION}.bin; do if [ -f "$file" ]; then echo "Uploading $file..." curl -k -s \ @@ -118,8 +134,6 @@ jobs: -H "Content-Type: application/octet-stream" \ --data-binary "@$file" \ "${API_URL}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=$file" - else - echo "Warning: $file not found" fi done else diff --git a/.github/workflows/providers/github-release.yml b/.github/workflows/providers/github-release.yml index 5d899d2..f43aec7 100644 --- a/.github/workflows/providers/github-release.yml +++ b/.github/workflows/providers/github-release.yml @@ -26,44 +26,51 @@ jobs: sudo apt-get update sudo apt-get install xxd + - name: Check for SPIFFS changes + id: check_spiffs + run: | + git fetch --unshallow || true + CHANGED_FILES=$(git diff --name-only HEAD^..HEAD) + if echo "$CHANGED_FILES" | grep -q "^data/\|^html/"; then + echo "SPIFFS_CHANGED=true" >> $GITHUB_OUTPUT + else + echo "SPIFFS_CHANGED=false" >> $GITHUB_OUTPUT + fi + - name: Build Firmware run: | - pio run -e esp32dev -t buildfs # Build SPIFFS - pio run -e esp32dev # Build firmware - cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman.bin - cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/filaman_spiffs.bin + # Get version from platformio.ini + VERSION=$(grep '^version = ' platformio.ini | cut -d'"' -f2) + + # Always build firmware + pio run -e esp32dev + cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman_${VERSION}.bin + + # Only build SPIFFS if changed + if [[ "${{ steps.check_spiffs.outputs.SPIFFS_CHANGED }}" == "true" ]]; then + echo "Building SPIFFS due to changes..." + cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/webpage_${VERSION}.bin + fi - name: Prepare binaries run: | - # Ensure we're in the project root - cd $GITHUB_WORKSPACE - - # Create SPIFFS directory if it doesn't exist - mkdir -p .pio/build/esp32dev/spiffs - - # Copy firmware to SPIFFS directory - cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/spiffs/firmware.bin - - # Build new SPIFFS image with firmware included - pio run -t buildfs - cd .pio/build/esp32dev + VERSION=$(grep '^version = ' ../../platformio.ini | cut -d'"' -f2) - # Create release files - cp spiffs.bin filaman_spiffs.bin - - # Create full binary - echo "Creating full binary..." - esptool.py --chip esp32 merge_bin \ - --fill-flash-size 4MB \ - --flash_mode dio \ - --flash_freq 40m \ - --flash_size 4MB \ - -o filaman_full.bin \ - 0x0000 bootloader.bin \ - 0x8000 partitions.bin \ - 0x10000 firmware.bin \ - 0x390000 spiffs.bin + # Create full binary only if SPIFFS changed + if [[ "${{ steps.check_spiffs.outputs.SPIFFS_CHANGED }}" == "true" ]]; then + echo "Creating full binary..." + esptool.py --chip esp32 merge_bin \ + --fill-flash-size 4MB \ + --flash_mode dio \ + --flash_freq 40m \ + --flash_size 4MB \ + -o filaman_full_${VERSION}.bin \ + 0x0000 bootloader.bin \ + 0x8000 partitions.bin \ + 0x10000 firmware.bin \ + 0x390000 spiffs.bin + fi # Verify file sizes echo "File sizes:" @@ -87,16 +94,23 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - # Check which files exist and create a list for upload cd .pio/build/esp32dev + VERSION=$(grep '^version = ' ../../platformio.ini | cut -d'"' -f2) FILES_TO_UPLOAD="" - for file in filaman_spiffs.bin filaman_full.bin; do - if [ -f "$file" ]; then - FILES_TO_UPLOAD="$FILES_TO_UPLOAD .pio/build/esp32dev/$file" - else - echo "Warning: $file not found" - fi - done + + # Always add firmware + if [ -f "filaman_${VERSION}.bin" ]; then + FILES_TO_UPLOAD="$FILES_TO_UPLOAD filaman_${VERSION}.bin" + fi + + # Add SPIFFS and full binary only if they exist + if [ -f "webpage_${VERSION}.bin" ]; then + FILES_TO_UPLOAD="$FILES_TO_UPLOAD webpage_${VERSION}.bin" + fi + + if [ -f "filaman_full_${VERSION}.bin" ]; then + FILES_TO_UPLOAD="$FILES_TO_UPLOAD filaman_full_${VERSION}.bin" + fi # Create release with available files if [ -n "$FILES_TO_UPLOAD" ]; then @@ -106,4 +120,5 @@ jobs: $FILES_TO_UPLOAD else echo "Error: No files found to upload" - exit 1 \ No newline at end of file + exit 1 + fi \ No newline at end of file diff --git a/html/header.html b/html/header.html index a83cd72..7bf2e7e 100644 --- a/html/header.html +++ b/html/header.html @@ -6,13 +6,24 @@ FilaMan - Filament Management Tool + + + diff --git a/html/index.html b/html/index.html index 2bd59e8..0c597ce 100644 --- a/html/index.html +++ b/html/index.html @@ -6,13 +6,24 @@ FilaMan - Filament Management Tool + + + diff --git a/html/rfid.html b/html/rfid.html index 7467cb5..79a9ce8 100644 --- a/html/rfid.html +++ b/html/rfid.html @@ -6,13 +6,24 @@ FilaMan - Filament Management Tool + + + diff --git a/html/spoolman.html b/html/spoolman.html index 0f56d8e..8689e2f 100644 --- a/html/spoolman.html +++ b/html/spoolman.html @@ -6,13 +6,24 @@ FilaMan - Filament Management Tool + + + diff --git a/html/upgrade.html b/html/upgrade.html index 8d3a8e1..ea57831 100644 --- a/html/upgrade.html +++ b/html/upgrade.html @@ -6,13 +6,24 @@ FilaMan - Filament Management Tool + + + diff --git a/html/waage.html b/html/waage.html index 067a785..da4fb6d 100644 --- a/html/waage.html +++ b/html/waage.html @@ -6,13 +6,24 @@ FilaMan - Filament Management Tool + + + diff --git a/html/wifi.html b/html/wifi.html index b86f796..8c1b489 100644 --- a/html/wifi.html +++ b/html/wifi.html @@ -6,13 +6,24 @@ FilaMan - Filament Management Tool + + + diff --git a/platformio.ini b/platformio.ini index 28af4b3..79f8c25 100644 --- a/platformio.ini +++ b/platformio.ini @@ -19,8 +19,10 @@ monitor_speed = 115200 lib_deps = tzapu/WiFiManager @ ^2.0.17 - https://github.com/me-no-dev/ESPAsyncWebServer.git#master - me-no-dev/AsyncTCP @ ^1.1.1 + #https://github.com/me-no-dev/ESPAsyncWebServer.git#master + #me-no-dev/AsyncTCP @ ^1.1.1 + mathieucarbou/ESPAsyncWebServer @ ^3.6.0 + esp32async/AsyncTCP @ ^3.3.5 bogde/HX711 @ ^0.7.5 adafruit/Adafruit SSD1306 @ ^2.5.13 adafruit/Adafruit GFX Library @ ^1.11.11 @@ -48,37 +50,20 @@ build_flags = -DCORE_DEBUG_LEVEL=3 -DCONFIG_ARDUHAL_LOG_COLORS=1 -DOTA_DEBUG=1 - -DARDUINO_RUNNING_CORE=1 - -DARDUINO_EVENT_RUNNING_CORE=1 -DCONFIG_OPTIMIZATION_LEVEL_DEBUG=1 -DCONFIG_ESP32_PANIC_PRINT_REBOOT - -DCONFIG_ARDUINO_OTA_READSIZE=1024 - -DCONFIG_ASYNC_TCP_RUNNING_CORE=1 - -DCONFIG_ASYNC_TCP_USE_WDT=0 - -DCONFIG_LWIP_TCP_MSS=1460 - -DOTA_PARTITION_SUBTYPE=0x10 - -DPARTITION_TABLE_OFFSET=0x8000 - -DPARTITION_TABLE_SIZE=0x1000 - -DCONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=1 - -DCONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=1 - -DCONFIG_BOOTLOADER_SKIP_VALIDATE_ON_POWER_ON=1 - -DCONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0x1000 - -DCONFIG_PARTITION_TABLE_OFFSET=0x8000 - -DCONFIG_PARTITION_TABLE_MD5=y -DBOOT_APP_PARTITION_OTA_0=1 -DCONFIG_LOG_DEFAULT_LEVEL=3 extra_scripts = scripts/extra_script.py - pre:scripts/pre_build.py ; wird zuerst ausgeführt - pre:scripts/pre_spiffs.py ; wird als zweites ausgeführt - pre:scripts/combine_html.py ; wird als drittes ausgeführt - scripts/gzip_files.py + ${env:buildfs.extra_scripts} -; Remove or comment out the targets line -;targets = buildfs, build +[env:buildfs] +extra_scripts = + pre:scripts/combine_html.py ; Combine header with HTML files + scripts/gzip_files.py ; Compress files for SPIFFS -; Add a custom target to build both [platformio] default_envs = esp32dev diff --git a/src/website.cpp b/src/website.cpp index dd2636d..395d93c 100644 --- a/src/website.cpp +++ b/src/website.cpp @@ -11,6 +11,7 @@ // Cache-Control Header definieren #define CACHE_CONTROL "max-age=31536000" // Cache für 1 Jahr +#define VERSION "1.0.0" AsyncWebServer server(webserverPort); AsyncWebSocket ws("/ws"); @@ -363,6 +364,11 @@ void setupWebserver(AsyncWebServer &server) { } ); + server.on("/api/version", HTTP_GET, [](AsyncWebServerRequest *request){ + String jsonResponse = "{\"version\": \"" VERSION "\"}"; + request->send(200, "application/json", jsonResponse); + }); + // Fehlerbehandlung für nicht gefundene Seiten server.onNotFound([](AsyncWebServerRequest *request){ Serial.print("404 - Nicht gefunden: "); From 60553255b862293571d62e4deeb5b9c33ae4d643 Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Fri, 21 Feb 2025 11:57:19 +0100 Subject: [PATCH 2/5] feat: enhance update process with separate forms for firmware and webpage uploads, including validation and improved UI --- html/upgrade.html | 90 +++++++++++++++++++++++++++++++++++++---------- src/website.cpp | 48 +++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 18 deletions(-) diff --git a/html/upgrade.html b/html/upgrade.html index ea57831..d624393 100644 --- a/html/upgrade.html +++ b/html/upgrade.html @@ -50,26 +50,64 @@
-

Firmware Upgrade

- +

System Update

Warning: Please do not turn off or restart the device during the update. The device will restart automatically after the update.
-
-
- - -
+
+
+

Firmware Update

+

Upload a new firmware file (filaman_*.bin)

+
+
+ + +
+
+
+ +
+

Webpage Update

+

Upload a new webpage file (webpage_*.bin)

+
+
+ + +
+
+
-
-
0%
+ + + \ No newline at end of file diff --git a/src/website.cpp b/src/website.cpp index 395d93c..99b4e2d 100644 --- a/src/website.cpp +++ b/src/website.cpp @@ -385,3 +385,51 @@ void setupWebserver(AsyncWebServer &server) { server.begin(); Serial.println("Webserver gestartet"); } + +void handleOTAUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) { + if (!index) { + // Start eines neuen Uploads + Serial.println("Update Start: " + filename); + + // Überprüfe den Dateityp basierend auf dem Dateinamen + bool isFirmware = filename.startsWith("filaman_"); + bool isWebpage = filename.startsWith("webpage_"); + + if (!isFirmware && !isWebpage) { + request->send(400, "application/json", "{\"message\":\"Invalid file type. File must start with 'filaman_' or 'webpage_'\"}"); + return; + } + + // Wähle den Update-Typ basierend auf dem Dateinamen + if (isWebpage) { + if (!Update.begin(SPIFFS.totalBytes(), U_SPIFFS)) { + Update.printError(Serial); + request->send(400, "application/json", "{\"message\":\"SPIFFS Update failed: " + String(Update.errorString()) + "\"}"); + return; + } + } else { + if (!Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASH)) { + Update.printError(Serial); + request->send(400, "application/json", "{\"message\":\"Firmware Update failed: " + String(Update.errorString()) + "\"}"); + return; + } + } + } + + if (Update.write(data, len) != len) { + Update.printError(Serial); + request->send(400, "application/json", "{\"message\":\"Write failed: " + String(Update.errorString()) + "\"}"); + return; + } + + if (final) { + if (!Update.end(true)) { + Update.printError(Serial); + request->send(400, "application/json", "{\"message\":\"Update failed: " + String(Update.errorString()) + "\"}"); + return; + } + request->send(200, "application/json", "{\"message\":\"Update successful!\", \"restart\": true}"); + delay(500); + ESP.restart(); + } +} From d6ca69fd19c53415e2698cef86494d1d0139decd Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Fri, 21 Feb 2025 11:57:57 +0100 Subject: [PATCH 3/5] chore: bump version to 1.2.94 in platformio.ini --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 79f8c25..83e762a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [common] -version = "1.2.91" +version = "1.2.94" [env:esp32dev] platform = espressif32 From c07689e15a00eaedccdde3ece8c8af33957ad240 Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Fri, 21 Feb 2025 11:58:00 +0100 Subject: [PATCH 4/5] docs: update webpages for version v1.2.95 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 83e762a..231f883 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [common] -version = "1.2.94" +version = "1.2.95" [env:esp32dev] platform = espressif32 From 767c217c25f268bb8136ab0ec3437844964e58b8 Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Fri, 21 Feb 2025 11:58:00 +0100 Subject: [PATCH 5/5] docs: update changelog for version 1.2.95 --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d19a6f8..65fdbca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [1.2.95] - 2025-02-21 +### Added +- enhance update process with separate forms for firmware and webpage uploads, including validation and improved UI +- add API endpoint for version retrieval and update HTML to display dynamic version + +### Changed +- update webpages for version v1.2.95 +- bump version to 1.2.94 in platformio.ini + + ## [1.2.91] - 2025-02-20 ### Added - add file existence checks before uploading binaries in release workflows