@@ -105,9 +105,9 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
105105 if (!_authenticated)
106106 return request->requestAuthentication ();
107107
108- if (Update. hasError () )
108+ if (_updateResult != UpdateResult::UPDATE_OK )
109109 {
110- AsyncWebServerResponse *response = request->beginResponse (200 , F (" text/html" ), String (F (" Update error: " )) + _updaterError);
110+ AsyncWebServerResponse *response = request->beginResponse (200 , F (" text/html" ), Update. hasError () ? String (F (" Update error: " )) + _updaterError : " Update aborted by server. " );
111111 response->addHeader (" Access-Control-Allow-Headers" , " *" );
112112 response->addHeader (" Access-Control-Allow-Origin" , " *" );
113113 response->addHeader (" Connection" , " close" );
@@ -116,6 +116,7 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
116116 else
117117 {
118118 request->send_P (200 , PSTR (" text/html" ), successResponse);
119+ Log (" Rebooting...\n " );
119120 restartTimer.once_ms (1000 , ESP.restart );
120121 } },
121122 [&](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final )
@@ -160,7 +161,7 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
160161#endif
161162 if (_updateType == UpdateType::FILE_SYSTEM)
162163 {
163- Log (" updating filesystem" );
164+ Log (" updating filesystem\n " );
164165#ifdef ESP8266
165166 int command = U_FS;
166167 size_t fsSize = ((size_t )FS_end - (size_t )FS_start);
@@ -182,28 +183,28 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
182183 }
183184 else
184185 {
185- Log (" updating flash" );
186+ Log (" updating flash\n " );
186187 uint32_t maxSketchSpace = (ESP.getFreeSketchSpace () - 0x1000 ) & 0xFFFFF000 ;
187188 if (!Update.begin (maxSketchSpace, U_FLASH)) // start with max available size
188189 _setUpdaterError ();
189190 }
190191 }
191192
192- if (_authenticated && len && !_updaterError. length () )
193+ if (_authenticated && len && _updateResult == UpdateResult::UPDATE_OK )
193194 {
194195 Log (" ." );
195196 if (Update.write (data, len) != len)
196197 _setUpdaterError ();
197198 }
198199
199- if (_authenticated && final && !_updaterError. length () )
200+ if (_authenticated && final && _updateResult == UpdateResult::UPDATE_OK )
200201 {
201202 if (Update.end (true ))
202203 { // true to set the size to the current progress
204+ Log (" Update Success.\n " );
203205 _updateResult = UpdateResult::UPDATE_OK;
204206 if (onUpdateEnd)
205207 onUpdateEnd (_updateType, _updateResult);
206- Log (" Update Success: \n Rebooting...\n " );
207208 }
208209 else
209210 _setUpdaterError ();
0 commit comments