Here is the example program that just hosts one webpage that asks to upload a file
#include <FS.h> //SPIFFS File system
#include <ESP8266WiFi.h>
#include "ESPAsyncTCP.h"
#include "ESPAsyncWebServer.h"
#define HTTPPORT 80
const char* ssid = "SSID";
const char* password = "PASSWORD";
AsyncWebServer HTTPserver(HTTPPORT);
void HTTPRoot(AsyncWebServerRequest *request) {
String w= F("\
Upload a simple test program<p>\n\
<form method='POST' action='/update' enctype='multipart/form-data'>\n\
<input type='file' accept='.bin' name='update' value='Select File'><p>\n\
<input type='submit' value='Upload and Update'>\n\
</form>\n");
AsyncResponseStream *response = request->beginResponseStream("text/html");
response->print(w);
request->send(response);
}
void update(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
if (!index) { //UPLOAD Start
Serial.setDebugOutput(true);
Serial.printf("Update: %s\n", filename.c_str());
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
Update.runAsync(true);
if (!Update.begin(maxSketchSpace)) {//start with max available size
Update.printError(Serial);
request->send(200, F("text/html"), F("Error: Max size exceeded"));
}
} else if(final) { //Upload finished
Serial.println(F("File Finished Uploading"));
if (Update.end(true)) { //true to set the size to the current progress
Serial.print(F("Update Success: Restarting..."));
ESP.restart();
}
else {
Update.printError(Serial);
}
Serial.setDebugOutput(false);
}
//Write the Data to flash
if (Update.write(data, len) != len) {
Update.printError(Serial);
request->send(200, F("text/html"), F("Error: Updated size did not match file uploaded"));
}
Serial.print(".");
}//===============================================================================================
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.printf("connecting to: %s\n\r", ssid);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.printf("STA: Failed!\n");
WiFi.disconnect(false);
delay(1000);
WiFi.begin(ssid, password);
}
Serial.print("connected:"); Serial.println(WiFi.localIP().toString());
HTTPserver.on("/", HTTPRoot);
HTTPserver.on("/update", HTTP_POST, [](AsyncWebServerRequest *request) {
request->send(200);
}, update);
HTTPserver.begin();
}
void loop()
{
//do nothing
}
Here is a link to a Hello World program that you can use to test the update (just repeats "Hello World" via serial once a second):
https://www.dropbox.com/s/nj7c6ix723pwo8e/HelloWorld.WeMos.160MHz.Flash4MB.SPIFFS1MB.bin?dl=0
EDIT: deleted compiled program that would have only worked with my SSID and password. Spelling