Convert Figma logo to code with AI

me-no-dev logoESPAsyncWebServer

Async Web Server for ESP8266 and ESP32

3,889
1,231
3,889
288

Top Related Projects

22,569

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at

ESP8266 WiFi Connection manager with web captive portal

16,164

ESP8266 core for Arduino

Arduino core for the ESP32

arduinoWebSockets

📟 JSON library for Arduino and embedded C++. Simple and efficient.

Quick Overview

ESPAsyncWebServer is an asynchronous HTTP and WebSocket server library for ESP8266 and ESP32 microcontrollers. It provides a powerful and efficient way to handle web requests and WebSocket communications on these popular IoT devices, allowing for the creation of responsive web interfaces and real-time applications.

Pros

  • Asynchronous design for improved performance and responsiveness
  • Support for both ESP8266 and ESP32 platforms
  • Built-in WebSocket functionality for real-time communication
  • Extensive API for handling various HTTP methods and request types

Cons

  • Steeper learning curve compared to simpler web server libraries
  • May consume more memory due to its feature-rich nature
  • Limited documentation and examples for advanced use cases
  • Potential compatibility issues with some ESP8266/ESP32 SDK versions

Code Examples

  1. Basic HTTP server setup:
#include "ESPAsyncWebServer.h"

AsyncWebServer server(80);

void setup() {
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(200, "text/plain", "Hello, World!");
  });
  server.begin();
}
  1. Serving HTML content:
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
  request->send(200, "text/html", "<html><body><h1>ESP Async Web Server</h1></body></html>");
});
  1. Handling POST requests:
server.on("/post", HTTP_POST, [](AsyncWebServerRequest *request){
  if (request->hasParam("message", true)) {
    String message = request->getParam("message", true)->value();
    request->send(200, "text/plain", "Received: " + message);
  } else {
    request->send(400, "text/plain", "No message received");
  }
});
  1. WebSocket server setup:
AsyncWebSocket ws("/ws");

server.addHandler(&ws);

ws.onEvent([](AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len){
  if (type == WS_EVT_CONNECT) {
    Serial.println("WebSocket client connected");
  } else if (type == WS_EVT_DISCONNECT) {
    Serial.println("WebSocket client disconnected");
  }
});

Getting Started

  1. Install the ESPAsyncWebServer library in your Arduino IDE or PlatformIO environment.
  2. Include the necessary headers in your sketch:
#include <ESP8266WiFi.h>
#include "ESPAsyncWebServer.h"

AsyncWebServer server(80);

void setup() {
  WiFi.begin("your_ssid", "your_password");
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(200, "text/plain", "Hello from ESPAsyncWebServer!");
  });
  
  server.begin();
}

void loop() {
  // Your main code here
}
  1. Upload the sketch to your ESP8266 or ESP32 board and access the server via its IP address.

Competitor Comparisons

22,569

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at

Pros of Tasmota

  • Comprehensive firmware solution for IoT devices with built-in support for various sensors and protocols
  • Large community and extensive documentation, making it easier to find support and resources
  • Regular updates and active development, ensuring compatibility with new hardware and features

Cons of Tasmota

  • Steeper learning curve for beginners due to its extensive feature set
  • May be overkill for simple projects that only require basic web server functionality
  • Less flexibility for custom web server implementations compared to ESPAsyncWebServer

Code Comparison

ESPAsyncWebServer:

AsyncWebServer server(80);
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(200, "text/plain", "Hello, World!");
});
server.begin();

Tasmota:

void WebServer_on(void)
{
  WebServer->on("/", HTTP_GET, [](){
    WebServer->send(200, "text/plain", "Hello, World!");
  });
}

While both examples set up a simple web server, ESPAsyncWebServer offers more granular control over request handling, while Tasmota provides a more integrated approach within its firmware ecosystem.

ESP8266 WiFi Connection manager with web captive portal

Pros of WiFiManager

  • Simplifies WiFi configuration process with a captive portal
  • Provides automatic connection and fallback to Access Point mode
  • Lightweight and easy to integrate into existing projects

Cons of WiFiManager

  • Limited to WiFi configuration and management
  • Less flexible for complex web server applications
  • May require additional libraries for advanced features

Code Comparison

WiFiManager:

#include <WiFiManager.h>

WiFiManager wifiManager;
wifiManager.autoConnect("AutoConnectAP");

ESPAsyncWebServer:

#include <ESPAsyncWebServer.h>

AsyncWebServer server(80);
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(200, "text/plain", "Hello, world");
});

Summary

WiFiManager excels in simplifying WiFi setup for ESP8266/ESP32 projects, while ESPAsyncWebServer offers a more comprehensive and flexible web server solution. WiFiManager is ideal for projects that primarily need WiFi configuration, whereas ESPAsyncWebServer is better suited for complex web applications requiring advanced routing and request handling.

16,164

ESP8266 core for Arduino

Pros of Arduino

  • Extensive library support and community resources
  • Easier for beginners with a more straightforward API
  • Broader compatibility with various ESP8266 boards and modules

Cons of Arduino

  • Synchronous operations can lead to blocking code
  • Less efficient for handling multiple concurrent connections
  • May consume more memory due to its comprehensive feature set

Code Comparison

Arduino:

#include <ESP8266WebServer.h>

ESP8266WebServer server(80);

void setup() {
  server.on("/", handleRoot);
  server.begin();
}

ESPAsyncWebServer:

#include <ESPAsyncWebServer.h>

AsyncWebServer server(80);

void setup() {
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(200, "text/plain", "Hello, async world!");
  });
  server.begin();
}

The ESPAsyncWebServer code demonstrates non-blocking, asynchronous handling of requests, while the Arduino example uses a more traditional, synchronous approach. ESPAsyncWebServer offers better performance for concurrent connections but may have a steeper learning curve for beginners.

Arduino core for the ESP32

Pros of arduino-esp32

  • Official repository maintained by Espressif, ensuring compatibility and regular updates
  • Comprehensive support for ESP32 features, including Wi-Fi, Bluetooth, and various peripherals
  • Extensive documentation and examples for easier development

Cons of arduino-esp32

  • Lacks built-in asynchronous web server functionality
  • May require additional libraries for advanced web server features
  • Potentially higher resource usage for web server applications

Code Comparison

ESPAsyncWebServer:

AsyncWebServer server(80);

server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(200, "text/plain", "Hello, world");
});

server.begin();

arduino-esp32 (using WiFiServer):

WiFiServer server(80);

if (client) {
    client.println("HTTP/1.1 200 OK");
    client.println("Content-type:text/plain");
    client.println("Connection: close");
    client.println();
    client.println("Hello, world");
    client.stop();
}

The ESPAsyncWebServer code is more concise and handles requests asynchronously, while the arduino-esp32 example requires manual HTTP response handling and blocks during client communication.

arduinoWebSockets

Pros of arduinoWebSockets

  • Supports multiple WebSocket connections simultaneously
  • Provides SSL/TLS encryption for secure communication
  • Compatible with a wider range of Arduino boards and ESP8266/ESP32

Cons of arduinoWebSockets

  • Lacks built-in HTTP server functionality
  • May require more manual handling of WebSocket events
  • Potentially higher memory usage due to multiple connection support

Code Comparison

ESPAsyncWebServer:

AsyncWebServer server(80);
AsyncWebSocket ws("/ws");

server.addHandler(&ws);
server.begin();

arduinoWebSockets:

WebSocketsServer webSocket = WebSocketsServer(81);

webSocket.begin();
webSocket.onEvent(webSocketEvent);

ESPAsyncWebServer provides an integrated HTTP server with WebSocket support, while arduinoWebSockets focuses solely on WebSocket functionality. ESPAsyncWebServer offers a more streamlined setup for combined HTTP and WebSocket services, whereas arduinoWebSockets requires separate HTTP server implementation if needed.

ESPAsyncWebServer is designed specifically for ESP8266 and ESP32, offering optimized performance for these platforms. In contrast, arduinoWebSockets supports a broader range of Arduino-compatible boards, making it more versatile for different hardware setups.

Both libraries have active communities and regular updates, ensuring ongoing support and improvements for developers working on IoT and web-connected projects.

📟 JSON library for Arduino and embedded C++. Simple and efficient.

Pros of ArduinoJson

  • Specialized for JSON parsing and generation, offering efficient memory usage
  • Extensive documentation and examples for various use cases
  • Cross-platform compatibility, supporting Arduino and other embedded systems

Cons of ArduinoJson

  • Limited to JSON data format, while ESPAsyncWebServer handles various HTTP requests
  • Requires manual integration with web server functionality
  • May need additional libraries for network communication

Code Comparison

ArduinoJson:

StaticJsonDocument<200> doc;
doc["sensor"] = "temperature";
doc["value"] = 25.5;
String output;
serializeJson(doc, output);

ESPAsyncWebServer:

server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
    String json = "{\"sensor\":\"temperature\",\"value\":25.5}";
    request->send(200, "application/json", json);
});

Summary

ArduinoJson excels in JSON manipulation but lacks built-in web server capabilities. ESPAsyncWebServer provides a complete web server solution but may require additional JSON handling. Choose based on your project's primary focus: JSON processing or web server functionality.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

https://avatars.githubusercontent.com/u/195753706?s=96&v=4

Project moved to ESP32Async organization at https://github.com/ESP32Async/ESPAsyncWebServer

Discord Server: https://discord.gg/X7zpGdyUcY

Please see the new links:

  • ESP32Async/ESPAsyncWebServer @ 3.6.0 (ESP32, ESP8266, RP2040)
  • ESP32Async/AsyncTCP @ 3.3.2 (ESP32)
  • ESP32Async/ESPAsyncTCP @ 2.0.0 (ESP8266)
  • https://github.com/ESP32Async/AsyncTCPSock/archive/refs/tags/v1.0.3-dev.zip (AsyncTCP alternative for ESP32)
  • khoih-prog/AsyncTCP_RP2040W @ 1.2.0 (RP2040)