Skip to content

Commit

Permalink
Merge pull request #4516 from willmmiles/aws-queue-0_16
Browse files Browse the repository at this point in the history
Update AsyncWebServer and enable response queue
  • Loading branch information
netmindz authored Jan 26, 2025
2 parents daa438b + e27fa88 commit 61b9947
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
13 changes: 4 additions & 9 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ lib_deps =
IRremoteESP8266 @ 2.8.2
makuna/NeoPixelBus @ 2.8.0
#https://github.com/makuna/NeoPixelBus.git#CoreShaderBeta
https://github.com/Aircoookie/ESPAsyncWebServer.git#v2.2.1
https://github.com/Aircoookie/ESPAsyncWebServer.git#v2.4.0
# for I2C interface
;Wire
# ESP-NOW library
Expand Down Expand Up @@ -236,14 +236,15 @@ lib_deps_compat =
IRremoteESP8266 @ 2.8.2
makuna/NeoPixelBus @ 2.7.9
https://github.com/blazoncek/QuickESPNow.git#optional-debug
https://github.com/Aircoookie/ESPAsyncWebServer.git#v2.2.1
https://github.com/Aircoookie/ESPAsyncWebServer.git#v2.4.0

[esp32_all_variants]
lib_deps =
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
willmmiles/AsyncTCP @ 1.3.1
bitbank2/AnimatedGIF@^1.4.7
https://github.com/Aircoookie/GifDecoder#bc3af18
build_flags =
-D CONFIG_ASYNC_TCP_USE_WDT=0
-D WLED_ENABLE_GIF

[esp32]
Expand All @@ -254,7 +255,6 @@ build_unflags = ${common.build_unflags}
build_flags = -g
-DARDUINO_ARCH_ESP32
#-DCONFIG_LITTLEFS_FOR_IDF_3_2
-D CONFIG_ASYNC_TCP_USE_WDT=0
#use LITTLEFS library by lorol in ESP32 core 1.x.x instead of built-in in 2.x.x
-D LOROL_LITTLEFS
; -DARDUINO_USB_CDC_ON_BOOT=0 ;; this flag is mandatory for "classic ESP32" when building with arduino-esp32 >=2.0.3
Expand Down Expand Up @@ -289,7 +289,6 @@ build_unflags = ${common.build_unflags}
build_flags = -g
-Wshadow=compatible-local ;; emit warning in case a local variable "shadows" another local one
-DARDUINO_ARCH_ESP32 -DESP32
-D CONFIG_ASYNC_TCP_USE_WDT=0
-DARDUINO_USB_CDC_ON_BOOT=0 ;; this flag is mandatory for "classic ESP32" when building with arduino-esp32 >=2.0.3
${esp32_all_variants.build_flags}
-D WLED_ENABLE_DMX_INPUT
Expand All @@ -307,7 +306,6 @@ build_flags = -g
-DARDUINO_ARCH_ESP32
-DARDUINO_ARCH_ESP32S2
-DCONFIG_IDF_TARGET_ESP32S2=1
-D CONFIG_ASYNC_TCP_USE_WDT=0
-DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0
-DCO
-DARDUINO_USB_MODE=0 ;; this flag is mandatory for ESP32-S2 !
Expand All @@ -327,7 +325,6 @@ build_flags = -g
-DARDUINO_ARCH_ESP32
-DARDUINO_ARCH_ESP32C3
-DCONFIG_IDF_TARGET_ESP32C3=1
-D CONFIG_ASYNC_TCP_USE_WDT=0
-DCO
-DARDUINO_USB_MODE=1 ;; this flag is mandatory for ESP32-C3
;; 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:
Expand All @@ -348,7 +345,6 @@ build_flags = -g
-DARDUINO_ARCH_ESP32
-DARDUINO_ARCH_ESP32S3
-DCONFIG_IDF_TARGET_ESP32S3=1
-D CONFIG_ASYNC_TCP_USE_WDT=0
-DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_DFU_ON_BOOT=0
-DCO
;; 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:
Expand Down Expand Up @@ -646,7 +642,6 @@ build_flags = ${common.build_flags} ${esp32s2.build_flags} -D WLED_RELEASE_NAME=
-DBOARD_HAS_PSRAM
-DLOLIN_WIFI_FIX ; seems to work much better with this
-D WLED_WATCHDOG_TIMEOUT=0
-D CONFIG_ASYNC_TCP_USE_WDT=0
-D DATA_PINS=16
-D HW_PIN_SCL=35
-D HW_PIN_SDA=33
Expand Down
1 change: 1 addition & 0 deletions tools/stress_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ read -a JSON_TINY_TARGETS <<< $(replicate "json/nodes")
read -a JSON_SMALL_TARGETS <<< $(replicate "json/info")
read -a JSON_LARGE_TARGETS <<< $(replicate "json/si")
read -a JSON_LARGER_TARGETS <<< $(replicate "json/fxdata")
read -a INDEX_TARGETS <<< $(replicate "")

# Expand target URLS to full arguments for curl
TARGETS=(${TARGET_STR[@]})
Expand Down
21 changes: 19 additions & 2 deletions wled00/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,25 @@
#endif
#endif

//#define MIN_HEAP_SIZE (8k for AsyncWebServer)
#define MIN_HEAP_SIZE 8192
//#define MIN_HEAP_SIZE
#define MIN_HEAP_SIZE 2048

// Web server limits
#ifdef ESP8266
// Minimum heap to consider handling a request
#define WLED_REQUEST_MIN_HEAP (8*1024)
// Estimated maximum heap required by any one request
#define WLED_REQUEST_HEAP_USAGE (6*1024)
#else
// ESP32 TCP stack needs much more RAM than ESP8266
// Minimum heap remaining before queuing a request
#define WLED_REQUEST_MIN_HEAP (12*1024)
// Estimated maximum heap required by any one request
#define WLED_REQUEST_HEAP_USAGE (12*1024)
#endif
// Maximum number of requests in queue; absolute cap on web server resource usage.
// Websockets do not count against this limit.
#define WLED_REQUEST_MAX_QUEUE 6

// Maximum size of node map (list of other WLED instances)
#ifdef ESP8266
Expand Down
2 changes: 1 addition & 1 deletion wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ void serveJson(AsyncWebServerRequest* request)
}

if (!requestJSONBufferLock(17)) {
serveJsonError(request, 503, ERR_NOBUF);
request->deferResponse();
return;
}
// releaseJSONBufferLock() will be called when "response" is destroyed (from AsyncWebServer)
Expand Down
5 changes: 4 additions & 1 deletion wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
//USERMODS
if (subPage == SUBPAGE_UM)
{
if (!requestJSONBufferLock(5)) return;
if (!requestJSONBufferLock(5)) {
request->deferResponse();
return;
}

// global I2C & SPI pins
int8_t hw_sda_pin = !request->arg(F("SDA")).length() ? -1 : (int)request->arg(F("SDA")).toInt();
Expand Down
1 change: 1 addition & 0 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ void WLED::loop()
DEBUG_PRINTF_P(PSTR("Strip time[ms]:%u/%lu\n"), avgStripMillis/loops, maxStripMillis);
}
strip.printSize();
server.printStatus(DEBUGOUT);
loops = 0;
maxLoopMillis = 0;
maxUsermodMillis = 0;
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ WLED_GLOBAL bool ledStatusState _INIT(false); // the current LED state
#endif

// server library objects
WLED_GLOBAL AsyncWebServer server _INIT_N(((80)));
WLED_GLOBAL AsyncWebServer server _INIT_N(((80, {0, WLED_REQUEST_MAX_QUEUE, WLED_REQUEST_MIN_HEAP, WLED_REQUEST_HEAP_USAGE})));
#ifdef WLED_ENABLE_WEBSOCKETS
WLED_GLOBAL AsyncWebSocket ws _INIT_N((("/ws")));
#endif
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void initServer()
bool isConfig = false;

if (!requestJSONBufferLock(14)) {
serveJsonError(request, 503, ERR_NOBUF);
request->deferResponse();
return;
}

Expand Down

0 comments on commit 61b9947

Please sign in to comment.