Skip to content

Commit 5680b46

Browse files
committed
updated readme
cleaned logging code renamed SerialOutput flag fixed leftover Serial usages
1 parent 3f5cced commit 5680b46

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<p align=left>
2+
<img src="https://img.shields.io/github/v/release/IPdotSetAF/ESPAsyncHTTPUpdateServer"/>
3+
<img src="https://img.shields.io/github/release-date/IPdotSetAF/ESPAsyncHTTPUpdateServer"/>
4+
<img src="https://img.shields.io/github/last-commit/IPdotSetAF/ESPAsyncHTTPUpdateServer"/>
5+
<img src="https://img.shields.io/github/license/IPdotSetAF/ESPAsyncHTTPUpdateServer"/>
6+
<!--<img src="https://img.shields.io/github/downloads/IPdotSetAF/ESPAsyncHTTPUpdateServer/total"/>-->
7+
</p>
8+
19
# ESP Async HTTP Update Server
210

311
This is a copy of [ESP8266HTTPUpdateServer](https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266HTTPUpdateServer)/[ESP32's HTTPUpdateServer](https://github.com/espressif/arduino-esp32/tree/master/libraries/HTTPUpdateServer) library, modified to be compatible with [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer).
@@ -56,15 +64,18 @@ or
5664
_updateServer.setup(&_server, "/customroute", "username", "password");
5765
```
5866

67+
### Selecting FileSystem
5968
> [!IMPORTANT]
60-
> ### Selecting FileSystem
6169
> The library's default fileSystem is `SPIFFS` but if you are using `LittleFS` for your FileSystem, make sure to add the `-DESPASYNCHTTPUPDATESERVER_LITTLEFS` Build Flag to your environment.
6270
71+
### Debugging
6372
> [!TIP]
64-
> ### Debugging
6573
> In order to debug the library funtionality, you can add the `-DESPASYNCHTTPUPDATESERVER_DEBUG` Build Flag to your environment.
6674
>
67-
>This will enable the library to print logs to the Serial.
75+
> This will enable the library to print logs to the Serial.
76+
77+
> [!TIP]
78+
> If you are using another `Serial` port, you can override the default serial by adding the `-DESPASYNCHTTPUPDATESERVER_SerialOutput=Serial1` Build Flag to your environment.
6879
6980
## TODO:
7081
- ESP8266 LittleFS support

src/ESPAsyncHTTPUpdateServer.cpp

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616
#error "This library only supports boards with an ESP8266 or ESP32 processor."
1717
#endif
1818

19-
#define SerialOutput Serial
19+
#ifndef ESPASYNCHTTPUPDATESERVER_SerialOutput
20+
#define ESPASYNCHTTPUPDATESERVER_SerialOutput Serial
21+
#endif
22+
23+
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
24+
#define Log(...) ESPASYNCHTTPUPDATESERVER_SerialOutput.printf(__VA_ARGS__)
25+
#else
26+
#define Log(...)
27+
#endif
2028

2129
static const char serverIndex[] PROGMEM =
2230
R"(<!DOCTYPE html>
@@ -75,9 +83,7 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
7583
_authenticated = (_username == emptyString || _password == emptyString || request -> authenticate(_username.c_str(), _password.c_str()));
7684
if (!_authenticated)
7785
{
78-
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
79-
SerialOutput.printf("Unauthenticated Update\n");
80-
#endif
86+
Log("Unauthenticated Update\n");
8187
return;
8288
} });
8389

@@ -114,28 +120,21 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
114120
{
115121
_updaterError.clear();
116122
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
117-
SerialOutput.setDebugOutput(true);
123+
ESPASYNCHTTPUPDATESERVER_SerialOutput.setDebugOutput(true);
118124
#endif
119125
_authenticated = (_username == emptyString || _password == emptyString || request->authenticate(_username.c_str(), _password.c_str()));
120126
if (!_authenticated)
121127
{
122-
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
123-
SerialOutput.printf("Unauthenticated Update\n");
124-
#endif
128+
Log("Unauthenticated Update\n");
125129
return;
126130
}
127-
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
128-
SerialOutput.printf("Update: %s\n", filename.c_str());
129-
#endif
131+
Log("Update: %s\n", filename.c_str());
130132
#ifdef ESP8266
131133
Update.runAsync(true);
132134
#endif
133135
if (inputName == "filesystem")
134136
{
135-
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
136-
SerialOutput.println("updating filesystem");
137-
#endif
138-
137+
Log("updating filesystem");
139138
#ifdef ESP8266
140139
int command = U_FS;
141140
size_t fsSize = ((size_t)FS_end - (size_t)FS_start);
@@ -151,44 +150,36 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
151150
if (!Update.begin(fsSize, command))
152151
{ // start with max available size
153152
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
154-
Update.printError(Serial);
153+
Update.printError(ESPASYNCHTTPUPDATESERVER_SerialOutput);
155154
#endif
156155
}
157156
}
158157
else
159158
{
160-
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
161-
SerialOutput.println("updating flash");
162-
#endif
159+
Log("updating flash");
163160
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
164-
if (!Update.begin(maxSketchSpace, U_FLASH))
165-
{ // start with max available size
161+
if (!Update.begin(maxSketchSpace, U_FLASH)) // start with max available size
166162
_setUpdaterError();
167-
}
168163
}
169164
}
170165

171166
if (_authenticated && len && !_updaterError.length())
172167
{
173-
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
174-
SerialOutput.printf(".");
175-
#endif
168+
Log(".");
176169
if (Update.write(data, len) != len)
177170
_setUpdaterError();
178171
}
179172

180173
if (_authenticated && final && !_updaterError.length())
181174
{
182175
if (Update.end(true))
183-
{ // true to set the size to the current progress
184-
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
185-
SerialOutput.println("Update Success: \nRebooting...\n");
186-
#endif
176+
{// true to set the size to the current progress
177+
Log("Update Success: \nRebooting...\n");
187178
}
188179
else
189180
_setUpdaterError();
190181
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
191-
SerialOutput.setDebugOutput(false);
182+
ESPASYNCHTTPUPDATESERVER_SerialOutput.setDebugOutput(false);
192183
#endif
193184
}
194185
else
@@ -199,7 +190,7 @@ void ESPAsyncHTTPUpdateServer::setup(AsyncWebServer *server, const String &path,
199190
void ESPAsyncHTTPUpdateServer::_setUpdaterError()
200191
{
201192
#ifdef ESPASYNCHTTPUPDATESERVER_DEBUG
202-
Update.printError(Serial);
193+
Update.printError(ESPASYNCHTTPUPDATESERVER_SerialOutput);
203194
#endif
204195
StreamString str;
205196
Update.printError(str);

0 commit comments

Comments
 (0)