11#include < Arduino.h>
22#include " StreamString.h"
33#include " ESPAsyncHTTPUpdateServer.h"
4+ #include < Ticker.h>
45
56#ifdef ESP32
67 #ifdef ESPASYNCHTTPUPDATESERVER_LITTLEFS
5556static const char successResponse[] PROGMEM =
5657 R"( <meta content="15;URL=/"http-equiv=refresh>Update Success! Rebooting...)" ;
5758
59+ Ticker restartTimer;
60+
5861ESPAsyncHTTPUpdateServer::ESPAsyncHTTPUpdateServer ()
5962{
6063 _server = NULL ;
@@ -77,7 +80,7 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
7780 return request->requestAuthentication ();
7881 AsyncWebServerResponse* response = request->beginResponse_P (200 , " text/html" , serverIndex, sizeof (serverIndex));
7982 response->addHeader (" Content-Encoding" , " gzip" );
80- request->send (response); });
83+ request->send (response); });
8184
8285 // handler for the /update form page - preflight options
8386 _server->on (path.c_str (), HTTP_OPTIONS, [&](AsyncWebServerRequest *request)
@@ -113,8 +116,7 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
113116 else
114117 {
115118 request->send_P (200 , PSTR (" text/html" ), successResponse);
116- delay (1000 );
117- ESP.restart ();
119+ restartTimer.once_ms (1000 , ESP.restart );
118120 } },
119121 [&](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final )
120122 {
@@ -180,7 +182,7 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
180182 if (_authenticated && final && !_updaterError.length ())
181183 {
182184 if (Update.end (true ))
183- {// true to set the size to the current progress
185+ { // true to set the size to the current progress
184186 Log (" Update Success: \n Rebooting...\n " );
185187 }
186188 else
@@ -202,4 +204,4 @@ void ESPAsyncHTTPUpdateServer::_setUpdaterError()
202204 StreamString str;
203205 Update.printError (str);
204206 _updaterError = str.c_str ();
205- }
207+ }
0 commit comments