Gianluca Grasso
Gianluca Grasso

Reputation: 1

esp32 rest chuncked response

Im trying to know the real wifi speed capabilities of the esp32, and so i created a simple routine using a common library

void speedTest(AsyncWebServerRequest *request)
{


    static uint8_t data[1024] = {0};
    static uint32_t dataLen = 1*1024*1024;


    memcpy(data, "ciao", 4);

    AsyncWebServerResponse *response = request->beginChunkedResponse("application/octet-stream", [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {

      size_t len = (dataLen>maxLen)?maxLen:dataLen;

      if (len>0)
      {
        memcpy(buffer, data, len);
        dataLen -= len;
        index += len;
        
      }

      
      return len;
      
    });
    response->setContentLength(dataLen);
    request->send(response);
}

but when i make the GET request, the board reset itself and in serial monitor i see the following log:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
E (17770) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (17770) task_wdt: - async_tcp (CPU 0/1)
E (17770) task_wdt: Tasks currently running:
E (17770) task_wdt: CPU 0: IDLE0
E (17770) task_wdt: CPU 1: loopTask
E (17770) task_wdt: Aborting.
abort() was called at PC 0x40131b44 on core 0

I also have tried to reduce the file size and the download goes fine, but for my purpose is useless. Someone has already meet and solved this problem ? im not really a lambda lover, alternately a different library more customizable, if is possible I would not like to reimplement all the http protocol over socket. thanks in adavance for the help.

comeplete code:



#include <Arduino.h>
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#endif
#include <ESPAsyncWebServer.h>




IPAddress local_ip(192,168,1,1);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
AsyncWebServer server(80);

const char* ssid = "testSpeed";
const char* psw = "12345678";





void notFound(AsyncWebServerRequest *request)
{
    request->send(404, "text/plain", "Not found");
}



void speedTest(AsyncWebServerRequest *request)
{


    #if 1
    static uint8_t data[1024] = {0};
    static uint32_t dataLen = 1*1024*1024;


    memcpy(data, "ciao", 4);

    AsyncWebServerResponse *response = request->beginChunkedResponse("application/octet-stream", [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {

      size_t len = (dataLen>maxLen)?maxLen:dataLen;

      if (len>0)
      {
        memcpy(buffer, data, len);
        dataLen -= len;
        index += len;
        
      }

      
      return len;
      
    });
    response->setContentLength(dataLen);
    request->send(response);
    #endif

    



}



void setup() {

    Serial.begin(115200);
    

    WiFi.mode(WIFI_AP);
    WiFi.softAP(ssid, psw);
    WiFi.softAPConfig(local_ip, gateway, subnet);


    server.on("/stream", HTTP_GET, speedTest);


    server.onNotFound(notFound);
    server.begin();
}




void loop() {

}

Upvotes: 0

Views: 927

Answers (1)

Tarmo
Tarmo

Reputation: 4762

Looks like the implementation of AsyncWebServer is not meant for long-running transactions, as it never resets the task watchdog. As a workaround you can increase the watchdog timeout to its maximum limit of 60 s or disable it entirely. It's controlled by the following options in sdkconfig:

CONFIG_ESP_TASK_WDT=y            # Task Watchdog is enabled
CONFIG_ESP_TASK_WDT_PANIC=y      # Panic (reset) is invoked on timeout
CONFIG_ESP_TASK_WDT_TIMEOUT_S=30 # Timeout in seconds

The normal way to change those is to run idf.py menuconfig (where they appear under "Component config", "Common ESP-related") but you can just update the file "sdkconfig" directly.

Undo those changes after you're finished with your experiments, it's usually a good idea to keep the Task Watchdog enabled.

Upvotes: 0

Related Questions