Skip to content

Commit a8a2e4c

Browse files
Update to allow upload of SPIFFS as well
Based on code from https://github.com/lbernstone/asyncUpdate/blob/master/AsyncUpdate.ino#L42
1 parent 5c42ca2 commit a8a2e4c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/AsyncElegantOTA.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "elegantWebpage.h"
2323

2424

25+
size_t content_len;
26+
2527
class AsyncElegantOtaClass{
2628
public:
2729

@@ -47,19 +49,22 @@ class AsyncElegantOtaClass{
4749
if (!index) {
4850

4951
#if defined(ESP8266)
50-
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
51-
if (!Update.begin(maxSketchSpace)){ // Start with max available size
52+
content_len = request->contentLength();
53+
int cmd = (filename.indexOf("spiffs") > -1) ? U_SPIFFS : U_FLASH;
54+
//uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
55+
Update.runAsync(true);
56+
if (!Update.begin(content_len, cmd)){ // Start with max available size
5257
#endif
5358

5459
#if defined(ESP32)
55-
if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { // Start with max available size
60+
if (!Update.begin(UPDATE_SIZE_UNKNOWN, cmd)) { // Start with max available size
5661
#endif
5762
Update.printError(Serial);
5863
}
5964

60-
#if defined(ESP8266)
65+
/*#if defined(ESP8266)
6166
Update.runAsync(true); // Tell the updaterClass to run in async mode
62-
#endif
67+
#endif*/
6368

6469
}
6570

@@ -98,4 +103,4 @@ class AsyncElegantOtaClass{
98103
};
99104

100105
AsyncElegantOtaClass AsyncElegantOTA;
101-
#endif
106+
#endif

0 commit comments

Comments
 (0)