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
further Infos on following error message: assert failed: tcp_alloc /IDF/components/lwip/lwip/src/core/tcp.c:1854 (Required to lock TCPIP core functionality!)
Why works PubSubClient, but not AsyncMqttClient together with an older version of AsyncTCP for Arduino-IDE 2.x ?
Library
Eigener Task?
FreeRTOS‑Timer?
LWIP‑safe?
CYD‑Board stabil?
AsyncMqttClient
Ja
Ja
Nein
❌ Crash
PubSubClient
Nein
Nein
Ja
✔️ stabil
Pls check and remove the entire directory of older versions of AsyncTCP and use the forked version, provided by Sara. Check the compiler-output to ensure which version is taken ..
The AsyncMQTT library that we recommend works.
It’s a forked version that we created: https://github.com/RuiSantosdotme/async-mqtt-client/
You must install it via .ZIP file.
Regards,
Sara
Hi Sara,
I have exactly this lib from your link installed (async-mqtt-client-develop.zip), included by the Arduino-IDE 2.3.7.
Additional I have the Async TCP from ESP32Async, V 3.4.10 by the lib-manager installed.
When running the examples 5_6_1_MQTT_Publish_Button_Counter.ino or 5_6_2_MQTT_Publish_Button_On_Off.ino, then there are cyclic SW-Resets with the error-message:
WiFi connected
IP address:
192.168.178.76
Connecting to MQTT...
assert failed: tcp_alloc /IDF/components/lwip/lwip/src/core/tcp.c:1854 (Required to lock TCPIP core functionality!)
After some research I found the PubSubClient-Lib, thread-safe running without timers and tasks. Afterwards also both arduino-programs are stable running together with node-red. update from 14.02.26: An older version of AsyncTCP was taken by the compliler, although that is not installed, but physically located on disc (inside ..\Arduino15\lib..).
update:
Hi Sara,
I have now applied the patch, described by Brian. Now it works fine with Async_TCP from ESP32Async, V 3.4.10 and async-mqtt-client-develop.zip. In this context, I found, that the arduino-IDE has used an older version of AsyncTCP, although I did install the correct one additionally. This was apparently the root cause for the cyclic SW-Resets ..
Hi.
Great.
I’m glad it is working now.
But, did you try with our version of the library? Our fork?
Because for me, it works as expected without further modifications.
Regards,
Sara
Hi Sara,
thank-you for your fast response.
You are right, the mqtt-client on the CYD is now working as expected with your forked lib “AsyncTCP-main.zip” (Arduino-IDE shows V 3.4.10 from ESP32Async).
I suppose the problem is (was), that an older version of AsyncTCP (although it wasn’t installed inside the Arduino-IDE 2.x), rather possibly installed on an previous Arduino-Version 1.x in the past was taken:
c:\Users\gerald\AppData\Local\Arduino15\libraries\AsyncTCP. In the context of troubleshooting I found, that the Arduino-IDE (2.3.7) has taken this version, and reported that the your forked version was only detected, but not applied. So I have this lib physically removed under ..\Arduino15\ .. and the mqtt-client works correctly !!!
Pls excuse my confusion, I’m very sorry.
PS: The patched version from Brian combined with the older version of AsyncTCP, that is leading not longer to a SW-Reset, but the mqtt-client does not connect to the broker !!
Regards,
Gerald