@@ -203,12 +203,13 @@ void UpdateManager::installUpdate(bool skip_filesystem, bool force) {
203203
204204 // --- Install firmware ---
205205 if (manifest_.firmware .url .length () > 0 && manifest_.firmware .size_bytes > 0 ) {
206+ phase_ = " firmware" ;
206207 setStatus (UpdateStatus::DOWNLOADING, true );
207208 bytes_downloaded_ = 0 ;
208209 total_bytes_ = manifest_.firmware .size_bytes ;
209210 progress_percent_ = 0 ;
210211
211- logger.logInfo (" Downloading firmware: " + String (manifest_.firmware .size_bytes ) + " bytes" );
212+ logger.logInfo (" Downloading firmware: " + String (( unsigned long ) manifest_.firmware .size_bytes ) + " bytes" );
212213
213214 // Begin OTA firmware partition
214215 if (!hal_->otaBegin (manifest_.firmware .size_bytes , 0 )) {
@@ -231,10 +232,12 @@ void UpdateManager::installUpdate(bool skip_filesystem, bool force) {
231232
232233 if (!downloadSuccess) {
233234 hal_->otaAbort ();
234- setError (UpdateError::DOWNLOAD_FAILED, " Firmware download failed" );
235+ setError (UpdateError::DOWNLOAD_FAILED, " Firmware download failed or incomplete " );
235236 return ;
236237 }
237238
239+ logger.logInfo (" Firmware download complete: " + String ((unsigned long )bytes_downloaded_) + " bytes, finalizing..." );
240+
238241 // Finalize firmware OTA
239242 setStatus (UpdateStatus::INSTALLING);
240243 if (!hal_->otaEnd (true )) {
@@ -248,12 +251,13 @@ void UpdateManager::installUpdate(bool skip_filesystem, bool force) {
248251
249252 // --- Install filesystem (if not skipping) ---
250253 if (!skip_filesystem && manifest_.filesystem .url .length () > 0 && manifest_.filesystem .size_bytes > 0 ) {
254+ phase_ = " filesystem" ;
251255 bytes_downloaded_ = 0 ;
252256 total_bytes_ = manifest_.filesystem .size_bytes ;
253257 progress_percent_ = 0 ;
254258 setStatus (UpdateStatus::DOWNLOADING, true );
255259
256- logger.logInfo (" Downloading filesystem: " + String (manifest_.filesystem .size_bytes ) + " bytes" );
260+ logger.logInfo (" Downloading filesystem: " + String (( unsigned long ) manifest_.filesystem .size_bytes ) + " bytes" );
257261
258262 // End current filesystem before flashing
259263 hal_->fsEnd ();
@@ -268,6 +272,7 @@ void UpdateManager::installUpdate(bool skip_filesystem, bool force) {
268272 [this ](const uint8_t * data, size_t len, uint32_t downloaded, uint32_t total) -> bool {
269273 size_t written = hal_->otaWrite (data, len);
270274 if (written != len) {
275+ logger.logError (" Filesystem OTA write failed: wrote " + String ((unsigned long )written) + " /" + String ((unsigned long )len) + " bytes" );
271276 return false ;
272277 }
273278 bytes_downloaded_ = downloaded;
@@ -279,10 +284,12 @@ void UpdateManager::installUpdate(bool skip_filesystem, bool force) {
279284 if (!fsDownloadSuccess) {
280285 hal_->otaAbort ();
281286 hal_->fsBegin ();
282- setError (UpdateError::DOWNLOAD_FAILED, " Filesystem download failed" );
287+ setError (UpdateError::DOWNLOAD_FAILED, " Filesystem download failed or incomplete " );
283288 return ;
284289 }
285290
291+ logger.logInfo (" Filesystem download complete: " + String ((unsigned long )bytes_downloaded_) + " bytes, finalizing..." );
292+
286293 setStatus (UpdateStatus::INSTALLING);
287294 if (!hal_->otaEnd (true )) {
288295 hal_->otaAbort ();
@@ -294,10 +301,11 @@ void UpdateManager::installUpdate(bool skip_filesystem, bool force) {
294301 logger.logInfo (" Filesystem update installed successfully" );
295302 }
296303
304+ phase_ = " complete" ;
297305 setStatus (UpdateStatus::COMPLETE, true );
298306 progress_percent_ = 100 ;
299- logger.logWarning (" Update complete! Restarting device..." );
300- delay (1000 );
307+ logger.logWarning (" Update complete! Restarting device in 5 seconds ..." );
308+ delay (5000 ); // Allow time for status poll to see COMPLETE
301309 hal_->restart ();
302310}
303311
@@ -326,6 +334,7 @@ UpdateStatusSnapshot UpdateManager::getStatus() const {
326334 snapshot.bytes_downloaded = bytes_downloaded_;
327335 snapshot.total_bytes = total_bytes_;
328336 snapshot.error_message = last_error_message_;
337+ snapshot.phase = phase_;
329338 snapshot.last_check_time = last_check_time_;
330339 snapshot.next_check_time = 0 ; // TODO: Calculate based on settings
331340
@@ -397,6 +406,7 @@ JsonDocument UpdateManager::getStatusResponseJson() const {
397406
398407 doc[" status" ] = statusStr;
399408 doc[" progress" ] = progress_percent_;
409+ doc[" phase" ] = phase_;
400410 doc[" last_check" ] = last_check_time_;
401411 doc[" error" ] = last_error_message_;
402412
@@ -414,6 +424,7 @@ void UpdateManager::reset() {
414424 status_ = UpdateStatus::IDLE;
415425 error_ = UpdateError::NONE;
416426 last_error_message_ = " " ;
427+ phase_ = " " ;
417428 progress_percent_ = 0 ;
418429 bytes_downloaded_ = 0 ;
419430 total_bytes_ = 0 ;
0 commit comments