Compare commits
	
		
			7 Commits
		
	
	
		
			v1.2.99
			...
			a77918da41
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a77918da41 | |||
| 262dad38a6 | |||
| cfc9f103cf | |||
| 0117302672 | |||
| 1de283b62f | |||
| f1eb78eb38 | |||
| 8a65b86475 | 
							
								
								
									
										27
									
								
								.github/workflows/providers/gitea-release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										27
									
								
								.github/workflows/providers/gitea-release.yml
									
									
									
									
										vendored
									
									
								
							| @@ -74,23 +74,20 @@ jobs: | ||||
|         # Copy firmware binary | ||||
|         cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman_${VERSION}.bin | ||||
|          | ||||
|         # Copy SPIFFS binary if SPIFFS changed | ||||
|         if [[ "${{ steps.check_spiffs.outputs.SPIFFS_CHANGED }}" == "true" ]]; then | ||||
|           echo "SPIFFS changes detected, copying SPIFFS binary..." | ||||
|           cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/webpage_${VERSION}.bin | ||||
|         fi | ||||
|         # Always create SPIFFS binary | ||||
|         cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/webpage_${VERSION}.bin | ||||
|          | ||||
|         # Create full binary (always) | ||||
|         (cd .pio/build/esp32dev && \ | ||||
|         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 \ | ||||
|         (cd .pio/build/esp32dev &&  | ||||
|         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) | ||||
|          | ||||
|         # Verify file sizes | ||||
|   | ||||
							
								
								
									
										13
									
								
								.github/workflows/providers/github-release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								.github/workflows/providers/github-release.yml
									
									
									
									
										vendored
									
									
								
							| @@ -60,11 +60,8 @@ jobs: | ||||
|         # Copy firmware binary | ||||
|         cp .pio/build/esp32dev/firmware.bin .pio/build/esp32dev/filaman_${VERSION}.bin | ||||
|          | ||||
|         # Copy SPIFFS binary if SPIFFS changed | ||||
|         if [[ "${{ steps.check_spiffs.outputs.SPIFFS_CHANGED }}" == "true" ]]; then | ||||
|           echo "SPIFFS changes detected, copying SPIFFS binary..." | ||||
|           cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/webpage_${VERSION}.bin | ||||
|         fi | ||||
|         # Always create SPIFFS binary | ||||
|         cp .pio/build/esp32dev/spiffs.bin .pio.build/esp32dev/webpage_${VERSION}.bin | ||||
|          | ||||
|         # Create full binary (always) | ||||
|         (cd .pio/build/esp32dev && \ | ||||
| @@ -79,12 +76,6 @@ jobs: | ||||
|           0x10000 firmware.bin \ | ||||
|           0x390000 spiffs.bin) | ||||
|          | ||||
|         # Only copy SPIFFS binary if data changed | ||||
|         if [[ "${{ steps.check_data.outputs.DATA_CHANGED }}" == "true" ]]; then | ||||
|           echo "Data changes detected, copying SPIFFS binary..." | ||||
|           cp .pio/build/esp32dev/spiffs.bin .pio/build/esp32dev/webpage_${VERSION}.bin | ||||
|         fi | ||||
|          | ||||
|         # Verify file sizes | ||||
|         echo "File sizes:" | ||||
|         (cd .pio/build/esp32dev && ls -lh *.bin) | ||||
|   | ||||
							
								
								
									
										13
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								CHANGELOG.md
									
									
									
									
									
								
							| @@ -1,5 +1,18 @@ | ||||
| # Changelog | ||||
|  | ||||
| ## [1.2.101] - 2025-02-21 | ||||
| ### Changed | ||||
| - update webpages for version v1.2.101 | ||||
| - always create SPIFFS binary in release workflows | ||||
| - migrate calibration value storage from EEPROM to NVS | ||||
|  | ||||
|  | ||||
| ## [1.2.100] - 2025-02-21 | ||||
| ### Changed | ||||
| - update webpages for version v1.2.100 | ||||
| - remove OTA handling and JSON backup/restore functions | ||||
|  | ||||
|  | ||||
| ## [1.2.99] - 2025-02-21 | ||||
| ### Added | ||||
| - add SPIFFS change detection and binary copying to release workflows | ||||
|   | ||||
| @@ -9,7 +9,7 @@ | ||||
| ; https://docs.platformio.org/page/projectconf.html | ||||
|  | ||||
| [common] | ||||
| version = "1.2.99" | ||||
| version = "1.2.101" | ||||
|  | ||||
| [env:esp32dev] | ||||
| platform = espressif32 | ||||
|   | ||||
							
								
								
									
										269
									
								
								src/ota.cpp
									
									
									
									
									
								
							
							
						
						
									
										269
									
								
								src/ota.cpp
									
									
									
									
									
								
							| @@ -1,269 +0,0 @@ | ||||
| #include <Arduino.h> | ||||
| #include "ota.h" | ||||
| #include <Update.h> | ||||
| #include <SPIFFS.h> | ||||
| #include "commonFS.h" | ||||
| #include "bambu.h" | ||||
| #include "scale.h" | ||||
| #include "nfc.h" | ||||
|  | ||||
| #define UPLOAD_TIMEOUT_MS 60000  // 60 Sekunden Timeout für den gesamten Upload | ||||
| #define CHUNK_RESPONSE_TIMEOUT_MS 10000  // 10 Sekunden Timeout pro Chunk | ||||
| #define MAX_FAILED_CHUNKS 3  // Maximale Anzahl fehlgeschlagener Chunks bevor Abbruch | ||||
| #define MAX_FILE_SIZE 4194304    // 4MB Limit | ||||
|  | ||||
| static bool tasksAreStopped = false; | ||||
| static uint32_t lastChunkTime = 0; | ||||
| static size_t failedChunks = 0; | ||||
| static size_t expectedOffset = 0; | ||||
| static size_t totalSize = 0; | ||||
|  | ||||
| void stopAllTasks() { | ||||
|     Serial.println("Stopping RFID Reader"); | ||||
|     if (RfidReaderTask) vTaskSuspend(RfidReaderTask); | ||||
|     Serial.println("Stopping Bambu"); | ||||
|     if (BambuMqttTask) vTaskSuspend(BambuMqttTask); | ||||
|     Serial.println("Stopping Scale"); | ||||
|     if (ScaleTask) vTaskSuspend(ScaleTask); | ||||
|     vTaskDelay(100 / portTICK_PERIOD_MS); | ||||
|     Serial.println("All tasks stopped"); | ||||
| } | ||||
|  | ||||
| void backupJsonConfigs() { | ||||
|     const char* configs[] = {"/bambu_credentials.json", "/spoolman_url.json"}; | ||||
|     for (const char* config : configs) { | ||||
|         if (SPIFFS.exists(config)) { | ||||
|             String backupPath = String(config) + ".bak"; | ||||
|             SPIFFS.remove(backupPath); | ||||
|             SPIFFS.rename(config, backupPath); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| void restoreJsonConfigs() { | ||||
|     const char* configs[] = {"/bambu_credentials.json", "/spoolman_url.json"}; | ||||
|     for (const char* config : configs) { | ||||
|         String backupPath = String(config) + ".bak"; | ||||
|         if (SPIFFS.exists(backupPath)) { | ||||
|             SPIFFS.remove(config); | ||||
|             SPIFFS.rename(backupPath, config); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| void performStageTwo() { | ||||
|     if (!SPIFFS.begin(true)) { | ||||
|         Serial.println("Error: Could not mount SPIFFS for stage 2"); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     // Backup JSON configs before update | ||||
|     backupJsonConfigs(); | ||||
|  | ||||
|     File firmwareFile = SPIFFS.open("/firmware.bin", "r"); | ||||
|     if (!firmwareFile) { | ||||
|         Serial.println("Error: Could not open firmware.bin from SPIFFS"); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     size_t firmwareSize = firmwareFile.size(); | ||||
|     size_t maxAppSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; | ||||
|  | ||||
|     Serial.printf("Stage 2 - Firmware size: %u bytes\n", firmwareSize); | ||||
|     Serial.printf("Available space: %u bytes\n", maxAppSpace); | ||||
|  | ||||
|     if (firmwareSize > maxAppSpace) { | ||||
|         Serial.printf("Error: Not enough space for firmware. Need %u bytes but only have %u bytes\n",  | ||||
|                     firmwareSize, maxAppSpace); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     if (!Update.begin(firmwareSize)) { | ||||
|         Update.printError(Serial); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     size_t written = Update.writeStream(firmwareFile); | ||||
|     if (written != firmwareSize) { | ||||
|         Update.printError(Serial); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     if (!Update.end(true)) { | ||||
|         Update.printError(Serial); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     firmwareFile.close(); | ||||
|     SPIFFS.remove("/firmware.bin"); // Cleanup | ||||
|  | ||||
|     // Restore JSON configs after update | ||||
|     restoreJsonConfigs(); | ||||
|  | ||||
|     Serial.println("Stage 2 update successful, restarting..."); | ||||
|     delay(500); | ||||
|     ESP.restart(); | ||||
| } | ||||
|  | ||||
| void checkForStagedUpdate() { | ||||
|     if (!SPIFFS.begin(true)) { | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     if (SPIFFS.exists("/firmware.bin")) { | ||||
|         Serial.println("Found staged firmware update, initiating stage 2..."); | ||||
|         performStageTwo(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| void handleOTAUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { | ||||
|     static File stagingFile; | ||||
|     static uint32_t uploadStartTime = 0; | ||||
|      | ||||
|     if (!index) { | ||||
|         // Überprüfe Gesamtgröße im Header | ||||
|         if (request->hasHeader("X-Total-Size")) { | ||||
|             totalSize = request->header("X-Total-Size").toInt(); | ||||
|             if (totalSize > MAX_FILE_SIZE) { | ||||
|                 request->send(413, "application/json",  | ||||
|                             "{\"status\":\"error\",\"message\":\"File too large\"}"); | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         uploadStartTime = millis(); | ||||
|         lastChunkTime = millis(); | ||||
|         expectedOffset = 0; | ||||
|         failedChunks = 0; | ||||
|          | ||||
|         bool isSpiffsUpdate = filename.endsWith("_spiffs.bin"); | ||||
|         Serial.printf("Update Start: %s (type: %s)\n", filename.c_str(), isSpiffsUpdate ? "SPIFFS" : "OTA"); | ||||
|         Serial.printf("Total size: %u bytes\n", totalSize); | ||||
|          | ||||
|         // Überprüfe Header für Chunk-Informationen | ||||
|         if (request->hasHeader("X-Chunk-Offset")) { | ||||
|             String offsetStr = request->header("X-Chunk-Offset"); | ||||
|             expectedOffset = offsetStr.toInt(); | ||||
|         } | ||||
|  | ||||
|         if (request->contentLength() == 0) { | ||||
|             request->send(400, "application/json", "{\"status\":\"error\",\"message\":\"Invalid file size\"}"); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         if (!tasksAreStopped) { | ||||
|             stopAllTasks(); | ||||
|             tasksAreStopped = true; | ||||
|         } | ||||
|  | ||||
|         if (isSpiffsUpdate) { | ||||
|             if (!SPIFFS.begin(true)) { | ||||
|                 request->send(400, "application/json",  | ||||
|                             "{\"status\":\"error\",\"message\":\"Could not mount SPIFFS\"}"); | ||||
|                 return; | ||||
|             } | ||||
|              | ||||
|             if (!Update.begin(totalSize > 0 ? totalSize : request->contentLength(), U_SPIFFS)) { | ||||
|                 Update.printError(Serial); | ||||
|                 request->send(400, "application/json",  | ||||
|                             "{\"status\":\"error\",\"message\":\"SPIFFS update initialization failed\"}"); | ||||
|                 return; | ||||
|             } | ||||
|         } else { | ||||
|             stagingFile = SPIFFS.open("/firmware.bin", "w"); | ||||
|             if (!stagingFile) { | ||||
|                 request->send(400, "application/json",  | ||||
|                             "{\"status\":\"error\",\"message\":\"Could not create staging file\"}"); | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // Chunk Validierung | ||||
|     if (request->hasHeader("X-Chunk-Offset")) { | ||||
|         size_t chunkOffset = request->header("X-Chunk-Offset").toInt(); | ||||
|         if (chunkOffset != expectedOffset) { | ||||
|             failedChunks++; | ||||
|             if (failedChunks >= MAX_FAILED_CHUNKS) { | ||||
|                 if (stagingFile) { | ||||
|                     stagingFile.close(); | ||||
|                     SPIFFS.remove("/firmware.bin"); | ||||
|                 } | ||||
|                 Update.abort(); | ||||
|                 request->send(400, "application/json",  | ||||
|                             "{\"status\":\"error\",\"message\":\"Too many failed chunks\"}"); | ||||
|                 return; | ||||
|             } | ||||
|             request->send(400, "application/json",  | ||||
|                         "{\"status\":\"error\",\"message\":\"Invalid chunk offset\"}"); | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // Timeout Überprüfungen | ||||
|     uint32_t currentTime = millis(); | ||||
|     if (currentTime - uploadStartTime > UPLOAD_TIMEOUT_MS) { | ||||
|         if (stagingFile) { | ||||
|             stagingFile.close(); | ||||
|             SPIFFS.remove("/firmware.bin"); | ||||
|         } | ||||
|         Update.abort(); | ||||
|         request->send(408, "application/json", "{\"status\":\"error\",\"message\":\"Upload timeout\"}"); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     if (currentTime - lastChunkTime > CHUNK_RESPONSE_TIMEOUT_MS) { | ||||
|         if (stagingFile) { | ||||
|             stagingFile.close(); | ||||
|             SPIFFS.remove("/firmware.bin"); | ||||
|         } | ||||
|         Update.abort(); | ||||
|         request->send(408, "application/json", "{\"status\":\"error\",\"message\":\"Chunk timeout\"}"); | ||||
|         return; | ||||
|     } | ||||
|     lastChunkTime = currentTime; | ||||
|  | ||||
|     if (stagingFile) { | ||||
|         size_t written = stagingFile.write(data, len); | ||||
|         if (written != len) { | ||||
|             stagingFile.close(); | ||||
|             SPIFFS.remove("/firmware.bin"); | ||||
|             request->send(400, "application/json",  | ||||
|                         "{\"status\":\"error\",\"message\":\"Write to SPIFFS failed\"}"); | ||||
|             return; | ||||
|         } | ||||
|     } else { | ||||
|         if (Update.write(data, len) != len) { | ||||
|             Update.printError(Serial); | ||||
|             request->send(400, "application/json",  | ||||
|                         "{\"status\":\"error\",\"message\":\"Write failed\"}"); | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     expectedOffset += len; | ||||
|  | ||||
|     if (final) { | ||||
|         if (stagingFile) { | ||||
|             stagingFile.close(); | ||||
|             Serial.println("Stage 1 complete - firmware staged in SPIFFS"); | ||||
|             request->send(200, "application/json",  | ||||
|                         "{\"status\":\"success\",\"message\":\"Update staged successfully! Starting stage 2...\"}"); | ||||
|             delay(100); | ||||
|             performStageTwo(); | ||||
|         } else { | ||||
|             if (!Update.end(true)) { | ||||
|                 Update.printError(Serial); | ||||
|                 request->send(400, "application/json",  | ||||
|                             "{\"status\":\"error\",\"message\":\"Update failed\"}"); | ||||
|                 return; | ||||
|             } | ||||
|             Serial.println("SPIFFS update successful, restarting..."); | ||||
|             request->send(200, "application/json",  | ||||
|                         "{\"status\":\"success\",\"message\":\"SPIFFS update successful! Device will restart...\",\"restart\":true}"); | ||||
|             delay(500); | ||||
|             ESP.restart(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
							
								
								
									
										18
									
								
								src/ota.h
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/ota.h
									
									
									
									
									
								
							| @@ -1,18 +0,0 @@ | ||||
| #ifndef OTA_H | ||||
| #define OTA_H | ||||
|  | ||||
| #include <ESPAsyncWebServer.h> | ||||
|  | ||||
| // Update size unknown constant, falls nicht bereits definiert | ||||
| #ifndef UPDATE_SIZE_UNKNOWN | ||||
| #define UPDATE_SIZE_UNKNOWN 0xFFFFFFFF | ||||
| #endif | ||||
|  | ||||
| void handleOTAUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final); | ||||
| void checkForStagedUpdate(); | ||||
| void performStageTwo(); | ||||
| void stopAllTasks(); | ||||
| void backupJsonConfigs(); | ||||
| void restoreJsonConfigs(); | ||||
|  | ||||
| #endif | ||||
| @@ -3,9 +3,9 @@ | ||||
| #include <ArduinoJson.h> | ||||
| #include "config.h" | ||||
| #include "HX711.h" | ||||
| #include <EEPROM.h> | ||||
| #include "display.h" | ||||
| #include "esp_task_wdt.h" | ||||
| #include <Preferences.h> | ||||
|  | ||||
| HX711 scale; | ||||
|  | ||||
| @@ -17,6 +17,10 @@ uint8_t weigthCouterToApi = 0; | ||||
| uint8_t scale_tare_counter = 0; | ||||
| uint8_t pauseMainTask = 0; | ||||
|  | ||||
| Preferences preferences; | ||||
| const char* NVS_NAMESPACE = "scale"; | ||||
| const char* NVS_KEY_CALIBRATION = "cal_value"; | ||||
|  | ||||
| // ##### Funktionen für Waage ##### | ||||
| uint8_t tareScale() { | ||||
|   Serial.println("Tare scale"); | ||||
| @@ -48,13 +52,12 @@ void scale_loop(void * parameter) { | ||||
|  | ||||
| void start_scale() { | ||||
|   Serial.println("Prüfe Calibration Value"); | ||||
|   long calibrationValue; // calibration value (see example file "Calibration.ino") | ||||
|   //calibrationValue = 696.0; // uncomment this if you want to set the calibration value in the sketch | ||||
|   long calibrationValue; | ||||
|  | ||||
|   EEPROM.begin(512); | ||||
|   EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch the calibration value from eeprom | ||||
|  | ||||
|   //calibrationValue = EEPROM.read(calVal_eepromAdress); | ||||
|   // NVS | ||||
|   preferences.begin(NVS_NAMESPACE, true); // true = readonly | ||||
|   calibrationValue = preferences.getLong(NVS_KEY_CALIBRATION, defaultScaleCalibrationValue); | ||||
|   preferences.end(); | ||||
|  | ||||
|   Serial.print("Read Scale Calibration Value "); | ||||
|   Serial.println(calibrationValue); | ||||
| @@ -137,18 +140,19 @@ uint8_t calibrate_scale() { | ||||
|     { | ||||
|       Serial.print("New calibration value has been set to: "); | ||||
|       Serial.println(newCalibrationValue); | ||||
|       Serial.print("Save this value to EEPROM adress "); | ||||
|       Serial.println(calVal_eepromAdress); | ||||
|  | ||||
|       //EEPROM.put(calVal_eepromAdress, newCalibrationValue); | ||||
|       EEPROM.put(calVal_eepromAdress, newCalibrationValue); | ||||
|       EEPROM.commit(); | ||||
|       // Speichern mit NVS | ||||
|       preferences.begin(NVS_NAMESPACE, false); // false = readwrite | ||||
|       preferences.putLong(NVS_KEY_CALIBRATION, newCalibrationValue); | ||||
|       preferences.end(); | ||||
|  | ||||
|       EEPROM.get(calVal_eepromAdress, newCalibrationValue); | ||||
|       //newCalibrationValue = EEPROM.read(calVal_eepromAdress); | ||||
|       // Verifizieren | ||||
|       preferences.begin(NVS_NAMESPACE, true); | ||||
|       long verifyValue = preferences.getLong(NVS_KEY_CALIBRATION, 0); | ||||
|       preferences.end(); | ||||
|  | ||||
|       Serial.print("Read Value "); | ||||
|       Serial.println(newCalibrationValue); | ||||
|       Serial.print("Verified stored value: "); | ||||
|       Serial.println(verifyValue); | ||||
|  | ||||
|       Serial.println("End calibration, revome weight"); | ||||
|  | ||||
|   | ||||
| @@ -29,4 +29,8 @@ void sendNfcData(AsyncWebSocketClient *client); | ||||
| void foundNfcTag(AsyncWebSocketClient *client, uint8_t success); | ||||
| void sendWriteResult(AsyncWebSocketClient *client, uint8_t success); | ||||
|  | ||||
| // Upgrade-Funktionen | ||||
| void backupJsonConfigs(); | ||||
| void restoreJsonConfigs(); | ||||
|  | ||||
| #endif | ||||
|   | ||||
		Reference in New Issue
	
	Block a user