This repository contains an HTTPS server library that can be used with the ESP32 Arduino Core. It supports HTTP as well.
- Providing support for HTTP, HTTPS or both at the same time
- Handling requests in callback functions that can be bound to URLs, like for example in Express or Servlets.
- Abstraction of handling the HTTP stuff and providing a simple API for it, eg. to access parameters, headers, HTTP Basic Auth etc.
- Using middleware functions as proxy to every request to perform central tasks like authentication or logging.
- Make use of the built-in encryption of the ESP32 module for HTTPS.
- Handle multiple clients in parallel (max. 3-4 TLS clients due to memory limits).
- Usage of
Connection: keep-alive
and SSL session reuse to reduce the overhead of SSL handshakes and speed up data transfer.
The library is self-contained and just needs the Arduino and ESP32 system libraries. Running the examples requires the WiFi library in addition to that.
The steps to install this library depend on the IDE you are using. PlatformIO is recommended as you have more options to configure the library (see Advanced Configuration), but the library can be used with the plain Arduino IDE.
The library is listed in PlatformIO's library registry. If you're using the IDE, search for esp32_https_server
and install it, on the command line, just run:
pio lib install "esp32_https_server"
New release can take one or two days before they get picked up by the library crawler which makes them available in the registry. The version numbers of releases are based on semantic versioning.
Add the library to your platform.ini
like in the following example:
[platformio]
env_default = wrover
[env:wrover]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = esp32_https_server
If you want a specific version, you can use a notation like lib_deps = esp32_https_server@0.3.0
. More information on this can be found in the PlatformIO documentation.
To use the current master of the library, don't add it to your platform.ini
but go to your project's libs
folder and run the following command to get a copy of repository:
git clone https://github.com/fhessel/esp32_https_server.git
Note: While the
master
branch should contain a running version of the library at any time, the API might already have changes towards the next major release. So for a stable setup, it is recommended to use a published release.
Download the latest release and extract it into your Arduino/libraries folder. Then restart your IDE.
You then should be able to add the library to your project if you selected the ESP32 as architecture.
Note: To run the examples (except for the Self-Signed-Certificates example), you need to execute the script extras/create_cert.sh first (see Issue #26 for Windows). This script will create a simple CA to sign certificates that are used with the examples. Some notes on the usage can be found in the extras/README.md file.
You will find several examples showing how you can use the library:
- Static-Page: Short example showing how to serve some static resources with the server. You should start with this sketch and get familiar with it before having a look at the more complex examples.
- Parameters: Shows how you can access request parameters (the part after the question mark in the URL) or parameters in dynamic URLs (like /led/1, /led/2, ...)
- Put-Post-Echo: Implements a simple echo service for PUT and POST requests that returns the request body as response body. Also shows how to differentiate between multiple HTTP methods for the same URL.
- HTTPS-and-HTTP: Shows how to serve resources via HTTP and HTTPS in parallel and how to check if the user is using a secure connection during request handling
- Middleware: Shows how to use the middleware API for logging. Middleware functions are defined very similar to webservers like Express.
- Authentication: Implements a chain of two middleware functions to handle authentication and authorization using HTTP Basic Auth.
- Async-Server: Like the Static-Page example, but the server runs in a separate task on the ESP32, so you do not need to call the loop() function in your main sketch.
- Websocket-Chat: Provides a browser-based chat built on top of websockets. Note: Websockets are still under development!
- Parameter-Validation: Shows how you can integrate validator functions to do formal checks on parameters in your URL.
- Self-Signed-Certificate: Shows how to generate a self-signed certificate on the fly on the ESP when the sketch starts. You do not need to run
create_cert.sh
to use this example. - REST-API: Uses ArduinoJSON and SPIFFS file upload to serve a small web interface that provides a REST API.
If you encounter error messages that cert.h or private_key.h are missing when running an example, make sure to run create_cert.sh first (see Setup Instructions).
You might also want to check out the (work-in-progress) Documentation.
< 8000 div class="markdown-heading" dir="auto">