Hi all,
I'm struggling with a watchdog reset.
What I'm trying to do, is to download a FW image (self OTA) using ftp client.
I chosed FTP, since I already are using it within the same project, for downloading a smaller file (~150kb) and it has been working great.
Now, when I download the ESP binary, which is larger, it always gives me a watchdog reset.
17:32:53.899 -> Downloading tester_fw.bin, size 1020688
17:35:12.820 -> ets Jul 29 2019 12:21:46
17:35:12.820 ->
17:35:12.820 -> rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
17:35:12.820 -> configsip: 0, SPIWP:0xee
17:35:12.820 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
17:35:12.820 -> mode:DIO, clock div:1
17:35:12.820 -> load:0x3fff0030,len:1344
17:35:12.820 -> load:0x40078000,len:13964
17:35:12.898 -> load:0x40080400,len:3600
17:35:12.898 -> entry 0x400805f0
I'm calling the download from setup(), have tried also from loop, but it does not seem to make much difference.
The loop in the ftp client, looks like this;
while(dclient.available())
{
esp_task_wdt_reset();
delay(50);
if( length >= 512)
{
dclient.readBytes(_buf, 512);
if(file.write(_buf, 512) == 512){
//FTPdbgn(".");
}
length -= 512;
}
else
{
dclient.readBytes(_buf, length);
if(file.write(_buf, length) == length){
//FTPdbgn(".");
}
length = 0;
}
}
The esp_task_wdt_reset() I threw in, but it does not seem to make any difference - perhaps this is not the same watchdog(?), if I understand correctly, there are multiple watchdogs in esp32.
I then inserted the delay(50), which makes a difference - without it, the watchdog comes already after around 40 seconds.
I am now thinking, that it is the filesystem that is not happy.
Edit: if I remove the file write line, it only takes about 3 seconds to download, and no watchdog time (which makes sense, of course).
I hope someone can say "but you forgot to ..." - I'm at loss.
This is the complete ftp function for reference;
void ESP32_FTPClient::DownloadFileFS(fs::FS &fs, const char * filename, size_t length) {
FTPdbgn("Send RETR");
if(!isConnected()) return;
client.print(F("RETR "));
client.println(F(filename));
char _resp[ sizeof(outBuf) ];
GetFTPAnswer(_resp);
uint8_t _buf[512];
unsigned long _m = millis();
String _filename = String("/") + String(F(filename));
File file = fs.open(_filename.c_str(), FILE_WRITE);
if (!file)
{
Serial.println("Failed to open file for writing");
return;
}
while( !dclient.available() && millis() < _m + timeout) delay(1);
while(dclient.available())
{
esp_task_wdt_reset();
delay(50);
if( length >= 512)
{
dclient.readBytes(_buf, 512);
if(file.write(_buf, 512) == 512){
//FTPdbgn(".");
}
length -= 512;
}
else
{
dclient.readBytes(_buf, length);
if(file.write(_buf, length) == length){
//FTPdbgn(".");
}
length = 0;
}
}
file.close();
}
Any help/suggestions appreciated!