server.on("/update", HTTP_POST, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
ESP.restart();
}, []() {
HTTPUpload& upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
Serial.setDebugOutput(true);
WiFiUDP::stopAll();
Serial.printf("Update: %s\n", upload.filename.c_str());
uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
if (!Update.begin(maxSketchSpace)) { //start with max available size
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { //true to set the size to the current progress
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
} else {
Update.printError(Serial);
}
Serial.setDebugOutput(false);
}
yield();
});
I don't understand what this flags needs to be checked :
upload.status == UPLOAD_FILE_START
upload.status == UPLOAD_FILE_WRITE
upload.status == UPLOAD_FILE_END
I don't understand what those lines do in the code. Why do I need to check those flags? If I upload the file the data will be stored in server.upload(). Why do I need to ask about those flags?
I guess this is more a question regarding how a server works and not related to the program, but tried to find information about this and I can't find 'till now anything similar to what I found in this code.
If any of you can point to some reference, will be appreciated.
I guess I just want to understand each part of the code to get the big picture on how this code woks and not just cut and paste the code.
Thanks
Gastón