Skip to content

Latest commit

 

History

History
141 lines (101 loc) · 6.74 KB

README.md

File metadata and controls

141 lines (101 loc) · 6.74 KB

https://avatars.githubusercontent.com/u/195753706?s=96&v=4

ESPAsyncWebServer

Latest Release PlatformIO Registry

License: LGPL 3.0 Contributor Covenant

GitHub latest commit Gitpod Ready-to-Code

ESP32Async Discord Server

Documentation

Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266 and RP2040

Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc.

Documentation

The complete project documentation is available in the Wiki section.

How to install

The library can be downloaded from the releases page at https://github.com/ESP32Async/ESPAsyncWebServer/releases.

It is also deployed in these registries:

Dependencies

ESP32 / pioarduino

[env:stable]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
lib_compat_mode = strict
lib_ldf_mode = chain
lib_deps =
  ESP32Async/AsyncTCP
  ESP32Async/ESPAsyncWebServer

ESP8266 / pioarduino

[env:stable]
platform = espressif8266
lib_compat_mode = strict
lib_ldf_mode = chain
lib_deps =
  ESP32Async/ESPAsyncTCP
  ESP32Async/ESPAsyncWebServer

Unofficial dependencies

AsyncTCPSock

AsyncTCPSock can be used instead of AsyncTCP by excluding AsyncTCP from the library dependencies and adding AsyncTCPSock instead:

lib_compat_mode = strict
lib_ldf_mode = chain
lib_deps =
  https://github.com/ESP32Async/AsyncTCPSock/archive/refs/tags/v1.0.3-dev.zip
  ESP32Async/ESPAsyncWebServer
lib_ignore =
  AsyncTCP
  ESP32Async/AsyncTCP

AsyncTCP_RP2040W

AsyncTCP_RP2040W provides support for RP2040 and replaced AsyncTCP in this case:

lib_compat_mode = strict
lib_ldf_mode = chain
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = rpipicow
board_build.core = earlephilhower
lib_deps =
  khoih-prog/AsyncTCP_RP2040W @ 1.2.0
  ESP32Async/ESPAsyncWebServer
lib_ignore =
  lwIP_ESPHost
build_flags = ${env.build_flags}
  -Wno-missing-field-initializers

Important recommendations for build options

Most of the crashes are caused by improper use or configuration of the AsyncTCP library used for the project. Here are some recommendations to avoid them and build-time flags you can change.

CONFIG_ASYNC_TCP_MAX_ACK_TIME - defines a timeout for TCP connection to be considered alive when waiting for data. In some bad network conditions you might consider increasing it.

CONFIG_ASYNC_TCP_QUEUE_SIZE - defines the length of the queue for events related to connections handling. Both the server and AsyncTCP library were optimized to control the queue automatically. Do NOT try blindly increasing the queue size, it does not help you in a way you might think it is. If you receive debug messages about queue throttling, try to optimize your server callbacks code to execute as fast as possible. Read #165 thread, it might give you some hints.

CONFIG_ASYNC_TCP_RUNNING_CORE - CPU core thread affinity that runs the queue events handling and executes server callbacks. Default is ANY core, so it means that for dualcore SoCs both cores could handle server activities. If your server's code is too heavy and unoptimized or you see that sometimes server might affect other network activities, you might consider to bind it to the same core that runs Arduino code (1) to minimize affect on radio part. Otherwise you can leave the default to let RTOS decide where to run the thread based on priority

CONFIG_ASYNC_TCP_STACK_SIZE - stack size for the thread that runs sever events and callbacks. Default is 16k that is a way too much waste for well-defined short async code or simple static file handling. You might want to cosider reducing it to 4-8k to same RAM usage. If you do not know what this is or not sure about your callback code demands - leave it as default, should be enough even for very hungry callbacks in most cases.

Note

This relates to ESP32 only, ESP8266 uses different ESPAsyncTCP lib that does not has this build options

I personally use the following configuration in my projects:

  -D CONFIG_ASYNC_TCP_MAX_ACK_TIME=5000   // (keep default)
  -D CONFIG_ASYNC_TCP_PRIORITY=10         // (keep default)
  -D CONFIG_ASYNC_TCP_QUEUE_SIZE=64       // (keep default)
  -D CONFIG_ASYNC_TCP_RUNNING_CORE=1      // force async_tcp task to be on same core as Arduino app (default is any core)
  -D CONFIG_ASYNC_TCP_STACK_SIZE=4096     // reduce the stack size (default is 16K)

If you need to serve chunk requests with a really low buffer (which should be avoided), you can set -D ASYNCWEBSERVER_USE_CHUNK_INFLIGHT=0 to disable the in-flight control.