Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/ESPAsyncHTTPUpdateServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#error "This library only supports boards with an ESP8266 or ESP32 processor."
#endif

#define SerialOutput Serial

static const char serverIndex[] PROGMEM =
R"(<!DOCTYPE html>
<html lang='en'>
Expand Down Expand Up @@ -74,7 +76,7 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
if (!_authenticated)
{
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
Serial.printf("Unauthenticated Update\n");
SerialOutput.printf("Unauthenticated Update\n");
#endif
return;
} });
Expand Down Expand Up @@ -112,26 +114,26 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
{
_updaterError.clear();
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
Serial.setDebugOutput(true);
SerialOutput.setDebugOutput(true);
#endif
_authenticated = (_username == emptyString || _password == emptyString || request->authenticate(_username.c_str(), _password.c_str()));
if (!_authenticated)
{
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
Serial.printf("Unauthenticated Update\n");
SerialOutput.printf("Unauthenticated Update\n");
#endif
return;
}
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
Serial.printf("Update: %s\n", filename.c_str());
SerialOutput.printf("Update: %s\n", filename.c_str());
#endif
#ifdef ESP8266
Update.runAsync(true);
#endif
if (inputName == "filesystem")
{
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
Serial.println("updating filesystem");
SerialOutput.println("updating filesystem");
#endif

#ifdef ESP8266
Expand All @@ -156,7 +158,7 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
else
{
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
Serial.println("updating flash");
SerialOutput.println("updating flash");
#endif
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if (!Update.begin(maxSketchSpace, U_FLASH))
Expand All @@ -169,7 +171,7 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
if (_authenticated && len && !_updaterError.length())
{
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
Serial.printf(".");
SerialOutput.printf(".");
#endif
if (Update.write(data, len) != len)
_setUpdaterError();
Expand All @@ -180,13 +182,13 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
if (Update.end(true))
{ // true to set the size to the current progress
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
Serial.println("Update Success: \nRebooting...\n");
SerialOutput.println("Update Success: \nRebooting...\n");
#endif
}
else
_setUpdaterError();
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
Serial.setDebugOutput(false);
SerialOutput.setDebugOutput(false);
#endif
}
else
Expand Down