Hey guys,
How could I block through some if() within the arduino code the UPDATE.
When I upload a file to the web server page and click UPLOAD nothing should happen. Progress (1 to 100%) must not evolve.
I use this basic UPDATE configuration:
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.printf("Update: %s\n", upload.filename.c_str());
if (!Update.begin(UPDATE_SIZE_UNKNOWN)) {
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)) { //para definir o tamanho para o progresso atual
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
} else {
Update.printError(Serial);
}
}
});
Well if you want to block the initialization of the process, you can do
server.on("/update", HTTP_POST, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
ESP.restart();
}, []() {
if (!server.authenticate("user", "password")) {
return server.requestAuthentication();
// or just
// server.send(200, "text/plain","Upload Blocked");
// return;
}
HTTPUpload& upload = server.upload(); // this is where the process is actually started.
if (upload.status == UPLOAD_FILE_START) {
Serial.printf("Update: %s\n", upload.filename.c_str());
if (!Update.begin(UPDATE_SIZE_UNKNOWN)) {
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)) { //para definir o tamanho para o progresso atual
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
} else {
Update.printError(Serial);
}
}
});
Of course the actual initialization starts with the navigation and the choosing of the file, followed by the "POST" request.
Tested. Progress even evolves but in fact when it reaches 100% nothing happens. And that's what I needed. Thank you very much.
system
Closed
4
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.