- Begin OTA. Wait updating ...
- OTA: 1%
- OTA: 2%
- OTA: 3%
- OTA: 4%
- OTA: 5%
- OTA: 6%
- OTA: 7%
- OTA: 8%
- ESP-ROM:esp32s3-20210327
- Build:Mar 27 2021
- rst:0x8 (TG1WDT_SYS_RST),boot:0x28 (SPI_FAST_FLASH_BOOT)
- Saved PC:0x403743c0
- SPIWP:0xee
- mode:DIO, clock div:1
This is the debugging section:
- #define CPR_ESP32OTA_HTTP_TIMEOUT 10000 //millis
- #define CPR_ESP32OTA_BIN_BUF_SIZE 4096
- bool CprESP32OTA::execOTA(UpdateClass::THandlerFunction_Progress fnProgress)
- {
- String url = "http://" + _host + _bin;
- HTTPClient http;
- http.setConnectTimeout(CPR_ESP32OTA_HTTP_TIMEOUT);
- http.setTimeout(CPR_ESP32OTA_HTTP_TIMEOUT);
- if(!http.begin(url))
- {
- Serial.printf("execOTA (%s): HTTP begin FAILED\n", url.c_str());
- return false;
- }
- if (http.GET() == HTTP_CODE_OK) //200
- {
- int totalLength = http.getSize();
- Serial.printf("%s: SIZE = %d\n", url.c_str(), totalLength);
- if(!Update.begin(totalLength))
- {
- Serial.printf("Update.begin ERR: %d (%s)\n", Update.getError(), Update.errorString());
- http.end();
- return false;
- }
- Serial.println("Begin OTA. Wait updating ...");
- // create buffer for read
- //uint8_t buff[CPR_ESP32OTA_BIN_BUF_SIZE] = { 0 };
- uint8_t *bin_buf = NULL;
- bin_buf = (uint8_t*)malloc(CPR_ESP32OTA_BIN_BUF_SIZE);
- memset(bin_buf, 0, CPR_ESP32OTA_BIN_BUF_SIZE);
- WiFiClient* stream = http.getStreamPtr(); // get tcp stream
- // read all data from server
- int dataWritten = 0;
- while (http.connected() && dataWritten < totalLength)
- {
- size_t sizeAvail = stream->available();
- if (sizeAvail > 0)
- {
- size_t bytes_to_read = min(sizeAvail, size_t(CPR_ESP32OTA_BIN_BUF_SIZE));
- //Serial.printf("bytes_to_read = %d\n", bytes_to_read);
- size_t bytes_read = stream->readBytes((char*)bin_buf, bytes_to_read);
- //Serial.printf("bytes_to_read = %d, bytes_read = %d\n", bytes_to_read, bytes_read);
- size_t bytes_written = Update.write(bin_buf, bytes_read);
- //Serial.printf("bytes_to_read = %d, bytes_read = %d, bytes_written = %d\n", bytes_to_read, bytes_read, bytes_written);
- if (bytes_read != bytes_written)
- {
- Serial.printf("Update.write ERR: %d %d %d\n", bytes_to_read, bytes_read, bytes_written);
- break;
- }
- dataWritten += bytes_written;
- if (fnProgress != NULL) fnProgress(dataWritten, totalLength);
- }
- //esp_task_wdt_reset();
- }
- free(bin_buf);
- bin_buf = NULL;
- if (dataWritten == totalLength)
- Serial.println("Written : " + String(dataWritten) + " successfully");
- else
- Serial.println("Written only : " + String(dataWritten) + "/" + String(totalLength));
- if (Update.end())
- {
- Serial.println("OTA done!");
- if (Update.isFinished())
- {
- Serial.println("Update completed. execOTA END");
- http.end();
- return true;
- }
- else
- Serial.println("Update not finished? Something went wrong!");
- }
- else
- Serial.printf("Update.end ERR: %d (%s)\n", Update.getError(), Update.errorString());
- }
- http.end();
- return false;
- }