Skip to content

Commit 61b9947

Browse files
authored
Merge pull request wled#4516 from willmmiles/aws-queue-0_16
Update AsyncWebServer and enable response queue
2 parents daa438b + e27fa88 commit 61b9947

File tree

8 files changed

+32
-15
lines changed

8 files changed

+32
-15
lines changed

platformio.ini

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ lib_deps =
140140
IRremoteESP8266 @ 2.8.2
141141
makuna/NeoPixelBus @ 2.8.0
142142
#https://github.com/makuna/NeoPixelBus.git#CoreShaderBeta
143-
https://github.com/Aircoookie/ESPAsyncWebServer.git#v2.2.1
143+
https://github.com/Aircoookie/ESPAsyncWebServer.git#v2.4.0
144144
# for I2C interface
145145
;Wire
146146
# ESP-NOW library
@@ -236,14 +236,15 @@ lib_deps_compat =
236236
IRremoteESP8266 @ 2.8.2
237237
makuna/NeoPixelBus @ 2.7.9
238238
https://github.com/blazoncek/QuickESPNow.git#optional-debug
239-
https://github.com/Aircoookie/ESPAsyncWebServer.git#v2.2.1
239+
https://github.com/Aircoookie/ESPAsyncWebServer.git#v2.4.0
240240

241241
[esp32_all_variants]
242242
lib_deps =
243-
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
243+
willmmiles/AsyncTCP @ 1.3.1
244244
bitbank2/AnimatedGIF@^1.4.7
245245
https://github.com/Aircoookie/GifDecoder#bc3af18
246246
build_flags =
247+
-D CONFIG_ASYNC_TCP_USE_WDT=0
247248
-D WLED_ENABLE_GIF
248249

249250
[esp32]
@@ -254,7 +255,6 @@ build_unflags = ${common.build_unflags}
254255
build_flags = -g
255256
-DARDUINO_ARCH_ESP32
256257
#-DCONFIG_LITTLEFS_FOR_IDF_3_2
257-
-D CONFIG_ASYNC_TCP_USE_WDT=0
258258
#use LITTLEFS library by lorol in ESP32 core 1.x.x instead of built-in in 2.x.x
259259
-D LOROL_LITTLEFS
260260
; -DARDUINO_USB_CDC_ON_BOOT=0 ;; this flag is mandatory for "classic ESP32" when building with arduino-esp32 >=2.0.3
@@ -289,7 +289,6 @@ build_unflags = ${common.build_unflags}
289289
build_flags = -g
290290
-Wshadow=compatible-local ;; emit warning in case a local variable "shadows" another local one
291291
-DARDUINO_ARCH_ESP32 -DESP32
292-
-D CONFIG_ASYNC_TCP_USE_WDT=0
293292
-DARDUINO_USB_CDC_ON_BOOT=0 ;; this flag is mandatory for "classic ESP32" when building with arduino-esp32 >=2.0.3
294293
${esp32_all_variants.build_flags}
295294
-D WLED_ENABLE_DMX_INPUT
@@ -307,7 +306,6 @@ build_flags = -g
307306
-DARDUINO_ARCH_ESP32
308307
-DARDUINO_ARCH_ESP32S2
309308
-DCONFIG_IDF_TARGET_ESP32S2=1
310-
-D CONFIG_ASYNC_TCP_USE_WDT=0
311309
-DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0
312310
-DCO
313311
-DARDUINO_USB_MODE=0 ;; this flag is mandatory for ESP32-S2 !
@@ -327,7 +325,6 @@ build_flags = -g
327325
-DARDUINO_ARCH_ESP32
328326
-DARDUINO_ARCH_ESP32C3
329327
-DCONFIG_IDF_TARGET_ESP32C3=1
330-
-D CONFIG_ASYNC_TCP_USE_WDT=0
331328
-DCO
332329
-DARDUINO_USB_MODE=1 ;; this flag is mandatory for ESP32-C3
333330
;; please make sure that the following flags are properly set (to 0 or 1) by your board.json, or included in your custom platformio_override.ini entry:
@@ -348,7 +345,6 @@ build_flags = -g
348345
-DARDUINO_ARCH_ESP32
349346
-DARDUINO_ARCH_ESP32S3
350347
-DCONFIG_IDF_TARGET_ESP32S3=1
351-
-D CONFIG_ASYNC_TCP_USE_WDT=0
352348
-DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_DFU_ON_BOOT=0
353349
-DCO
354350
;; please make sure that the following flags are properly set (to 0 or 1) by your board.json, or included in your custom platformio_override.ini entry:
@@ -646,7 +642,6 @@ build_flags = ${common.build_flags} ${esp32s2.build_flags} -D WLED_RELEASE_NAME=
646642
-DBOARD_HAS_PSRAM
647643
-DLOLIN_WIFI_FIX ; seems to work much better with this
648644
-D WLED_WATCHDOG_TIMEOUT=0
649-
-D CONFIG_ASYNC_TCP_USE_WDT=0
650645
-D DATA_PINS=16
651646
-D HW_PIN_SCL=35
652647
-D HW_PIN_SDA=33

tools/stress_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ read -a JSON_TINY_TARGETS <<< $(replicate "json/nodes")
2727
read -a JSON_SMALL_TARGETS <<< $(replicate "json/info")
2828
read -a JSON_LARGE_TARGETS <<< $(replicate "json/si")
2929
read -a JSON_LARGER_TARGETS <<< $(replicate "json/fxdata")
30+
read -a INDEX_TARGETS <<< $(replicate "")
3031

3132
# Expand target URLS to full arguments for curl
3233
TARGETS=(${TARGET_STR[@]})

wled00/const.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,25 @@
560560
#endif
561561
#endif
562562

563-
//#define MIN_HEAP_SIZE (8k for AsyncWebServer)
564-
#define MIN_HEAP_SIZE 8192
563+
//#define MIN_HEAP_SIZE
564+
#define MIN_HEAP_SIZE 2048
565+
566+
// Web server limits
567+
#ifdef ESP8266
568+
// Minimum heap to consider handling a request
569+
#define WLED_REQUEST_MIN_HEAP (8*1024)
570+
// Estimated maximum heap required by any one request
571+
#define WLED_REQUEST_HEAP_USAGE (6*1024)
572+
#else
573+
// ESP32 TCP stack needs much more RAM than ESP8266
574+
// Minimum heap remaining before queuing a request
575+
#define WLED_REQUEST_MIN_HEAP (12*1024)
576+
// Estimated maximum heap required by any one request
577+
#define WLED_REQUEST_HEAP_USAGE (12*1024)
578+
#endif
579+
// Maximum number of requests in queue; absolute cap on web server resource usage.
580+
// Websockets do not count against this limit.
581+
#define WLED_REQUEST_MAX_QUEUE 6
565582

566583
// Maximum size of node map (list of other WLED instances)
567584
#ifdef ESP8266

wled00/json.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ void serveJson(AsyncWebServerRequest* request)
10601060
}
10611061

10621062
if (!requestJSONBufferLock(17)) {
1063-
serveJsonError(request, 503, ERR_NOBUF);
1063+
request->deferResponse();
10641064
return;
10651065
}
10661066
// releaseJSONBufferLock() will be called when "response" is destroyed (from AsyncWebServer)

wled00/set.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
628628
//USERMODS
629629
if (subPage == SUBPAGE_UM)
630630
{
631-
if (!requestJSONBufferLock(5)) return;
631+
if (!requestJSONBufferLock(5)) {
632+
request->deferResponse();
633+
return;
634+
}
632635

633636
// global I2C & SPI pins
634637
int8_t hw_sda_pin = !request->arg(F("SDA")).length() ? -1 : (int)request->arg(F("SDA")).toInt();

wled00/wled.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ void WLED::loop()
303303
DEBUG_PRINTF_P(PSTR("Strip time[ms]:%u/%lu\n"), avgStripMillis/loops, maxStripMillis);
304304
}
305305
strip.printSize();
306+
server.printStatus(DEBUGOUT);
306307
loops = 0;
307308
maxLoopMillis = 0;
308309
maxUsermodMillis = 0;

wled00/wled.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ WLED_GLOBAL bool ledStatusState _INIT(false); // the current LED state
874874
#endif
875875

876876
// server library objects
877-
WLED_GLOBAL AsyncWebServer server _INIT_N(((80)));
877+
WLED_GLOBAL AsyncWebServer server _INIT_N(((80, {0, WLED_REQUEST_MAX_QUEUE, WLED_REQUEST_MIN_HEAP, WLED_REQUEST_HEAP_USAGE})));
878878
#ifdef WLED_ENABLE_WEBSOCKETS
879879
WLED_GLOBAL AsyncWebSocket ws _INIT_N((("/ws")));
880880
#endif

wled00/wled_server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ void initServer()
288288
bool isConfig = false;
289289

290290
if (!requestJSONBufferLock(14)) {
291-
serveJsonError(request, 503, ERR_NOBUF);
291+
request->deferResponse();
292292
return;
293293
}
294294

0 commit comments

Comments
 (0)