Skip to content

Prototype ESP8266 support - #122

Draft
willmmiles wants to merge 1 commit into
mainfrom
esp8266-support
Draft

willmmiles wants to merge 1 commit into
mainfrom
esp8266-support

Conversation

@willmmiles

Copy link
Copy Markdown

Believe it or not, basic support for the venerable ESP8266 required only fairly shallow changes to this library:

  • Import the logging bits from AsyncWebServer
  • Abstract over LwIP's err_t
  • Add "direct" versions of the LwIP wrappers, without tcpip_api_call
    • This has some intrinsic value anyways - they'll be very slightly more efficient when CONFIG_LWIP_TCPIP_CORE_LOCKING is set. It wasn't worth the extra code complexity to maintain two versions without some other advantage, though.
  • (Ab)use the ESP8266 Arduino core Schedule primitive to simulate a task in the cooperative environment. Not the most efficient but functional.

I did some very basic testing with the WebSocketsTest example in AsyncWebServer; it had no trouble with an overnight run. (It did require enabling progmem forgiveness but I have not yet looked at why.)

Opened more for discussion than anything else. If there's any interest in pursuing this, I'd suggest giving some thought to breaking AsyncTCP.cpp down into smaller chunks - perhaps local headers - for easier management.

Further thoughts:

  • A "no async task" mode that runs callbacks right off the LwIP task, like ESPAsyncTCP used to do. This has potential value for high performance applications on ESP32 as well. It may or may not dovetail with allowing multiple async tasks.
  • There's probably a better tool than Schedule abuse: it requires an awful lot of heap traffic this way (specifically, an additional allocation per event). Possibly schedule_recurrent_function_us offers a cleaner generic "add something to a polling engine" API.

@dimecho

dimecho commented Sep 6, 2026

Copy link
Copy Markdown

Added BearSSL support for my project, can do a pull request if this goes through.

commit 2d0a41b

@dimecho

dimecho commented Sep 8, 2026

Copy link
Copy Markdown

Found a bug,

#ifndef NO_SYS should be #if !NO_SYS otherwise ESP32 crashes with tcp_bind /IDF/components/lwip/lwip/src/core/tcp.c:677 (Required to lock TCPIP core functionality!)

@mathieucarbou

Copy link
Copy Markdown
Member

@willmmiles : this pr is still a work in progress or just needs some CI tweaks and ready for review ?

@willmmiles

Copy link
Copy Markdown
Author

It needs to be re-done properly. I've posted it more as a proof-of-concept demo in case I don't get back to it and someone else wants to follow up.

The issues that need to be addressed are, in short:

  • Making a proper abstraction boundary over tcpip_api_call usage. tcpip_api_call is actually only needed on ESP32 arduino-2; arduino-3 would actually be correct and more efficient using the functions introduced here for the 8266, wrapped with tcp_core_guard. The tricky bit is managing the tradeoff between sharing code (at the cost of efficiency on arduino-2) or duplicating code. (Also there is some significant churn incoming in that logic with safety issues surfaced around Fix safety issues with AsyncClient destruction in user callbacks #123.)
  • Cleaner abstraction boundary over the queue task to avoid the giant #ifdef sections cluttering up the file
  • An option to process more than one event per scheduler call
  • Fix the bugs (like the NO_SYS inversion)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants