|
3 | 3 | #include <WiFiServer.h>
|
4 | 4 | #include <ESP8266WebServer.h>
|
5 | 5 | #include <WiFiUdp.h>
|
| 6 | +#include <flash_hal.h> |
| 7 | +#include <FS.h> |
| 8 | +#include <LittleFS.h> |
6 | 9 | #include "StreamString.h"
|
7 | 10 | #include "ESP8266HTTPUpdateServer.h"
|
8 | 11 |
|
9 | 12 | namespace esp8266httpupdateserver {
|
10 | 13 | using namespace esp8266webserver;
|
11 | 14 |
|
12 | 15 | static const char serverIndex[] PROGMEM =
|
13 |
| - R"(<html><body><form method='POST' action='' enctype='multipart/form-data'> |
14 |
| - <input type='file' name='update'> |
15 |
| - <input type='submit' value='Update'> |
16 |
| - </form> |
17 |
| - </body></html>)"; |
| 16 | + R"(<!DOCTYPE html> |
| 17 | + <html lang='en'> |
| 18 | + <head> |
| 19 | + <meta charset='utf-8'> |
| 20 | + <meta name='viewport' content='width=device-width,initial-scale=1'/> |
| 21 | + </head> |
| 22 | + <body> |
| 23 | + <form method='POST' action='' enctype='multipart/form-data'> |
| 24 | + Firmware:<br> |
| 25 | + <input type='file' accept='.bin' name='firmware'> |
| 26 | + <input type='submit' value='Update Firmware'> |
| 27 | + </form> |
| 28 | + <form method='POST' action='' enctype='multipart/form-data'> |
| 29 | + FileSystem:<br> |
| 30 | + <input type='file' accept='.bin' name='filesystem'> |
| 31 | + <input type='submit' value='Update FileSystem'> |
| 32 | + </form> |
| 33 | + </body> |
| 34 | + </html>)"; |
18 | 35 | static const char successResponse[] PROGMEM =
|
19 | 36 | "<META http-equiv=\"refresh\" content=\"15;URL=/\">Update Success! Rebooting...";
|
20 | 37 |
|
@@ -75,9 +92,18 @@ void ESP8266HTTPUpdateServerTemplate<ServerType>::setup(ESP8266WebServerTemplate
|
75 | 92 | WiFiUDP::stopAll();
|
76 | 93 | if (_serial_output)
|
77 | 94 | Serial.printf("Update: %s\n", upload.filename.c_str());
|
78 |
| - uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; |
79 |
| - if(!Update.begin(maxSketchSpace)){//start with max available size |
80 |
| - _setUpdaterError(); |
| 95 | + if (upload.name == "filesystem") { |
| 96 | + size_t fsSize = ((size_t) &_FS_end - (size_t) &_FS_start); |
| 97 | + SPIFFS.end(); |
| 98 | + LittleFS.end(); |
| 99 | + if (!Update.begin(fsSize, U_FS)){//start with max available size |
| 100 | + if (_serial_output) Update.printError(Serial); |
| 101 | + } |
| 102 | + } else { |
| 103 | + uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000; |
| 104 | + if (!Update.begin(maxSketchSpace, U_FLASH)){//start with max available size |
| 105 | + _setUpdaterError(); |
| 106 | + } |
81 | 107 | }
|
82 | 108 | } else if(_authenticated && upload.status == UPLOAD_FILE_WRITE && !_updaterError.length()){
|
83 | 109 | if (_serial_output) Serial.printf(".");
|
|
0 commit comments