Giter Club home page Giter Club logo

espasyncwebserver's Introduction

ESP Async WebServer

License: LGPL 3.0 Continuous Integration PlatformIO Registry

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.

This fork is based on yubox-node-org/ESPAsyncWebServer and includes all the concurrency fixes.

Changes in this fork

  • Removed SPIFFSEditor
  • Deployed in PlatformIO registry and Arduino IDE library manager
  • CI
  • Some code cleanup
  • SSE_MAX_QUEUED_MESSAGES to control the maximum number of messages that can be queued for a SSE client
  • write() function public in AsyncEventSource.h
  • Arduino Json 7 compatibility and backward compatible with 6 and 6 (changes in AsyncJson.h). The API to use Json has not changed. These are only internal changes.
  • WS_MAX_QUEUED_MESSAGES: control the maximum number of messages that can be queued for a Websocket client
  • Resurrected AsyncWebSocketMessageBuffer and makeBuffer() in order to make the fork API-compatible with the original library from me-no-dev regarding WebSocket.
  • #5 (@vortigont): set real "Last-Modified" header based on file's LastWrite time
  • #13 (@tueddy): Compile with Arduino 3 (ESP-IDF 5.1)
  • #14 (@nilo85): Add support for Auth & GET requests in AsyncCallbackJsonWebHandler

Documentation

Usage and API stays the same as the original library. Please look at the original libraries for more examples and documentation.

https://github.com/yubox-node-org/ESPAsyncWebServer

AsyncWebSocketMessageBuffer and makeBuffer()

The fork from yubox-node-org introduces some breaking API changes compared to the original library, especially regarding the use of std::shared_ptr<std::vector<uint8_t>> for WebSocket.

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:

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:

void send(JsonDocument& doc) {
  const size_t len = measureJson(doc);

#if defined(ASYNCWEBSERVER_FORK_mathieucarbou)

  // this fork (originally from yubox-node-org), uses another API with shared pointer that better support concurrent use cases then the original project
  auto buffer = std::make_shared<std::vector<uint8_t>>(len);
  assert(buffer); // up to you to keep or remove this
  serializeJson(doc, buffer->data(), len);
  _ws->textAll(std::move(buffer));

#else

  // 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);

#endif
}

espasyncwebserver's People

Contributors

me-no-dev avatar mathieucarbou avatar lorol avatar avillacis avatar me21 avatar hallard avatar hagai-shatz avatar sticilface avatar dmytrokorniienko avatar ivankravets avatar blackhack avatar omersiar avatar matt123p avatar herm avatar bmooij avatar tueddy avatar probonopd avatar buddydvd avatar andig avatar adam5wu avatar trygvis avatar anisimovsergey avatar atanisoft avatar merlinschumacher avatar nut-code-monkey avatar baggior avatar vortigont avatar everslick avatar sharksharp avatar s-limo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.