Skip to content

Commit c1d0380

Browse files
authored
Merge pull request #29 from IPdotSetAF/22-update-response-on-8266
implemented ticker for reset after update
2 parents e1f7cdf + 5f38a6d commit c1d0380

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/ESPAsyncHTTPUpdateServer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <Arduino.h>
22
#include "StreamString.h"
33
#include "ESPAsyncHTTPUpdateServer.h"
4+
#include <Ticker.h>
45

56
#ifdef ESP32
67
#ifdef ESPASYNCHTTPUPDATESERVER_LITTLEFS
@@ -55,6 +56,8 @@
5556
static const char successResponse[] PROGMEM =
5657
R"(<meta content="15;URL=/"http-equiv=refresh>Update Success! Rebooting...)";
5758

59+
Ticker restartTimer;
60+
5861
ESPAsyncHTTPUpdateServer::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: \nRebooting...\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

Comments
 (0)