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: ");