Skip to content

Commit fb12021

Browse files
committed
Update readme, add links to docs
1 parent a134858 commit fb12021

File tree

1 file changed

+78
-31
lines changed

1 file changed

+78
-31
lines changed

README.md

Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,65 @@ This repository contains an HTTPS server library that can be used with the [ESP3
44

55
## Features
66

7-
- Make use of the built-in encryption of the ESP32 module
8-
- Handle multiple clients in parallel (max 3-4 SSL clients due to memory limits)
9-
- Usage of `Connection: keep-alive` and SSL Session reuse to reduce the overhead of SSL handshakes and speed up data transfer
10-
- Abstraction of handling the HTTP stuff and providing a simple API for it, eg. to access parameters, headers, HTTP Basic Auth etc.
11-
- Handling requests in callback functions that can be bound to URLs
12-
- Using middleware functions as proxy to every request to perform central tasks like authentication or logging
137
- Providing support for HTTP, HTTPS or both at the same time
8+
- Handling requests in callback functions that can be bound to URLs, like for example in Express or Servlets.
9+
- Abstraction of handling the HTTP stuff and providing a simple API for it, eg. to access parameters, headers, HTTP Basic Auth etc.
10+
- Using middleware functions as proxy to every request to perform central tasks like authentication or logging.
11+
- Make use of the built-in encryption of the ESP32 module for HTTPS.
12+
- Handle multiple clients in parallel (max. 3-4 TLS clients due to memory limits).
13+
- Usage of `Connection: keep-alive` and SSL session reuse to reduce the overhead of SSL handshakes and speed up data transfer.
1414

1515
## Dependencies
1616

1717
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.
1818

1919
## Setup Instructions
2020

21-
Clone or download the content of this git repository into your Arduino/libraries folder and restart your IDE.
21+
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](#advanced-configuration)), but the library can be used with the plain Arduino IDE.
22+
23+
### PlatformIO (Recommended)
24+
25+
The library is listed in PlatformIO's [library registry](https://platformio.org/lib/show/5887/esp32_https_server/). If you're using the IDE, search for `esp32_https_server` and install it, on the command line, just run:
26+
27+
```bash
28+
pio lib install "esp32_https_server"
29+
```
30+
31+
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](https://github.com/fhessel/esp32_https_server/releases) are based on [semantic versioning](https://semver.org/).
2232

23-
To run the examples (except for the _Self-Signed-Certificates_ example), you need to execute the script extras/create_cert.sh first. 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.
33+
Add the library to your `platform.ini` like in the following example:
34+
35+
```ini
36+
[platformio]
37+
env_default = wrover
38+
39+
[env:wrover]
40+
platform = espressif32
41+
board = esp32dev
42+
framework = arduino
43+
lib_deps = esp32_https_server
44+
```
45+
46+
If you want a specific version, you can use a notation like `lib_deps = [email protected]`. More information on this can be found in the [PlatformIO documentation](https://docs.platformio.org/en/latest/projectconf/section_env_library.html).
47+
48+
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:
49+
50+
```bash
51+
git clone https://github.com/fhessel/esp32_https_server.git
52+
```
53+
54+
> **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.
55+
56+
### Arduino
57+
58+
Download [the latest release](https://github.com/fhessel/esp32_https_server/releases) and extract it into your Arduino/libraries folder. Then restart your IDE.
2459

2560
You then should be able to add the library to your project if you selected the ESP32 as architecture.
2661

2762
## Examples
2863

64+
> **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](https://github.com/fhessel/esp32_https_server/issues/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.
65+
2966
You will find several examples showing how you can use the library:
3067

3168
- [Static-Page](examples/Static-Page/Static-Page.ino): 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.
@@ -67,7 +104,15 @@ using namespace httpsserver
67104
```
68105
### Create Server Instance
69106
70-
Then, you can create the server like this:
107+
You can create your server instance like shown below:
108+
109+
**For HTTP:**
110+
111+
```C++
112+
HTTPServer myServer = HTTPServer();
113+
```
114+
115+
**For HTTPS:**
71116

72117
```C++
73118
// Create certificate data (see extras/README.md on how to create it)
@@ -83,13 +128,13 @@ SSLCert cert = SSLCert(
83128
HTTPSServer myServer = HTTPSServer(cert);
84129
```
85130

86-
By default, the server will listen on port 443. If you want to change that (or some other options), you can have a look at the optional parameters of the HTTPSServer constructor.
131+
By default, the server will listen on port 443. If you want to change that (or some other options), you can have a look at the optional parameters of the [`HTTPServer`](https://fhessel.github.io/esp32_https_server/classhttpsserver_1_1HTTPServer.html) or [`HTTPSServer`](https://fhessel.github.io/esp32_https_server/classhttpsserver_1_1HTTPSServer.html) constructors.
87132

88-
If you want to have just an HTTP server, you can skip the SSLCert part and replace HTTPSServer by HTTPServer. Everything else is the same for both protocols.
133+
The only difference between the HTTP and HTTPS version is the certificate which you have to configure. Keep in mind that each opened connection of the TLS-enabled `HTTPSServer` requires additional 40 to 50 kB of heap memory for the TLS connection itself. This has to be considered when increasing `maxConnections`.
89134

90135
### Add Resources to the Server
91136

92-
Every URL that should be accessible on the server has to be configured as a so-called `ResourceNode`. Such a node links a handler function to a specific URL and HTTP method. The handler function could look like this:
137+
Every _route_ (or path) that should be accessible on the server has to be configured as a so-called `ResourceNode`. Such a node links a handler function to a specific route (like `/test`) and HTTP method (like `GET`). The handler function could look like this:
93138

94139
```C++
95140
void handleRoot(HTTPRequest * req, HTTPResponse * res) {
@@ -108,51 +153,51 @@ void handleRoot(HTTPRequest * req, HTTPResponse * res) {
108153
}
109154
```
110155
111-
As you can see, the function gets references to the HTTP request and response. You can use the request to read headers, parameters, authentication information etc. The response can be used to send data to the client, set headers or HTTP status codes.
156+
As you can see, the function gets references to the [`HTTPRequest`](https://fhessel.github.io/esp32_https_server/classhttpsserver_1_1HTTPRequest.html) and [`HTTPResponse`](https://fhessel.github.io/esp32_https_server/classhttpsserver_1_1HTTPResponse.html). You can use the request to read headers, parameters, authentication information etc. The response can be used to send data to the client, set headers or HTTP status codes.
112157
113-
Now we need to tell the server which URL should be served by this function. This can be done by creating a `ResourceNode` (usually in your `setup()` function).
158+
Now we need to tell the server which URL should be served by this function. This can be done by creating a [`ResourceNode`](https://fhessel.github.io/esp32_https_server/classhttpsserver_1_1ResourceNode.html) (usually in your `setup()` function).
114159
115160
```C++
116161
ResourceNode * nodeRoot = new ResourceNode("/", "GET", &handleRoot);
117162
```
118163

119-
The first parameter defines the URL. It should always start with a slash, and using just a slash like here means that the function will be called for requests to the server's root (like https:/10.0.x.x/).
164+
The first parameter defines the route. It should always start with a slash, and using just a slash like in this example means that the function will be called for requests to the server's root (like https://10.0.x.x/).
120165

121-
The second parameter is the HTTP method, "GET" in this case.
166+
The second parameter is the HTTP method, `"GET"` in this case.
122167

123-
Finally, you pass a reference to the request handler function to link it to the URL and method.
168+
Finally, you pass a reference to the request handler function to link it to the route and method.
124169

125-
Now you just need to register the created `ResourceNode` at your server:
170+
Now you just need to register the created [`ResourceNode`](https://fhessel.github.io/esp32_https_server/classhttpsserver_1_1ResourceNode.html) at your server:
126171

127172
```C++
128173
myServer.registerNode(nodeRoot);
129174
```
130175

131176
That's everything you need to do for a single web page on your server.
132177

133-
Note that you can define a single `ResourceNode` via `HTTPServer::setDefaultNode()`, which will be called if no other node on the server matches. Method and Path are ignored in this case. All examples use this to define a 404-handler, which might be a good idea for most scenarios.
178+
Note that you can define a single [`ResourceNode`](https://fhessel.github.io/esp32_https_server/classhttpsserver_1_1ResourceNode.html) via `HTTPServer::setDefaultNode()`, which will be called if no other node on the server matches. Method and route are ignored in this case. Most examples use this to define a 404-handler, which might be a good idea for most scenarios. In case no default node is specified, the server will return with a small error page if no matching route is found.
134179

135180
### Start the Server
136181

137-
A call to `HTTPServer::start()` will start the server so that it is listening on the port specified:
182+
A call to [`HTTPServer::start()`](https://fhessel.github.io/esp32_https_server/classhttpsserver_1_1HTTPServer.html#a1b1b6bce0b52348ca5b5664cf497e039) will start the server so that it is listening on the previously specified port:
138183

139184
```C++
140185
myServer.start();
141186
```
142187

143188
This code usually goes into your `setup()` function. You can use `HTTPServer::isRunning()` to check whether the server started successfully.
144189

145-
By default, you need to pass control to the server explicitly. This is done by calling the `HTTPServer::loop()` function, which you usually will put into your Arduino sketch's `loop()` function. Once called, the server will first check for incoming connection (up to the maximum connection count that has been defined in the constructor), and then handle every open connection if it has new data on the socket. So your request handler functions will be called during the call to `loop()`. Note that if one of your handler functions is blocking, it will block all other connections as well.
190+
By default, you need to pass control to the server explicitly. This is done by calling the [`HTTPServer::loop()`](https://fhessel.github.io/esp32_https_server/classhttpsserver_1_1HTTPServer.html#af8f68f5ff6ad101827bcc52217249fe2) function, which you usually will put into your Arduino sketch's `loop()` function. Once called, the server will first check for incoming connection (up to the maximum connection count that has been defined in the constructor), and then handle every open connection if it has new data on the socket. So your request handler functions will be called during the call to `loop()`. Note that if one of your handler functions is blocking, it will block all other connections as well.
146191

147192
### Running the Server asynchronously
148193

149194
If you want to have the server running in the background (and not calling `loop()` by yourself every few milliseconds), you can make use of the ESP32's task feature and put the whole server in a separate task.
150195

151-
See the Async-Server example to see how this can be done.
196+
See the [Async-Server example](https://github.com/fhessel/esp32_https_server/tree/master/examples/Async-Server) to see how this can be done.
152197

153198
## Advanced Configuration
154199

155-
This section covers some advanced configuration options that allow you e.g. to customize the build process, but which might require more advanced programming skills and a more sophisticated IDE that just the default Arduino IDE.
200+
This section covers some advanced configuration options that allow you, for example, to customize the build process, but which might require more advanced programming skills and a more sophisticated IDE that just the default Arduino IDE.
156201

157202
### Saving Space by Reducing Functionality
158203

@@ -166,15 +211,16 @@ The following flags are currently available:
166211

167212
Setting these flags requires a build environment that gives you some control of the compiler, as libraries are usually compiled separately, so just doing a `#define HTTPS_SOMETHING` in your sketch will not work.
168213

169-
**Example: Configuration with Platform IO**
214+
**Example: Configuration with PlatformIO**
170215

171-
To set these flags in Platform IO, you can modify your `platformio.ini`. To disable for example the self-signed-certificates part of the library, the file could look like this:
216+
To set these flags in PlatformIO, you can modify your `platformio.ini`. To disable for example the self-signed-certificates part of the library, the file could look like this:
172217

173218
```ini
174-
[env:esp32dev]
219+
[env:wroom]
175220
platform = espressif32
176221
board = esp32dev
177222
framework = arduino
223+
lib_deps = esp32_https_server
178224
build_flags =
179225
-DHTTPS_DISABLE_SELFSIGNING
180226
```
@@ -183,15 +229,15 @@ Note the `-D` in front of the actual flag name, that passes this flag as a defin
183229

184230
### Configure Logging
185231

186-
The server provides some internal logging, which is used on level `INFO` by default. This will look like this on your serial console:
232+
The server provides some internal logging, which is activated on level `INFO` by default. This will look like this on your serial console:
187233

188234
```
189235
[HTTPS:I] New connection. SocketFID=55
190236
[HTTPS:I] Request: GET / (FID=55)
191237
[HTTPS:I] Connection closed. Socket FID=55
192238
```
193239

194-
Logging output can also be controlled by using compiler flags. This requires an advanced development environment like explained in *Saving Space by Reducing Functionality*.
240+
Logging output can also be controlled by using compiler flags. This requires an advanced development environment like explained in [Saving Space by Reducing Functionality](#saving-space-by-reducing-functionality).
195241

196242
There are two parameters that can be configured:
197243

@@ -206,15 +252,16 @@ There are two parameters that can be configured:
206252
| 3 |||| |
207253
| 4 |||||
208254

209-
**Example: Configuration with Platform IO**
255+
**Example: Configuration with PlatformIO**
210256

211-
To set these flags in Platform IO, you can modify your `platformio.ini`. The following entries set the minimum log level to warning and enable timestamps
257+
To set these flags in PlatformIO, you can modify your `platformio.ini`. The following entries set the minimum log level to warning and enable timestamps
212258

213259
```ini
214-
[env:esp32dev]
260+
[env:wroom]
215261
platform = espressif32
216262
board = esp32dev
217263
framework = arduino
264+
lib_deps = esp32_https_server
218265
build_flags =
219266
-DHTTPS_LOGLEVEL=2
220267
-DHTTPS_LOGTIMESTAMP

0 commit comments

Comments
 (0)