ESPAsyncWebServer icon indicating copy to clipboard operation
ESPAsyncWebServer copied to clipboard

Compiling issues

Open c0debreaker opened this issue 1 year ago • 17 comments

I'm getting the errors below. If I remove #include <ESPAsyncWebServer.h> and other related code, the compile becomes successful. What did I do someting wrong?

/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/WebAuthentication.cpp: In function 'bool getMD5(uint8_t*, uint16_t, char*)':
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/WebAuthentication.cpp:74:3: error: 'mbedtls_md5_starts_ret' was not declared in this scope; did you mean 'mbedtls_md5_starts'?
   74 |   mbedtls_md5_starts_ret(&_ctx);
      |   ^~~~~~~~~~~~~~~~~~~~~~
      |   mbedtls_md5_starts
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/WebAuthentication.cpp:75:3: error: 'mbedtls_md5_update_ret' was not declared in this scope; did you mean 'mbedtls_md5_update'?
   75 |   mbedtls_md5_update_ret(&_ctx, data, len);
      |   ^~~~~~~~~~~~~~~~~~~~~~
      |   mbedtls_md5_update
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/WebAuthentication.cpp:76:3: error: 'mbedtls_md5_finish_ret' was not declared in this scope; did you mean 'mbedtls_md5_finish'?
   76 |   mbedtls_md5_finish_ret(&_ctx, _buf);
      |   ^~~~~~~~~~~~~~~~~~~~~~
      |   mbedtls_md5_finish
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/AsyncEventSource.cpp: In member function 'void AsyncEventSourceClient::_queueMessage(AsyncEventSourceMessage*)':
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/AsyncEventSource.cpp:188:7: error: 'ets_printf' was not declared in this scope; did you mean 'vswprintf'?
  188 |       ets_printf("ERROR: Too many messages queued\n");
      |       ^~~~~~~~~~
      |       vswprintf
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/AsyncWebSocket.cpp: In member function 'void AsyncWebSocketClient::_queueMessage(AsyncWebSocketMessage*)':
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/AsyncWebSocket.cpp:551:7: error: 'ets_printf' was not declared in this scope; did you mean 'vswprintf'?
  551 |       ets_printf("ERROR: Too many messages queued\n");
      |       ^~~~~~~~~~
      |       vswprintf
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/AsyncWebSocket.cpp: In member function 'IPAddress AsyncWebSocketClient::remoteIP()':
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/AsyncWebSocket.cpp:832:28: error: call of overloaded 'IPAddress(unsigned int)' is ambiguous
  832 |         return IPAddress(0U);
      |                            ^
In file included from /home/rcamara/.arduino15/packages/esp32/hardware/esp32/3.0.0/cores/esp32/Arduino.h:196,
                 from /home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/AsyncWebSocket.cpp:21:
/home/rcamara/.arduino15/packages/esp32/hardware/esp32/3.0.0/cores/esp32/IPAddress.h:115:3: note: candidate: 'IPAddress::IPAddress(const ip_addr_t*)'
  115 |   IPAddress(const ip_addr_t *addr);
      |   ^~~~~~~~~
/home/rcamara/.arduino15/packages/esp32/hardware/esp32/3.0.0/cores/esp32/IPAddress.h:73:3: note: candidate: 'IPAddress::IPAddress(const IPAddress&)'
   73 |   IPAddress(const IPAddress &address);
      |   ^~~~~~~~~
/home/rcamara/.arduino15/packages/esp32/hardware/esp32/3.0.0/cores/esp32/IPAddress.h:72:3: note: candidate: 'IPAddress::IPAddress(const char*)'
   72 |   IPAddress(const char *address);
      |   ^~~~~~~~~
/home/rcamara/.arduino15/packages/esp32/hardware/esp32/3.0.0/cores/esp32/IPAddress.h:69:3: note: candidate: 'IPAddress::IPAddress(const uint8_t*)'
   69 |   IPAddress(const uint8_t *address);
      |   ^~~~~~~~~
/home/rcamara/.arduino15/packages/esp32/hardware/esp32/3.0.0/cores/esp32/IPAddress.h:67:3: note: candidate: 'IPAddress::IPAddress(uint32_t)'
   67 |   IPAddress(uint32_t address);
      |   ^~~~~~~~~
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/AsyncWebSocket.cpp: In constructor 'AsyncWebSocketResponse::AsyncWebSocketResponse(const String&, AsyncWebSocket*)':
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/AsyncWebSocket.cpp:1262:3: error: 'mbedtls_sha1_starts_ret' was not declared in this scope; did you mean 'mbedtls_sha1_starts'?
 1262 |   mbedtls_sha1_starts_ret(&ctx);
      |   ^~~~~~~~~~~~~~~~~~~~~~~
      |   mbedtls_sha1_starts
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/AsyncWebSocket.cpp:1263:3: error: 'mbedtls_sha1_update_ret' was not declared in this scope; did you mean 'mbedtls_sha1_update'?
 1263 |   mbedtls_sha1_update_ret(&ctx, (const unsigned char*)key.c_str(), key.length());
      |   ^~~~~~~~~~~~~~~~~~~~~~~
      |   mbedtls_sha1_update
/home/rcamara/Arduino/libraries/ESP_Async_WebServer/src/AsyncWebSocket.cpp:1264:3: error: 'mbedtls_sha1_finish_ret' was not declared in this scope; did you mean 'mbedtls_sha1_finish'?
 1264 |   mbedtls_sha1_finish_ret(&ctx, hash);
      |   ^~~~~~~~~~~~~~~~~~~~~~~
      |   mbedtls_sha1_finish
Multiple libraries were found for "WiFi.h"
  Used: /home/rcamara/.arduino15/packages/esp32/hardware/esp32/3.0.0/libraries/WiFi
  Not used: /home/rcamara/Arduino/libraries/WiFiNINA
exit status 1

Compilation error: exit status 1

and my source code is

#include <Arduino.h>
#include <WiFi.h>
#include <LittleFS.h>
#include <ESPAsyncWebServer.h>

// Replace with your network credentials
const char* ssid = "******";
const char* password = "******";

AsyncWebServer server(80);

void setup() {
  // Start Serial for debug output
  Serial.begin(115200);

  // Initialize LittleFS
  if (!LittleFS.begin()) {
    Serial.println("An Error has occurred while mounting LittleFS");
    return;
  }

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");

  // Serve static files from LittleFS
  server.serveStatic("/", LittleFS, "/").setDefaultFile("index.html");

  // Handle 404 (Not Found)
  server.onNotFound([](AsyncWebServerRequest *request) {
    request->send(404, "text/plain", "Not found");
  });

  // Start server
  server.begin();
}

void loop() {
  // Nothing needed here
}

c0debreaker avatar Jun 02 '24 07:06 c0debreaker

This needs guardrails for when to include, but here are the necessary includes

diff --git a/src/AsyncEventSource.cpp b/src/AsyncEventSource.cpp
index f2914df..230e3f6 100644
--- a/src/AsyncEventSource.cpp
+++ b/src/AsyncEventSource.cpp
@@ -19,6 +19,7 @@
 */
 #include "Arduino.h"
 #include "AsyncEventSource.h"
+#include "rom/ets_sys.h"
 
 static String generateEventMessage(const char *message, const char *event, uint32_t id, uint32_t reconnect){
   String ev = "";
diff --git a/src/AsyncWebSocket.cpp b/src/AsyncWebSocket.cpp
index f76f2fc..ef94775 100644
--- a/src/AsyncWebSocket.cpp
+++ b/src/AsyncWebSocket.cpp
@@ -28,6 +28,7 @@
 #else
 #include <Hash.h>
 #endif
+#include "mbedtls/compat-2.x.h"
 
 #define MAX_PRINTF_LEN 64
 
@@ -829,7 +830,7 @@ void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer * buffer)
 
 IPAddress AsyncWebSocketClient::remoteIP() {
     if(!_client) {
-        return IPAddress(0U);
+        return IPAddress(0,0,0,0);
     }
     return _client->remoteIP();
 }
diff --git a/src/WebAuthentication.cpp b/src/WebAuthentication.cpp
index 45246a1..01fb567 100644
--- a/src/WebAuthentication.cpp
+++ b/src/WebAuthentication.cpp
@@ -22,6 +22,7 @@
 #include <libb64/cencode.h>
 #ifdef ESP32
 #include "mbedtls/md5.h"
+#include "mbedtls/compat-2.x.h"
 #else
 #include "md5.h"
 #endif

lbernstone avatar Jun 02 '24 19:06 lbernstone

This needs guardrails for when to include, but here are the necessary includes

diff --git a/src/AsyncEventSource.cpp b/src/AsyncEventSource.cpp
index f2914df..230e3f6 100644
--- a/src/AsyncEventSource.cpp
+++ b/src/AsyncEventSource.cpp
@@ -19,6 +19,7 @@
 */
 #include "Arduino.h"
 #include "AsyncEventSource.h"
+#include "rom/ets_sys.h"
 
 static String generateEventMessage(const char *message, const char *event, uint32_t id, uint32_t reconnect){
   String ev = "";
diff --git a/src/AsyncWebSocket.cpp b/src/AsyncWebSocket.cpp
index f76f2fc..ef94775 100644
--- a/src/AsyncWebSocket.cpp
+++ b/src/AsyncWebSocket.cpp
@@ -28,6 +28,7 @@
 #else
 #include <Hash.h>
 #endif
+#include "mbedtls/compat-2.x.h"
 
 #define MAX_PRINTF_LEN 64
 
@@ -829,7 +830,7 @@ void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer * buffer)
 
 IPAddress AsyncWebSocketClient::remoteIP() {
     if(!_client) {
-        return IPAddress(0U);
+        return IPAddress(0,0,0,0);
     }
     return _client->remoteIP();
 }
diff --git a/src/WebAuthentication.cpp b/src/WebAuthentication.cpp
index 45246a1..01fb567 100644
--- a/src/WebAuthentication.cpp
+++ b/src/WebAuthentication.cpp
@@ -22,6 +22,7 @@
 #include <libb64/cencode.h>
 #ifdef ESP32
 #include "mbedtls/md5.h"
+#include "mbedtls/compat-2.x.h"
 #else
 #include "md5.h"
 #endif

Hi lbernstone,

I see there are 3 files that needs to be updated. I can update it manually. However, I like to learn how to update it from your given code. What tool should I use for that? It looks similar to some diffs I've seen very long time ago using patch command. Thanks a lot!

c0debreaker avatar Jun 02 '24 19:06 c0debreaker

That was a git diff. It was updated with my own 2 hands :) I just looked at what was missing, grep'd for those functions in the arduino-esp32/tools/esp32-arduino-libs/esp32/include folder, and included those files in the correct locations. To make a PR, I need to figure out a way to only include those headers if the version is >3.0.0.

lbernstone avatar Jun 02 '24 19:06 lbernstone

Oh got it. I knew I will have issues when Arduino popped up something on the lower right corner. Do you want to update to 3.0.0? I said yes. Few hours later, I encountered the issues above.

Alrighty, I'll make changes to my local. Thank you.

c0debreaker avatar Jun 03 '24 02:06 c0debreaker

I add the lines above with the + on them I got this: /Users/jcdonelson/Documents/Arduino/libraries/ESPAsyncWebServer/src/AsyncWebSocket.cpp: In member function 'void AsyncWebSocketClient::_queueMessage(AsyncWebSocketMessage*)': /Users/jcdonelson/Documents/Arduino/libraries/ESPAsyncWebServer/src/AsyncWebSocket.cpp:551:7: error: 'ets_printf' was not declared in this scope; did you mean 'vswprintf'? 551 | ets_printf("ERROR: Too many messages queued\n"); | ^~~~~~~~~~ | vswprintf If I comment out line 551 then it all compiles.

jimdgit avatar Jun 03 '24 18:06 jimdgit

That was a git diff. It was updated with my own 2 hands :) I just looked at what was missing, grep'd for those functions in the arduino-esp32/tools/esp32-arduino-libs/esp32/include folder, and included those files in the correct locations. To make a PR, I need to figure out a way to only include those headers if the version is >3.0.0.

I found this:

#ifdef ESP_ARDUINO_VERSION_MAJOR
            #if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(3, 0, 0)
                                                  // Code for version 3.x

                   #else
                                                 // Code for version 2.x
                   #ifdef ESP32

                   #else
 

                    #endif
                 #endif
                #endif

on https://github.com/h2zero/NimBLE-Arduino/issues/676#issuecomment-2160799917, from a comment made by ednieuw. ednieuw says they got this piece of code from the Espressif migration 2.x -> 3.x document. Supposedly, this piece of code makes a library compatible for both ESP32 versions. I hope this helps.

Update: I found a file with a piece a code explaining the manipulation of the ESP32 versions better in the Espressif's official repository for Arduino core for the ESP32. A little bit more information can be found in Espressif's Compatibility Guide for ESP32 Arduino Core page

capc0307 avatar Jun 13 '24 01:06 capc0307

If I comment out line 551 then it all compiles.

Just an observation, but in AsyncWebSocket.cpp the ets_printf() function is used 7 times, but 6 of these are commented out. The one that triggers the compile error is the only one that is not commented out. Perhaps that one got missed when the debug lines were added and commented out six years ago.

I can confirm that after making the changes above and commenting out this line, it compiles and seems to work fine on an ESP32 dev board.

joyfullservice avatar Jun 14 '24 18:06 joyfullservice

Is this already fixed? I am trying to build a project with this library and I have the same problem. In particular, there is a problem when I execute request->send().

kalwinskidawid avatar Aug 14 '24 12:08 kalwinskidawid

i changed it to printf... dont do that!

so maybe ::printf instead of ets_printf?

seandepagnier avatar Aug 28 '24 20:08 seandepagnier

I've encountered the same errors as the original poster, and managed to fix them by following @lbernstone 's recommendations for extra #include statements, as well as @jimdgit 's recommendation to comment out line #551 in AsyncWebSocket.cpp.

Unfortunately I'm still experiencing a compilation error.

Here's the compilation error message:

/Users/aran/Library/Arduino15/packages/esp32/tools/esp-x32/2405/bin/xtensa-esp32-elf-g++ @/Users/aran/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32/flags/ld_flags @/Users/aran/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32/flags/ld_scripts -Wl,--Map=/private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/sketch_sep6b.ino.map -L/Users/aran/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32/lib -L/Users/aran/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32/ld -L/Users/aran/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32/dio_qspi -Wl,--wrap=esp_panic_handler -Wl,--start-group /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/sketch/sketch_sep6b.ino.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/WiFi/AP.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/WiFi/STA.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/WiFi/WiFi.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/WiFi/WiFiAP.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/WiFi/WiFiGeneric.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/WiFi/WiFiMulti.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/WiFi/WiFiSTA.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/WiFi/WiFiScan.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/Network/NetworkClient.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/Network/NetworkEvents.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/Network/NetworkInterface.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/Network/NetworkManager.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/Network/NetworkServer.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/Network/NetworkUdp.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/ESPAsyncWebServer/AsyncEventSource.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/ESPAsyncWebServer/AsyncWebSocket.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/ESPAsyncWebServer/WebAuthentication.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/ESPAsyncWebServer/WebHandlers.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/ESPAsyncWebServer/WebRequest.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/ESPAsyncWebServer/WebResponses.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/ESPAsyncWebServer/WebServer.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/FS/FS.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/FS/vfs_api.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/AsyncTCP/AsyncTCP.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/LittleFS/LittleFS.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/core/variant.cpp.o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/cores/9dc0c0ccb082ebf96739fc43da6b9c53/core.a @/Users/aran/Library/Arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-466a392a/esp32/flags/ld_libs -Wl,--end-group -Wl,-EL -o /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/sketch_sep6b.ino.elf
/Users/aran/Library/Arduino15/packages/esp32/tools/esp-x32/2405/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: /private/var/folders/0p/vzf6vcfj7_z0hqd8j7ksbymh0000gn/T/arduino/sketches/A9D9498DC5653A959082DB29939625EC/libraries/ESPAsyncWebServer/AsyncWebSocket.cpp.o:(.literal._ZN17AsyncWebLockGuardC5ERK12AsyncWebLock[_ZN17AsyncWebLockGuardC5ERK12AsyncWebLock]+0x0): **undefined reference to `pxCurrentTCB'**
**collect2: error: ld returned 1 exit status**

And here's a simplified form of my code that still creates this error:

// LIBRARIES
#include <Arduino.h>
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include "LittleFS.h"
#include <AsyncTCP.h>

// Set up Network
const char* ssid = "******";
const char* password = "******";
AsyncWebServer server(80);    // Create AsyncWebServer object on port 80
AsyncWebSocket ws("/ws");     // Create a WebSocket object

// Initialize LittleFS
void initFS() {
  if (!LittleFS.begin()) {
    Serial.println("An error has occurred while mounting LittleFS");
  }
  else{
   Serial.println("LittleFS mounted successfully");
  }
}

// Initialize WiFi
void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println(WiFi.localIP());
}

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) {
    /*
    Parse web socket message here
    */
  }
}

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 initWebSocket() {
  ws.onEvent(onEvent);
  server.addHandler(&ws);
}

void setup() {
  Serial.begin(115200);
  LittleFS.begin();

  initFS();
  initWiFi();

  // Web Server Root URL
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(LittleFS, "/index.html", "text/html");
  });
  
  server.serveStatic("/", LittleFS, "/");

  // Start server
  server.begin();



}

void loop() {



}

I can find the offending lines of code in AsyncWebSynchronization.h, lines 32-35 here:

  bool lock() const {
    extern void *pxCurrentTCB;
    if (_lockedBy != pxCurrentTCB) {
      xSemaphoreTake(_lock, portMAX_DELAY);
      _lockedBy = pxCurrentTCB;
      return true;
    }
    return false;
  }

But I'm not sure what to try next to debug this. Please could you give me some help for what to try next?

Arduino Version: 2.3.2

Using library WiFi at version 3.1.0 Using library Networking at version 3.1.0 Using library ESP Async WebServer at version 1.2.4 Using library FS at version 3.1.0 Using library AsyncTCP at version 1.1.1 Using library LittleFS at version 3.1.0

Mac OS 13.5 Using Adafruit Huzzah32 Feather v2 (as here)

aranFish avatar Sep 06 '24 20:09 aranFish

OK I've made the lock() function in AsyncWebSynchronization.h always return false, by commenting out other lines inside that function. My very basic code is now working. I'll keep an eye out for what I've broken as I build up the complexity of the firmware again.

aranFish avatar Sep 07 '24 11:09 aranFish

A good fix I found and tried with success is to modify the file AsyncWebSynchronization.h using the following steps :

  1. Add after the #ifdef ESP32 at line 9 : #include "esp_private/freertos_debug.h".

  2. Modify line 29 with: void *_pxCurrentTCB = pvTaskGetCurrentTCBForCore(esp_cpu_get_core_id());.

  3. Replace subsequent references of pxCurrentTCB with _pxCurrentTCB (at line 30 and 32).

MOUMOUDOU avatar Nov 30 '24 21:11 MOUMOUDOU

This has been fixed by https://github.com/me-no-dev/ESPAsyncWebServer/commit/17a8d442169f3ca8496b20ebd24bbc06f55d4a62

@c0debreaker please install the latest version of the library from this GitHub repository (make sure you don't install one of the forks which haven't pulled down the fix), then check to see if the bug is fixed. If so, you can close the issue by clicking the "Close issue" button here on the issue web page.

per1234 avatar Dec 17 '24 07:12 per1234

@per1234 I'm using version 1.2.4 straight from this repository with Arduino core 3.1.0 and am still getting the pxCurrentTCB issue. It doesn't appear to have been fixed. Thanks

PureTek-Innovations avatar Jan 02 '25 19:01 PureTek-Innovations

I am using version 1.2.9 and esp32 3.1.0 and also getting the issue.

misterjtc avatar Jan 03 '25 16:01 misterjtc

still getting the pxCurrentTCB issue

@PureTek-Innovations this issue is not about pxCurrentTCB, and my comment was not about pxCurrentTCB. The problem with pxCurrentTCB is tracked in a separate issue: https://github.com/me-no-dev/ESPAsyncWebServer/issues/1442. So it is not productive to discuss it here.

per1234 avatar Jan 03 '25 19:01 per1234

I am using version 1.2.9

@misterjtc there is no such version so you must be using one of the forks of the repository. Uninstall that version and then install the library from this repository. You can't install this library via the Arduino Library Manager (https://github.com/me-no-dev/ESPAsyncWebServer/issues/1433). If you are using Arduino IDE, you can install it by the following procedure:

  1. Click the following link to open the library's GitHub repository homepage in your web browser: https://github.com/me-no-dev/ESPAsyncWebServer
  2. Click the "Code ▾" button you see on that page.
  3. Select Download ZIP from the menu. A download of the ZIP file of the library will start.
  4. Wait for the download to finish.
  5. Select Sketch > Include library > Add .ZIP Library from the Arduino IDE menus. The "Select the zip file containing the library you'd like to add" dialog will open.
  6. Select the downloaded file from the dialog.
  7. Click the "Open" button. The dialog will close.
  8. Wait for the installation process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    ⓘ Successfully installed library from ...

per1234 avatar Jan 03 '25 19:01 per1234