Skip to content

Commit

Permalink
Merge pull request #104 from mathieucarbou/update
Browse files Browse the repository at this point in the history
Version update + perf improvement from #103
  • Loading branch information
ayushsharma82 authored Oct 21, 2024
2 parents 4a60f7c + e7c5b49 commit 5e418e7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ jobs:
run: arduino-cli core install --additional-urls "${{ matrix.index_url }}" ${{ matrix.core }}

- name: Install AsyncTCP
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/AsyncTCP#v3.2.5
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/AsyncTCP#v3.2.6

- name: Install ESPAsyncTCP
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/esphome-ESPAsyncTCP#v2.0.0

- name: Install ESPAsyncWebServer
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/ESPAsyncWebServer#v3.2.4
run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/mathieucarbou/ESPAsyncWebServer#v3.3.11

- name: Build Demo
run: arduino-cli compile --library . --warnings none -b ${{ matrix.board }} "examples/Demo/Demo.ino"
Expand Down
10 changes: 10 additions & 0 deletions examples/HighPerf/HighPerf.ino
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void loop() {
if (millis() - last > 50) {
#endif
count++;

long r = random(10, 250) + 15;
String buffer;
buffer.reserve(r);
Expand All @@ -67,7 +68,16 @@ void loop() {
for (int i = 0; i < r; i++) {
buffer += dict[random(0, 62)];
}

#ifdef WSL_HIGH_PERF
// Using internal websocket buffer to improve memory consumption and avoid another internal copy when enqueueing the message
AsyncWebSocketMessageBuffer* wsBuffer = WebSerial.makeBuffer(buffer.length());
memmove(wsBuffer->get(), buffer.c_str(), buffer.length());
WebSerial.send(wsBuffer);
#else
WebSerial.print(buffer);
#endif

last = millis();
}
}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{
"owner": "mathieucarbou",
"name": "ESPAsyncWebServer",
"version": "^3.2.4",
"version": "^3.3.11",
"platforms": ["espressif8266", "espressif32"]
}
]
Expand Down
9 changes: 1 addition & 8 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ build_flags =
-D WS_MAX_QUEUED_MESSAGES=128
-D WSL_HIGH_PERF
lib_deps =
mathieucarbou/AsyncTCP@^3.2.5
mathieucarbou/ESPAsyncWebServer@^3.2.4
mathieucarbou/ESPAsyncWebServer@^3.3.11
lib_compat_mode = strict
lib_ldf_mode = chain
upload_protocol = esptool
Expand Down Expand Up @@ -43,9 +42,6 @@ board = esp32-s3-devkitc-1
platform = espressif8266
board = huzzah
; board = d1_mini
lib_deps =
mathieucarbou/ESPAsyncWebServer@^3.2.4
esphome/ESPAsyncTCP-esphome@^2.0.0

; CI

Expand All @@ -64,6 +60,3 @@ board = ${sysenv.PIO_BOARD}
[env:ci-esp8266]
platform = espressif8266
board = ${sysenv.PIO_BOARD}
lib_deps =
mathieucarbou/ESPAsyncWebServer@^3.2.4
esphome/ESPAsyncTCP-esphome@^2.0.0
23 changes: 23 additions & 0 deletions src/WebSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,29 @@ class WebSerialClass : public Print {
// The buffer is not enabled by default.
void setBuffer(size_t initialCapacity);

#ifdef WSL_HIGH_PERF
#ifdef ASYNCWEBSERVER_FORK_mathieucarbou
// Expose the internal WebSocket makeBuffer to even improve memory consumption on client-side
// 1. make a AsyncWebSocketMessageBuffer
// 2. put the data inside
// 3. send the buffer
// This method avoids a buffer copy when creating the WebSocket message
AsyncWebSocketMessageBuffer* makeBuffer(size_t size = 0) {
if (!_ws)
return nullptr;
return _ws->makeBuffer(size);
}

void send(AsyncWebSocketMessageBuffer* buffer) {
if (!_ws || !buffer)
return;
_ws->cleanupClients(WSL_MAX_WS_CLIENTS);
if (_ws->count())
_ws->textAll(buffer);
}
#endif
#endif

private:
// Server
AsyncWebServer *_server;
Expand Down

0 comments on commit 5e418e7

Please sign in to comment.