From ab6ddd0f322f1a40fd406d63bf6bbbfb21d87fd5 Mon Sep 17 00:00:00 2001 From: Pablo2048 Date: Sun, 4 Feb 2024 14:20:02 +0100 Subject: [PATCH] Revert k verze 2.5.1 s upravou pro ESP32. Zda se, ze verze 2.6.1 bere o cca 1kB RAM vic a zpomaluje OTA (i kdyz zatim netusim proc). --- docs/index.md | 27 +++++---------------------- library.json_ => library.json | 2 +- library.properties | 2 +- src/AsyncWebSocket.cpp | 2 +- src/ESPAsyncWebServer.h | 4 ++-- src/WebHandlers.cpp | 6 ++---- 6 files changed, 12 insertions(+), 31 deletions(-) rename library.json_ => library.json (97%) diff --git a/docs/index.md b/docs/index.md index 8b213e8..9cf1e0e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,7 +15,6 @@ This fork is based on https://github.com/yubox-node-org/ESPAsyncWebServer and in - Deployed in PlatformIO registry and Arduino IDE library manager - CI - Only supports ESP32 -- Resurrected `AsyncWebSocketMessageBuffer` and `makeBuffer()` in order to make the fork API-compatible with the original library from me-no-dev regarding WebSocket. ## Documentation @@ -24,29 +23,13 @@ Please look at the original libraries for more examples and documentation. [https://github.com/yubox-node-org/ESPAsyncWebServer](https://github.com/yubox-node-org/ESPAsyncWebServer) -## `AsyncWebSocketMessageBuffer` and `makeBuffer()` +## Pitfalls -The fork from `yubox-node-org` introduces some breaking API changes compared to the original library, especially regarding the use of `std::shared_ptr>` for WebSocket. +The fork from yubox introduces some breaking API changes compared to the original library, especially regarding the use of `std::shared_ptr>` for WebSocket. +Thanks to this fork, you can handle them by using `ASYNCWEBSERVER_FORK_mathieucarbou`. -This fork is compatible with the original library from `me-no-dev` regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class. -So you have the choice of which API to use. -I strongly suggest to use the optimized API from `yubox-node-org` as it is much more efficient. - -Here is an example for serializing a Json document in a websocket message buffer. This code is compatible with any forks, but not optimized: - -```cpp -void send(JsonDocument& doc) { - const size_t len = measureJson(doc); - - // original API from me-no-dev - AsyncWebSocketMessageBuffer* buffer = _ws->makeBuffer(len); - assert(buffer); // up to you to keep or remove this - serializeJson(doc, buffer->get(), len); - _ws->textAll(buffer); -} -``` - -Here is an example for serializing a Json document in a more optimized way, and compatible with both forks: +Here is an example for serializing a Json document in a websocket message buffer directly. +This code is compatible with both forks. ```cpp void send(JsonDocument& doc) { diff --git a/library.json_ b/library.json similarity index 97% rename from library.json_ rename to library.json index 94271bd..1730ad5 100644 --- a/library.json_ +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ESP Async WebServer", - "version": "2.6.1", + "version": "2.5.1", "description": "Asynchronous HTTP and WebSocket Server Library for ESP32. Supports: WebSocket, SSE, Authentication, Arduino Json 7, File Upload, Static File serving, URL Rewrite, URL Redirect, etc.", "keywords": "http,async,websocket,webserver", "homepage": "https://github.com/mathieucarbou/ESPAsyncWebServer", diff --git a/library.properties b/library.properties index fda5f3f..2e5699f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESP Async WebServer -version=2.6.1 +version=2.5.1 author=Me-No-Dev maintainer=Mathieu Carbou sentence=Asynchronous HTTP and WebSocket Server Library for ESP32 diff --git a/src/AsyncWebSocket.cpp b/src/AsyncWebSocket.cpp index 90f14cd..75189cf 100644 --- a/src/AsyncWebSocket.cpp +++ b/src/AsyncWebSocket.cpp @@ -798,7 +798,7 @@ void AsyncWebSocketClient::binary(const __FlashStringHelper *data, size_t len) IPAddress AsyncWebSocketClient::remoteIP() const { if (!_client) - return IPAddress((uint32_t)0U); + return {}; // IPAddress(0U); return _client->remoteIP(); } diff --git a/src/ESPAsyncWebServer.h b/src/ESPAsyncWebServer.h index 8955c39..2c88bda 100644 --- a/src/ESPAsyncWebServer.h +++ b/src/ESPAsyncWebServer.h @@ -40,9 +40,9 @@ #error Platform not supported #endif -#define ASYNCWEBSERVER_VERSION "2.6.1" +#define ASYNCWEBSERVER_VERSION "2.5.1" #define ASYNCWEBSERVER_VERSION_MAJOR 2 -#define ASYNCWEBSERVER_VERSION_MINOR 6 +#define ASYNCWEBSERVER_VERSION_MINOR 5 #define ASYNCWEBSERVER_VERSION_REVISION 1 #define ASYNCWEBSERVER_FORK_mathieucarbou diff --git a/src/WebHandlers.cpp b/src/WebHandlers.cpp index 0b55b0d..c79cdbb 100644 --- a/src/WebHandlers.cpp +++ b/src/WebHandlers.cpp @@ -58,7 +58,7 @@ AsyncStaticWebHandler& AsyncStaticWebHandler::setCacheControl(const char* cache_ } AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(const char* last_modified){ - _last_modified = last_modified; + _last_modified = String(last_modified); return *this; } @@ -205,9 +205,7 @@ void AsyncStaticWebHandler::handleRequest(AsyncWebServerRequest *request) return request->requestAuthentication(); if (request->_tempFile == true) { - time_t lw = request->_tempFile.getLastWrite(); // get last file mod time (if supported by FS) - if (lw) setLastModified(gmtime(&lw)); - String etag(lw ? lw : request->_tempFile.size()); // set etag to lastmod timestamp if available, otherwise to size + String etag = String(request->_tempFile.size()); if (_last_modified.length() && _last_modified == request->header(F("If-Modified-Since"))) { request->_tempFile.close(); request->send(304); // Not modified