Skip to content

Commit 514d194

Browse files
Merge pull request #35 from ESP32Async/doc
(doc) Documentation update
2 parents 6738e16 + f779040 commit 514d194

File tree

1 file changed

+128
-86
lines changed

1 file changed

+128
-86
lines changed

README.md

Lines changed: 128 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,143 @@
1212
[![GitHub latest commit](https://badgen.net/github/last-commit/ESP32Async/ESPAsyncWebServer)](https://GitHub.com/ESP32Async/ESPAsyncWebServer/commit/)
1313
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/ESP32Async/ESPAsyncWebServer)
1414

15-
Project moved to [ESP32Async](https://github.com/ESP32Async) organization at [https://github.com/ESP32Async/ESPAsyncWebServer](https://github.com/ESP32Async/ESPAsyncWebServer)
16-
1715
Discord Server: [https://discord.gg/X7zpGdyUcY](https://discord.gg/X7zpGdyUcY)
1816

19-
Please see the new links:
20-
21-
- `ESP32Async/ESPAsyncWebServer` (ESP32, ESP8266, RP2040)
22-
- `ESP32Async/AsyncTCP` (ESP32)
23-
- `ESP32Async/ESPAsyncTCP` (ESP8266)
24-
- `https://github.com/ESP32Async/AsyncTCPSock/archive/refs/tags/v1.0.3-dev.zip` (AsyncTCP alternative for ESP32)
25-
- `khoih-prog/AsyncTCP_RP2040W` (RP2040)
17+
## Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266 and RP2040
2618

27-
Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266 and RP2040
2819
Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc.
2920

30-
- [Changes in this repository](#changes-in-this-repository)
21+
- [Compatibility](#compatibility)
22+
- [How to install](#how-to-install)
3123
- [Dependencies](#dependencies)
32-
- [Performance](#performance)
24+
- [ESP32 / pioarduino](#esp32--pioarduino)
25+
- [ESP8266 / pioarduino](#esp8266--pioarduino)
26+
- [Unofficial dependencies](#unofficial-dependencies)
3327
- [Important recommendations for build options](#important-recommendations-for-build-options)
28+
- [Changes in this repository](#changes-in-this-repository)
29+
- [Performance](#performance)
3430
- [`AsyncWebSocketMessageBuffer` and `makeBuffer()`](#asyncwebsocketmessagebuffer-and-makebuffer)
3531
- [How to replace a response](#how-to-replace-a-response)
3632
- [How to use Middleware](#how-to-use-middleware)
37-
- [How to use authentication with AsyncAuthenticationMiddleware](#how-to-use-authentication-with-authenticationmiddleware)
33+
- [How to use authentication with AsyncAuthenticationMiddleware](#how-to-use-authentication-with-asyncauthenticationmiddleware)
3834
- [Migration to Middleware to improve performance and memory usage](#migration-to-middleware-to-improve-performance-and-memory-usage)
3935
- [Original Documentation](#original-documentation)
4036

37+
## Compatibility
38+
39+
- ESP32, ESP8266, RP2040
40+
- Arduino Core 2.x and 3.x
41+
42+
## How to install
43+
44+
The library can be downloaded from the releases page at [https://github.com/ESP32Async/ESPAsyncWebServer/releases](https://github.com/ESP32Async/ESPAsyncWebServer/releases).
45+
46+
It is also deployed in these registries:
47+
48+
- Arduino Library Registry: [https://github.com/arduino/library-registry](https://github.com/arduino/library-registry)
49+
50+
- ESP Component Registry [https://components.espressif.com/components/esp32async/espasyncbebserver/](https://components.espressif.com/components/esp32async/espasyncbebserver/)
51+
52+
- PlatformIO Registry: [https://registry.platformio.org/libraries/esp32async/ESPAsyncWebServer](https://registry.platformio.org/libraries/esp32async/ESPAsyncWebServer)
53+
54+
- Use: `lib_deps=ESP32Async/ESPAsyncWebServer` to point to latest version
55+
- Use: `lib_deps=ESP32Async/ESPAsyncWebServer @ ^<x.y.z>` to point to latest version with the same major version
56+
- Use: `lib_deps=ESP32Async/ESPAsyncWebServer @ <x.y.z>` to always point to the same version (reproductible build)
57+
58+
## Dependencies
59+
60+
### ESP32 / pioarduino
61+
62+
```ini
63+
[env:stable]
64+
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
65+
lib_compat_mode = strict
66+
lib_ldf_mode = chain
67+
lib_deps =
68+
ESP32Async/AsyncTCP
69+
ESP32Async/ESPAsyncWebServer
70+
```
71+
72+
### ESP8266 / pioarduino
73+
74+
```ini
75+
[env:stable]
76+
platform = espressif8266
77+
lib_compat_mode = strict
78+
lib_ldf_mode = chain
79+
lib_deps =
80+
ESP32Async/ESPAsyncTCP
81+
ESP32Async/ESPAsyncWebServer
82+
```
83+
84+
### Unofficial dependencies
85+
86+
**AsyncTCPSock**
87+
88+
AsyncTCPSock can be used instead of AsyncTCP by excluding AsyncTCP from the library dependencies and adding AsyncTCPSock instead:
89+
90+
```ini
91+
lib_compat_mode = strict
92+
lib_ldf_mode = chain
93+
lib_deps =
94+
https://github.com/ESP32Async/AsyncTCPSock/archive/refs/tags/v1.0.3-dev.zip
95+
ESP32Async/ESPAsyncWebServer
96+
lib_ignore =
97+
AsyncTCP
98+
ESP32Async/AsyncTCP
99+
```
100+
101+
**AsyncTCP_RP2040W**
102+
103+
AsyncTCP_RP2040W provides support for RP2040 and replaced AsyncTCP in this case:
104+
105+
```ini
106+
lib_compat_mode = strict
107+
lib_ldf_mode = chain
108+
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
109+
board = rpipicow
110+
board_build.core = earlephilhower
111+
lib_deps =
112+
khoih-prog/AsyncTCP_RP2040W @ 1.2.0
113+
ESP32Async/ESPAsyncWebServer
114+
lib_ignore =
115+
lwIP_ESPHost
116+
build_flags = ${env.build_flags}
117+
-Wno-missing-field-initializers
118+
```
119+
120+
## Important recommendations for build options
121+
122+
Most of the crashes are caused by improper use or configuration of the AsyncTCP library used for the project.
123+
Here are some recommendations to avoid them and build-time flags you can change.
124+
125+
`CONFIG_ASYNC_TCP_MAX_ACK_TIME` - defines a timeout for TCP connection to be considered alive when waiting for data.
126+
In some bad network conditions you might consider increasing it.
127+
128+
`CONFIG_ASYNC_TCP_QUEUE_SIZE` - defines the length of the queue for events related to connections handling.
129+
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.
130+
Read #165 thread, it might give you some hints.
131+
132+
`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
133+
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
134+
135+
`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.
136+
137+
> [!NOTE]
138+
> This relates to ESP32 only, ESP8266 uses different ESPAsyncTCP lib that does not has this build options
139+
140+
I personally use the following configuration in my projects:
141+
142+
```c++
143+
-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=5000 // (keep default)
144+
-D CONFIG_ASYNC_TCP_PRIORITY=10 // (keep default)
145+
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=64 // (keep default)
146+
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1 // force async_tcp task to be on same core as Arduino app (default is any core)
147+
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096 // reduce the stack size (default is 16K)
148+
```
149+
150+
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.
151+
41152
## Changes in this repository
42153

43154
- (bug) A lot of bug fixes
@@ -65,11 +176,9 @@ Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static Fi
65176
- (perf) Lot of code cleanup and optimizations
66177
- (perf) Performance improvements in terms of memory, speed and size
67178

68-
---
69-
70-
## WARNING: Important notes about future version 4.x
179+
**WARNING: Important notes about future version 4.x**
71180

72-
This ESPAsyncWebServer fork is now at version 3.x, where we try to keep the API compatibility with original project as much as possible.
181+
ESPAsyncWebServer is now at version 3.x, where we try to keep the API compatibility with original project as much as possible.
73182

74183
We plan on creating a next major 4.x version that will:
75184

@@ -85,41 +194,6 @@ Maintaining a library for ESP8266 and RP2040 has a real cost and clearly what we
85194

86195
If you are an ESP8266 user and want to help improve current 3.x, you are more than welcomed to contribute to this community effort.
87196

88-
## Dependencies
89-
90-
> [!WARNING]
91-
> The library name was changed from `ESP Async WebServer` to `ESPAsyncWebServer` as per the Arduino Lint recommendations, but its name had to stay `ESP Async WebServer` in Arduino Registry.
92-
93-
**PlatformIO / pioarduino:**
94-
95-
```ini
96-
lib_compat_mode = strict
97-
lib_ldf_mode = chain
98-
lib_deps = ESP32Async/ESPAsyncWebServer
99-
```
100-
101-
**Dependencies:**
102-
103-
- **ESP32 with AsyncTCP**: [`ESP32Async/AsyncTCP`](https://github.com/ESP32Async/AsyncTCP/releases)
104-
- **ESP32 with AsyncTCPSock**: `https://github.com/ESP32Async/AsyncTCPSock/archive/refs/tags/v1.0.3-dev.zip`
105-
- **ESP8266**: [`ESP32Async/ESPAsyncTCP`](https://github.com/ESP32Async/ESPAsyncTCP/releases)
106-
- **RP2040**: [`khoih-prog/AsyncTCP_RP2040W`](https://github.com/khoih-prog/AsyncTCP_RP2040W/releases)
107-
108-
**AsyncTCPSock**
109-
110-
AsyncTCPSock can be used instead of AsyncTCP by excluding AsyncTCP from the library dependencies and adding AsyncTCPSock instead:
111-
112-
```ini
113-
lib_compat_mode = strict
114-
lib_ldf_mode = chain
115-
lib_deps =
116-
https://github.com/ESP32Async/AsyncTCPSock/archive/refs/tags/v1.0.3-dev.zip
117-
ESP32Async/ESPAsyncWebServer
118-
lib_ignore =
119-
AsyncTCP
120-
ESP32Async/AsyncTCP
121-
```
122-
123197
## Performance
124198

125199
Performance of `ESP32Async/ESPAsyncWebServer`:
@@ -129,7 +203,7 @@ Performance of `ESP32Async/ESPAsyncWebServer`:
129203
> autocannon -c 10 -w 10 -d 20 http://192.168.4.1
130204
```
131205

132-
With `ESP32Async/AsyncTCP @ 3.3.2`
206+
With `ESP32Async/AsyncTCP`
133207

134208
<img width="629" alt="perf-c10" src="https://github.com/user-attachments/assets/b4b7f953-c24d-4e04-8d87-ba3f26805737" />
135209

@@ -171,43 +245,11 @@ Test is running for 20 seconds with 10 connections.
171245
// Total: 2038 events, 509.50 events / second
172246
```
173247

174-
## Important recommendations for build options
175-
176-
Most of the crashes are caused by improper use or configuration of the AsyncTCP library used for the project.
177-
Here are some recommendations to avoid them and build-time flags you can change.
178-
179-
`CONFIG_ASYNC_TCP_MAX_ACK_TIME` - defines a timeout for TCP connection to be considered alive when waiting for data.
180-
In some bad network conditions you might consider increasing it.
181-
182-
`CONFIG_ASYNC_TCP_QUEUE_SIZE` - defines the length of the queue for events related to connections handling.
183-
Both the server and AsyncTCP library in this fork 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.
184-
Read #165 thread, it might give you some hints.
185-
186-
`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
187-
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
188-
189-
`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.
190-
191-
> [!NOTE]
192-
> This relates to ESP32 only, ESP8266 uses different ESPAsyncTCP lib that does not has this build options
193-
194-
I personally use the following configuration in my projects:
195-
196-
```c++
197-
-D CONFIG_ASYNC_TCP_MAX_ACK_TIME=5000 // (keep default)
198-
-D CONFIG_ASYNC_TCP_PRIORITY=10 // (keep default)
199-
-D CONFIG_ASYNC_TCP_QUEUE_SIZE=64 // (keep default)
200-
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1 // force async_tcp task to be on same core as Arduino app (default is any core)
201-
-D CONFIG_ASYNC_TCP_STACK_SIZE=4096 // reduce the stack size (default is 16K)
202-
```
203-
204-
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.
205-
206248
## `AsyncWebSocketMessageBuffer` and `makeBuffer()`
207249

208250
The fork from [yubox-node-org](https://github.com/yubox-node-org/ESPAsyncWebServer) introduces some breaking API changes compared to the original library, especially regarding the use of `std::shared_ptr<std::vector<uint8_t>>` for WebSocket.
209251

210-
This fork is compatible with the original library from [me-no-dev](https://github.com/me-no-dev/ESPAsyncWebServer) regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class.
252+
This library is compatible with the original library from [me-no-dev](https://github.com/me-no-dev/ESPAsyncWebServer) regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class.
211253
So you have the choice of which API to use.
212254

213255
Here are examples for serializing a Json document in a websocket message buffer:

0 commit comments

Comments
 (0)