feat: add API endpoint for version retrieval and update HTML to display dynamic version

This commit is contained in:
Manuel Weiser 2025-02-21 11:53:59 +01:00
parent 4477537cec
commit 8199b283c0
11 changed files with 219 additions and 108 deletions

View File

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

View File

@ -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
exit 1
fi

View File

@ -6,13 +6,24 @@
<title>FilaMan - Filament Management Tool</title>
<link rel="icon" type="image/png" href="/favicon.ico">
<link rel="stylesheet" href="style.css">
<script>
fetch('/api/version')
.then(response => response.json())
.then(data => {
const versionSpan = document.querySelector('.version');
if (versionSpan) {
versionSpan.textContent = 'v' + data.version;
}
})
.catch(error => console.error('Error fetching version:', error));
</script>
</head>
<body>
<div class="navbar">
<div style="display: flex; align-items: center; gap: 2rem;">
<img src="/logo.png" alt="FilaMan Logo" class="logo">
<div class="logo-text">
<h1>FilaMan<span class="version">v1.2.91</span></h1>
<h1>FilaMan<span class="version"></span></h1>
<h4>Filament Management Tool</h4>
</div>
</div>
@ -33,4 +44,6 @@
<div class="ram-status" id="ramStatus"></div>
</div>
</div>
</body>
</html>

View File

@ -6,13 +6,24 @@
<title>FilaMan - Filament Management Tool</title>
<link rel="icon" type="image/png" href="/favicon.ico">
<link rel="stylesheet" href="style.css">
<script>
fetch('/api/version')
.then(response => response.json())
.then(data => {
const versionSpan = document.querySelector('.version');
if (versionSpan) {
versionSpan.textContent = 'v' + data.version;
}
})
.catch(error => console.error('Error fetching version:', error));
</script>
</head>
<body>
<div class="navbar">
<div style="display: flex; align-items: center; gap: 2rem;">
<img src="/logo.png" alt="FilaMan Logo" class="logo">
<div class="logo-text">
<h1>FilaMan<span class="version">v1.2.91</span></h1>
<h1>FilaMan<span class="version"></span></h1>
<h4>Filament Management Tool</h4>
</div>
</div>
@ -33,6 +44,8 @@
<div class="ram-status" id="ramStatus"></div>
</div>
</div>
</body>
</html>
<!-- head -->

View File

@ -6,13 +6,24 @@
<title>FilaMan - Filament Management Tool</title>
<link rel="icon" type="image/png" href="/favicon.ico">
<link rel="stylesheet" href="style.css">
<script>
fetch('/api/version')
.then(response => response.json())
.then(data => {
const versionSpan = document.querySelector('.version');
if (versionSpan) {
versionSpan.textContent = 'v' + data.version;
}
})
.catch(error => console.error('Error fetching version:', error));
</script>
</head>
<body>
<div class="navbar">
<div style="display: flex; align-items: center; gap: 2rem;">
<img src="/logo.png" alt="FilaMan Logo" class="logo">
<div class="logo-text">
<h1>FilaMan<span class="version">v1.2.91</span></h1>
<h1>FilaMan<span class="version"></span></h1>
<h4>Filament Management Tool</h4>
</div>
</div>
@ -33,6 +44,8 @@
<div class="ram-status" id="ramStatus"></div>
</div>
</div>
</body>
</html>
<!-- head -->

View File

@ -6,13 +6,24 @@
<title>FilaMan - Filament Management Tool</title>
<link rel="icon" type="image/png" href="/favicon.ico">
<link rel="stylesheet" href="style.css">
<script>
fetch('/api/version')
.then(response => response.json())
.then(data => {
const versionSpan = document.querySelector('.version');
if (versionSpan) {
versionSpan.textContent = 'v' + data.version;
}
})
.catch(error => console.error('Error fetching version:', error));
</script>
</head>
<body>
<div class="navbar">
<div style="display: flex; align-items: center; gap: 2rem;">
<img src="/logo.png" alt="FilaMan Logo" class="logo">
<div class="logo-text">
<h1>FilaMan<span class="version">v1.2.91</span></h1>
<h1>FilaMan<span class="version"></span></h1>
<h4>Filament Management Tool</h4>
</div>
</div>
@ -33,6 +44,8 @@
<div class="ram-status" id="ramStatus"></div>
</div>
</div>
</body>
</html>
<!-- head -->

View File

@ -6,13 +6,24 @@
<title>FilaMan - Filament Management Tool</title>
<link rel="icon" type="image/png" href="/favicon.ico">
<link rel="stylesheet" href="style.css">
<script>
fetch('/api/version')
.then(response => response.json())
.then(data => {
const versionSpan = document.querySelector('.version');
if (versionSpan) {
versionSpan.textContent = 'v' + data.version;
}
})
.catch(error => console.error('Error fetching version:', error));
</script>
</head>
<body>
<div class="navbar">
<div style="display: flex; align-items: center; gap: 2rem;">
<img src="/logo.png" alt="FilaMan Logo" class="logo">
<div class="logo-text">
<h1>FilaMan<span class="version">v1.2.91</span></h1>
<h1>FilaMan<span class="version"></span></h1>
<h4>Filament Management Tool</h4>
</div>
</div>
@ -33,6 +44,8 @@
<div class="ram-status" id="ramStatus"></div>
</div>
</div>
</body>
</html>
<!-- head -->

View File

@ -6,13 +6,24 @@
<title>FilaMan - Filament Management Tool</title>
<link rel="icon" type="image/png" href="/favicon.ico">
<link rel="stylesheet" href="style.css">
<script>
fetch('/api/version')
.then(response => response.json())
.then(data => {
const versionSpan = document.querySelector('.version');
if (versionSpan) {
versionSpan.textContent = 'v' + data.version;
}
})
.catch(error => console.error('Error fetching version:', error));
</script>
</head>
<body>
<div class="navbar">
<div style="display: flex; align-items: center; gap: 2rem;">
<img src="/logo.png" alt="FilaMan Logo" class="logo">
<div class="logo-text">
<h1>FilaMan<span class="version">v1.2.91</span></h1>
<h1>FilaMan<span class="version"></span></h1>
<h4>Filament Management Tool</h4>
</div>
</div>
@ -33,6 +44,8 @@
<div class="ram-status" id="ramStatus"></div>
</div>
</div>
</body>
</html>
<!-- head -->

View File

@ -6,13 +6,24 @@
<title>FilaMan - Filament Management Tool</title>
<link rel="icon" type="image/png" href="/favicon.ico">
<link rel="stylesheet" href="style.css">
<script>
fetch('/api/version')
.then(response => response.json())
.then(data => {
const versionSpan = document.querySelector('.version');
if (versionSpan) {
versionSpan.textContent = 'v' + data.version;
}
})
.catch(error => console.error('Error fetching version:', error));
</script>
</head>
<body>
<div class="navbar">
<div style="display: flex; align-items: center; gap: 2rem;">
<img src="/logo.png" alt="FilaMan Logo" class="logo">
<div class="logo-text">
<h1>FilaMan<span class="version">v1.2.91</span></h1>
<h1>FilaMan<span class="version"></span></h1>
<h4>Filament Management Tool</h4>
</div>
</div>
@ -33,6 +44,8 @@
<div class="ram-status" id="ramStatus"></div>
</div>
</div>
</body>
</html>
<!-- head -->

View File

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

View File

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