Update espmega_iot_core.cpp

This commit is contained in:
Siwat Sirichai 2023-10-01 13:48:02 +07:00
parent 8bd0fb5ecb
commit d301462298
1 changed files with 17 additions and 5 deletions

View File

@ -266,12 +266,15 @@ void ota_begin()
if (upload.status == UPLOAD_FILE_START)
{
lcd_send_command("page ota");
Serial.println(upload.currentSize);
String otafiletxt = "Downloading File : " + upload.filename;
panel.writeStr("otatxt.txt",otafiletxt);
lcd_send_stop_bit();
panel.writeStr("otatxt.txt", otafiletxt);
Serial.printf("Update: %s\n", upload.filename.c_str());
if (!Update.begin(UPDATE_SIZE_UNKNOWN))
{
panel.writeStr("otatxt.txt","Update Failed, Rebooting . . .");
panel.writeStr("otatxt.txt", "Update Failed, Rebooting . . .");
Update.printError(Serial);
}
}
@ -279,20 +282,29 @@ void ota_begin()
{
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize)
{
panel.writeStr("otatxt.txt","Update Failed, Rebooting . . .");
panel.writeStr("otatxt.txt", "Update Failed, Rebooting . . .");
Update.printError(Serial);
}
if (upload.currentSize != 0 && upload.totalSize != 0)
{
lcd_send_stop_bit();
uint32_t totalsize_kb = upload.totalSize / 1000;
uint32_t upload_pct = 100 * upload.totalSize/1000000;
String otafiletxt = "Downloading File : " + upload.filename + " ("+String(totalsize_kb) + "KB)";
panel.writeNum("prog.val", upload_pct);
panel.writeStr("otatxt.txt", otafiletxt);
}
}
else if (upload.status == UPLOAD_FILE_END)
{
if (Update.end(true))
{
panel.writeStr("otatxt.txt","Update Completed, Rebooting . . .");
panel.writeStr("otatxt.txt", "Update Completed, Rebooting . . .");
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
}
else
{
panel.writeStr("otatxt.txt","Update Failed, Rebooting . . .");
panel.writeStr("otatxt.txt", "Update Failed, Rebooting . . .");
Update.printError(Serial);
}
}