In my project I use the ESPAsyncWebServer. If an WebServer-event occurs, I need to call functions. These functions are fairly large and also contain some code, which require some time to execute. Due to that I sometimes receive Watchdog timeouts.
To fix this, I would like to outsource the functions, so they no longer run in the same task, as the webserver.
Here is a short code snippet as an example:
void onEvent(AsyncWebSocket *server,
AsyncWebSocketClient *client,
AwsEventType type,
void *arg,
uint8_t *data,
size_t len) {
switch (type) {
case WS_EVT_CONNECT:
Serial.printf("WebSocket client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str());
break;
case WS_EVT_DISCONNECT:
Serial.printf("WebSocket client #%u disconnected\n", client->id());
break;
case WS_EVT_DATA:
handleWebSocketMessage(arg, data, len);
break;
case WS_EVT_PONG:
case WS_EVT_ERROR:
break;
}
}
void handleWebSocketMessage(void *arg, uint8_t *data, size_t len) {
AwsFrameInfo *info = (AwsFrameInfo*)arg;
if (info->final && info->index == 0 && info->len == len && info->opcode == WS_TEXT) {
data[len] = 0;
if (strcmp((char*)data, "toggle1") == 0) {
function1();
}
if (strcmp((char*)data, "toggle2") == 0) {
function2();
}
if (strcmp((char*)data, "toggle3") == 0) {
function3();
}
...
}
}
The functions: function1(), function2(), function2() should run on a different task and should be executed if they are called by the handleWebSocketMessage-Function.
I don’t want to use flags, as the functions also contain several parameters, which are passed by the “uint8_t *data”-Element (via ArduinoJson).
Basically, all I want to achieve, is that the function “handleWebSocketMessage” don’t has to wait for the execution of the individual functions.
Has anybody an idea how to achieve that?