|
#include
<Updater.h> String html = R"***( <!DOCTYPE html> <html> <body><h1>ESP8266 OTA</h1> <form method='POST' action='/update' enctype='multipart/form-data'> <input type='file' name='firmware'><input type='submit' value='Update'> </form> </body> </html> )***"; void OTAUpload() { HTTPUpload& upload = webServer.upload(); if (upload.status == UPLOAD_FILE_START) { size_t maxSpace = ESP.getFreeSketchSpace() & 0xFFFFF000; Update.begin(maxSpace); } else if (upload.status == UPLOAD_FILE_WRITE) { Update.write(upload.buf, upload.currentSize); } else if ( upload.status == UPLOAD_FILE_END) { Update.end(true); } } void OTAUpdate() { if (Update.hasError()) { webServer.send(200, "text/plain", "Update FAILED"); } else { webServer.send(200, "text/plain", "Update OK, rebooting..."); } delay(500); ESP.restart(); } ... // irgendwo im void setup() webServer.on("/ota", HTTP_GET, []() { webServer.send(200, "text/html", html); }); webServer.on("/update", HTTP_POST, OTAUpdate, OTAUpload); // Upload starten |