I tried to download file from a server, it works perfectly for file until around 30ko but when I try for more bigger file (around 1000ko), system crash.
I use this code
Code: Select all
int HandleWriteFileFromServer()
{
HTTPClient http;
http.setTimeout(30000);
http.begin("http://boisurel.com/wp-content/uploads/2023/04/Capteur-solaire-en-facade-2604x1800.jpg");
int httpCode = http.GET();
if (httpCode <= 0) {
//Error HTTP failed
printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
http.end();
WifiFirmwareUpdate = false;
return 0;
}
int contentLen = http.getSize();
int len = http.getSize();
printf("Downloading: file should be %i\n", len);
WiFiClient* client = http.getStreamPtr();
client->setTimeout(2); // Définis timeout client
Serial.print("Start");
//size_t written = Update.writeStream(*client);
const size_t bufferSize = 1024; // Taille du tampon de lecture
uint8_t buffer[bufferSize]; // Tampon de lecture
size_t written = 0;
size_t bytesRead = 0;
size_t bytesWritten =0;
size_t size = 0;
unsigned long sortir = millis();
File fileToCreate = LittleFS.open("/Chart1.json", "w"); // Créer le nouveau fichier
while (written != contentLen && client->available()) {
if(!http.connected()){Serial.println("Déconnceté");}
size = client->available();
Serial.print("Size : ");
Serial.print(size);
bytesRead = client->readBytes(buffer, min(bufferSize, size));
Serial.print(".");
bytesWritten = fileToCreate.write(buffer, bytesRead);
Serial.print(". W : ");
written += bytesWritten;
Serial.println(written);
if(millis() - sortir >= 30000)
{
Serial.println("Temps dépassé, échec du téléchargement");
break;
}
if (bytesRead != bytesWritten) {
// Erreur d'écriture
Serial.print("Erreur d'écriture du firmware : ");
Serial.print(bytesRead);
Serial.print(" / ");
Serial.print(bytesWritten);
http.end();
WifiFirmwareUpdate = false;
return 0;
}
delay(1);
}
Serial.print("fichier créé");
fileToCreate.close();
http.end();
return 1;
}
Code: Select all
Size : 3503.. W : 610304
Size : 5351.. W : 611328
Size : 5763.. W : 612352
Size : 4739.. W : 613376
Size : 3715.. W : 614400
Size : 5563.. W : 615424
Size : 4539
E (115742) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (115742) task_wdt: - async_tcp (CPU 0/1)
E (115742) task_wdt: Tasks currently running:
E (115742) task_wdt: CPU 0: IDLE
E (115742) task_wdt: CPU 1: IDLE
Sometime it stop at 200000, sometimes at 500000 without reproductible number...
Is someone have any idea of what happens ?
Thanks for your help,
Antonin