ESPExpress is a lightweight and flexible web server library for ESP32, enabling developers to create efficient web-based applications with minimal effort. It provides an intuitive API for handling HTTP requests, serving static files, managing WebSockets, and enabling CORS support.
- HTTP Request Handling: Support for
GET,POST,PUT,DELETE, andOPTIONSrequests. - Middleware Support: Easily add global middleware functions.
- Static File Serving: Serve files from SPIFFS or other storage.
- WebSocket Support: Handle real-time communication with WebSockets.
- CORS Support: Enable Cross-Origin Resource Sharing.
- Template Rendering: Serve dynamic HTML with variable replacements.
Include ESPExpress in your project:
#include "ESPExpress.h"This example demonstrates how to create an ESP32 web server that controls an LED:
#include <Arduino.h>
#include <WiFi.h>
#include "ESPExpress.h"
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
const int ledPin = 2;
ESPExpress app(80);
void connectToWiFi() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
void handleTurnOn(Request &req, Response &res) {
digitalWrite(ledPin, HIGH);
res.send("LED turned ON");
}
void handleTurnOff(Request &req, Response &res) {
digitalWrite(ledPin, LOW);
res.send("LED turned OFF");
}
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
connectToWiFi();
app.get("/on", handleTurnOn);
app.get("/off", handleTurnOff);
app.listen();
}
void loop() {}Enable real-time WebSocket communication with:
app.ws("/ws", [](uint8_t num, WStype_t type, uint8_t* payload, size_t length) {
if (type == WStype_TEXT) {
Serial.printf("Client %d sent: %s\n", num, payload);
}
});Enable CORS to allow cross-origin requests:
app.enableCORS("*");Contributions are welcome! Follow these steps:
- Fork the Repository
- Create a new branch:
git checkout -b feature/YourFeature
- Commit your changes:
git commit -am 'Add new feature' - Push to your branch:
git push origin feature/YourFeature
- Open a Pull Request on GitHub.
See our CONTRIBUTING.md for details.
This project is licensed under the MIT License.
For support or questions:
- Open an issue
- Email: a_kadache@estin.dz
Happy coding with ESPExpress! Build efficient web-based applications on your ESP32 effortlessly. 🚀