Skip to content

Commit 669f611

Browse files
committed
Merge branch 'master-tmmsunny012' into for-iotsa
2 parents 9a3726d + f1b0844 commit 669f611

File tree

128 files changed

+7870
-1567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+7870
-1567
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ Breaking changes:
1414

1515
1616

17+
## [v1.1.0](https://github.com/fhessel/esp32_https_server/releases/tag/v1.0.0)
18+
19+
New functionality:
20+
21+
* Add examples to support WT32_ETH01 using LAN8720
22+
23+
Bug fixes:
24+
25+
* Fix compile error for using `hwcrypto/sha.h`
26+
27+
=========================================================
28+
1729
## [v1.0.0](https://github.com/fhessel/esp32_https_server/releases/tag/v1.0.0)
1830

1931
New functionality:

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# ESP32 HTTPS Server
22

3-
![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/fhessel/esp32_https_server?label=Version&sort=semver) ![Build Examples](https://github.com/fhessel/esp32_https_server/workflows/Build%20Examples/badge.svg?branch=master)
4-
53
This repository contains an HTTPS server library that can be used with the [ESP32 Arduino Core](https://github.com/espressif/arduino-esp32). It supports HTTP as well.
64

75
## Features
@@ -73,19 +71,18 @@ git clone https://github.com/fhessel/esp32_https_server.git
7371

7472
> **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.
7573
76-
You will find several examples showing how you can use the library (roughly ordered by complexity):
74+
You will find several examples showing how you can use the library:
7775

7876
- [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.
7977
- [Parameters](examples/Parameters/Parameters.ino): 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, ...)
80-
- [Parameter-Validation](examples/Parameter-Validation/Parameter-Validation.ino): Shows how you can integrate validator functions to do formal checks on parameters in your URL.
8178
- [Put-Post-Echo](examples/Put-Post-Echo/Put-Post-Echo.ino): 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.
8279
- [HTTPS-and-HTTP](examples/HTTPS-and-HTTP/HTTPS-and-HTTP.ino): 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
83-
- [HTML-Forms](examples/HTML-Forms/HTML-Forms.ino): Shows how to use body parsers to handle requests created from HTML forms (access text field contents, handle file upload, etc.).
84-
- [Async-Server](examples/Async-Server/Async-Server.ino): 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.
85-
- [Self-Signed-Certificate](examples/Self-Signed-Certificate/Self-Signed-Certificate.ino): 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.
8680
- [Middleware](examples/Middleware/Middleware.ino): Shows how to use the middleware API for logging. Middleware functions are defined very similar to webservers like Express.
8781
- [Authentication](examples/Authentication/Authentication.ino): Implements a chain of two middleware functions to handle authentication and authorization using HTTP Basic Auth.
82+
- [Async-Server](examples/Async-Server/Async-Server.ino): 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.
8883
- [Websocket-Chat](examples/Websocket-Chat/Websocket-Chat.ino): Provides a browser-based chat built on top of websockets. **Note:** Websockets are still under development!
84+
- [Parameter-Validation](examples/Parameter-Validation/Parameter-Validation.ino): Shows how you can integrate validator functions to do formal checks on parameters in your URL.
85+
- [Self-Signed-Certificate](examples/Self-Signed-Certificate/Self-Signed-Certificate.ino): 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.
8986
- [REST-API](examples/REST-API/REST-API.ino): Uses [ArduinoJSON](https://arduinojson.org/) and [SPIFFS file upload](https://github.com/me-no-dev/arduino-esp32fs-plugin) to serve a small web interface that provides a REST API.
9087

9188
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).

Sjenica1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 77 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
/**
2-
* Example for the ESP32 HTTP(S) Webserver
3-
*
4-
* IMPORTANT NOTE:
5-
* To run this script, your need to
6-
* 1) Enter your WiFi SSID and PSK below this comment
7-
* 2) Make sure to have certificate data available. You will find a
8-
* shell script and instructions to do so in the library folder
9-
* under extras/
10-
*
11-
* This script will install an HTTPS Server on your ESP32 with the following
12-
* functionalities:
13-
* - Show simple page on web server root
14-
* - 404 for everything else
15-
* The server will be run in a separate task, so that you can do your own stuff
16-
* in the loop() function.
17-
* Everything else is just like the Static-Page example
18-
*/
2+
Example for the ESP32 HTTP(S) Webserver
3+
4+
IMPORTANT NOTE:
5+
To run this script, your need to
6+
1) Enter your WiFi SSID and PSK below this comment
7+
2) Make sure to have certificate data available. You will find a
8+
shell script and instructions to do so in the library folder
9+
under extras/
10+
11+
This script will install an HTTPS Server on your ESP32 with the following
12+
functionalities:
13+
- Show simple page on web server root
14+
- 404 for everything else
15+
The server will be run in a separate task, so that you can do your own stuff
16+
in the loop() function.
17+
Everything else is just like the Static-Page example
18+
*/
1919

2020
// TODO: Configure your WiFi here
21-
#define WIFI_SSID "<your ssid goes here>"
22-
#define WIFI_PSK "<your pre-shared key goes here>"
21+
#define WIFI_SSID "your_ssid"
22+
#define WIFI_PSK "12345678"
2323

2424
/** Check if we have multiple cores */
2525
#if CONFIG_FREERTOS_UNICORE
26-
#define ARDUINO_RUNNING_CORE 0
26+
#define ARDUINO_RUNNING_CORE 0
2727
#else
28-
#define ARDUINO_RUNNING_CORE 1
28+
#define ARDUINO_RUNNING_CORE 1
2929
#endif
3030

3131
// Include certificate data (see note above)
@@ -46,53 +46,15 @@ using namespace httpsserver;
4646

4747
// Create an SSL certificate object from the files included above
4848
SSLCert cert = SSLCert(
49-
example_crt_DER, example_crt_DER_len,
50-
example_key_DER, example_key_DER_len
51-
);
49+
example_crt_DER, example_crt_DER_len,
50+
example_key_DER, example_key_DER_len
51+
);
5252

5353
// Create an SSL-enabled server that uses the certificate
5454
HTTPSServer secureServer = HTTPSServer(&cert);
5555

56-
// Declare some handler functions for the various URLs on the server
57-
void handleRoot(HTTPRequest * req, HTTPResponse * res);
58-
void handle404(HTTPRequest * req, HTTPResponse * res);
59-
60-
// We declare a function that will be the entry-point for the task that is going to be
61-
// created.
62-
void serverTask(void *params);
63-
64-
void setup() {
65-
// For logging
66-
Serial.begin(115200);
67-
68-
// Connect to WiFi
69-
Serial.println("Setting up WiFi");
70-
WiFi.begin(WIFI_SSID, WIFI_PSK);
71-
while (WiFi.status() != WL_CONNECTED) {
72-
Serial.print(".");
73-
delay(500);
74-
}
75-
Serial.print("Connected. IP=");
76-
Serial.println(WiFi.localIP());
77-
78-
// Setup the server as a separate task.
79-
Serial.println("Creating server task... ");
80-
// We pass:
81-
// serverTask - the function that should be run as separate task
82-
// "https443" - a name for the task (mainly used for logging)
83-
// 6144 - stack size in byte. If you want up to four clients, you should
84-
// not go below 6kB. If your stack is too small, you will encounter
85-
// Panic and stack canary exceptions, usually during the call to
86-
// SSL_accept.
87-
xTaskCreatePinnedToCore(serverTask, "https443", 6144, NULL, 1, NULL, ARDUINO_RUNNING_CORE);
88-
}
89-
90-
void loop() {
91-
Serial.println("loop()");
92-
delay(5000);
93-
}
94-
95-
void serverTask(void *params) {
56+
void serverTask(void *params)
57+
{
9658
// In the separate task we first do everything that we would have done in the
9759
// setup() function, if we would run the server synchronously.
9860

@@ -112,11 +74,14 @@ void serverTask(void *params) {
11274

11375
Serial.println("Starting server...");
11476
secureServer.start();
115-
if (secureServer.isRunning()) {
77+
78+
if (secureServer.isRunning())
79+
{
11680
Serial.println("Server ready.");
11781

11882
// "loop()" function of the separate task
119-
while(true) {
83+
while (true)
84+
{
12085
// This call will let the server do its work
12186
secureServer.loop();
12287

@@ -126,7 +91,8 @@ void serverTask(void *params) {
12691
}
12792
}
12893

129-
void handleRoot(HTTPRequest * req, HTTPResponse * res) {
94+
void handleRoot(HTTPRequest * req, HTTPResponse * res)
95+
{
13096
// Status code is 200 OK by default.
13197
// We want to deliver a simple HTML page, so we send a corresponding content type:
13298
res->setHeader("Content-Type", "text/html");
@@ -140,13 +106,14 @@ void handleRoot(HTTPRequest * req, HTTPResponse * res) {
140106
res->println("<h1>Hello World!</h1>");
141107
res->print("<p>Your server is running for ");
142108
// A bit of dynamic data: Show the uptime
143-
res->print((int)(millis()/1000), DEC);
109+
res->print((int)(millis() / 1000), DEC);
144110
res->println(" seconds.</p>");
145111
res->println("</body>");
146112
res->println("</html>");
147113
}
148114

149-
void handle404(HTTPRequest * req, HTTPResponse * res) {
115+
void handle404(HTTPRequest * req, HTTPResponse * res)
116+
{
150117
// Discard request body, if we received any
151118
// We do this, as this is the default node and may also server POST/PUT requests
152119
req->discardRequestBody();
@@ -165,3 +132,44 @@ void handle404(HTTPRequest * req, HTTPResponse * res) {
165132
res->println("<body><h1>404 Not Found</h1><p>The requested resource was not found on this server.</p></body>");
166133
res->println("</html>");
167134
}
135+
136+
void setup()
137+
{
138+
// For logging
139+
Serial.begin(115200);
140+
while (!Serial && millis() < 5000);
141+
142+
///////////////////////////////////////////////
143+
144+
Serial.print("\nStarting Async_Server on "); Serial.println(ARDUINO_BOARD);
145+
146+
// Connect to WiFi
147+
Serial.println("Setting up WiFi");
148+
WiFi.begin(WIFI_SSID, WIFI_PSK);
149+
150+
while (WiFi.status() != WL_CONNECTED)
151+
{
152+
Serial.print(".");
153+
delay(500);
154+
}
155+
156+
Serial.print("Connected. IP=");
157+
Serial.println(WiFi.localIP());
158+
159+
// Setup the server as a separate task.
160+
Serial.println("Creating server task... ");
161+
// We pass:
162+
// serverTask - the function that should be run as separate task
163+
// "https443" - a name for the task (mainly used for logging)
164+
// 6144 - stack size in byte. If you want up to four clients, you should
165+
// not go below 6kB. If your stack is too small, you will encounter
166+
// Panic and stack canary exceptions, usually during the call to
167+
// SSL_accept.
168+
xTaskCreatePinnedToCore(serverTask, "https443", 6144, NULL, 1, NULL, ARDUINO_RUNNING_CORE);
169+
}
170+
171+
void loop()
172+
{
173+
Serial.println("loop()");
174+
delay(5000);
175+
}

examples/Async-Server/cert.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef CERT_H_
2+
#define CERT_H_
3+
#error You have to run the srcipt extras/create_cert.sh to recreate these files
4+
#endif

examples/Async-Server/private_key.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef PRIVATE_KEY_H_
2+
#define PRIVATE_KEY_H_
3+
#error You have to run the srcipt extras/create_cert.sh to recreate these files
4+
#endif

0 commit comments

Comments
 (0)