ISSUE:
In most of our web server and MQTT projects, we use the following libraries (that are currently deprecated):
- ESPASyncWebServer: https://github.com/me-no-dev/ESPAsyncWebServer
- AsyncTCP: https://github.com/me-no-dev/asynctcp
Using these libraries will result in the following error and constant rebooting of the ESP32:
assert failed: tcp_alloc /IDF/components/lwip/lwip/src/core/tcp.c:1851 (Required to lock TCPIP core functionality!)
SOLUTION:
To fix this issue, you must use the newest fork of those libraries, available on the following links:
- ESPAsyncWebServer: https://github.com/ESP32Async/ESPAsyncWebServer (at least version 3.6.2)
- AsyncTCP: https://github.com/ESP32Async/AsyncTCP (at least version 3.3.2)
Follow these instructions to solve the issue:
- Go to the Arduino Libraries Manager: Sketch > Include Library > Manage Libraries
- UNINSTALL any previous versions of the ESPAsyncWebServer and AsyncTCP libraries
- Now, you can install the latest version of the new fork. Follow the next instructions:
To guarantee that you’re using the latest version of the ESPAsyncWebServer and AsyncTCP libraries, please install them via ZIP folder (don’t use the Library Manager that will currently install an older version with issues).
Click the following links to download the library files.
- Click here to download the ESPAsyncWebServer
- Click here to download the Async TCP library.
In your Arduino IDE, go to Sketch > Include Library > Add .zip Library and select the libraries you’ve just downloaded.
Compile your code again. This will work with the latest version of the ESP32 core.
I have a MQTT project in VSCode / Platformio that at one time ran great on my esp32-s3 and RPI-5. I attempted to upgrade the code but once downloaded I get the following error
” assert failed: tcp_alloc /IDF/components/lwip/lwip/src/core/tcp.c:1851 (Required to lock TCPIP core functionality!)”
Here is a list of included files:
#include <Arduino.h>
#include <OneWire.h>
#include “DallasTemperature.h”
#include <WiFi.h>
#include <AsyncMqttClient.h>
#include <string>
extern “C”
{
#include “freertos/FreeRTOS.h” //
#include “freertos/timers.h”
}
and libraries:
lib_deps =
marvinroger/AsyncMqttClient@^0.9.0
paulstoffregen/OneWire@^2.3.8
milesburton/DallasTemperature@^4.0.5
I’m not using the ESPAsyncWebServer or AsyncTCP libraries. Please help me figure out how to clear this error.
Hi.
When you say you atempted to upgrade the code, what do you mean exactly?
Can you share your complete plaformio.ini file?
Regards,
Sara
There were some features of my original working program that I wanted to improve. When I made the changes I started to receive the error and reboot issue. Even when I reflashed the esp with the once working version the problem remains. As the program was written several years back, there have been changes to the api version and I since changed to pioarduino. Here is a copy of the full platformio.ini file minus the comments:
[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
lib_deps =
marvinroger/AsyncMqttClient@^0.9.0
paulstoffregen/OneWire@^2.3.8
milesburton/DallasTemperature@^4.0.5
Thanks for looking at this. I asked copilot to look at the code and his suggestions fixed the issue. Here is the output summary:
Patch applied — changes summary:
Added lwIP header include: #include “lwip/tcpip.h”
Added function connectOnTcpipThread(void*) that calls mqttClient.connect().
Replaced direct mqttClient.connect() call in the main loop with tcpip_callback(connectOnTcpipThread, NULL).
Why this should fix the assert
tcpip_callback schedules a function to run on the lwIP TCPIP thread while holding the required TCPIP core lock. Any allocations or TCP operations performed there won’t trigger the tcp_alloc assert.
This is safer than calling connect() from event/timer contexts or even the main loop if the library expects to run on the TCPIP thread.
Hi.
Thanks for sharing that.
We would have suggested adding the following line to your platformio.ini file:
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
Instead of:
platform = espressif32
But, if it is working as expected now, it’s better to proceed at it is.
Regards,
Sara