Hello,
I'm using ESPAsyncWebServer and I've managed to make OTA webpage working like this:
WebServer.on("/update", HTTP_GET, [](AsyncWebServerRequest *request)
{ ProcessUpdate(request); });
WebServer.on(
"/update", HTTP_POST, [](AsyncWebServerRequest *request) {},
[](AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final)
{ ProcessUpdate(request, filename, index, data, len, final); });
Where processupdate is:
void ProcessUpdate(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final)
{
if (!index)
{
update_status = "Update started!";
Serial.println("Update started");
update_content_len = request->contentLength();
Update.runAsync(true);
if (!Update.begin(update_content_len, U_FLASH))
{
Update.printError(Serial);
}
}
if (Update.write(data, len) != len)
{
Update.printError(Serial);
}
else
{
update_status = "Progress: " + String((Update.progress() * 100) / Update.size()) + "%";
Serial.println(update_status);
}
if (final)
{
AsyncWebServerResponse *response = request->beginResponse(302, "text/plain", "Please wait while the device reboots...");
response->addHeader("Refresh", "5");
response->addHeader("Location", "/");
request->send(response);
if (!Update.end(true))
{
Update.printError(Serial);
}
else
{
update_status = "Done!";
Serial.println("Update complete");
Serial.flush();
eDM_Config.Flags.RebootESP = 1;
}
}
}
How can I return the progress to webpage?
Thanks,
JS