This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#### Releases v1.5.0 1. Add support to `ESP32` and `ESP32S2/S3/C3` boards using `LwIP W6100 Ethernet`
- Loading branch information
1 parent
58da4d6
commit 1a62e52
Showing
78 changed files
with
9,694 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,265 @@ | ||
/** | ||
Example for the ESP32_SC_W6100 HTTP(S) Webserver | ||
IMPORTANT NOTE: | ||
To run this script, your need to | ||
1) Make sure to have certificate data available. You will find a | ||
shell script (create_cert.sh) and instructions to do so in the library folder | ||
under extras/ | ||
This script will install an HTTPS Server on your ESP32_SC_W6100 with the following | ||
functionalities: | ||
- Show simple page on web server root | ||
- 404 for everything else | ||
The server will be run in a separate task, so that you can do your own stuff | ||
in the loop() function. | ||
Everything else is just like the Static-Page example | ||
*/ | ||
|
||
/** Check if we have multiple cores */ | ||
#if CONFIG_FREERTOS_UNICORE | ||
#define ARDUINO_RUNNING_CORE 0 | ||
#else | ||
#define ARDUINO_RUNNING_CORE 1 | ||
#endif | ||
|
||
// Include certificate data (see note above) | ||
#include "cert.h" | ||
#include "private_key.h" | ||
|
||
////////////////////////////////////////////////// | ||
|
||
// For ESP32_SC_W6100 | ||
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial | ||
|
||
// Debug Level from 0 to 4 | ||
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 | ||
|
||
////////////////////////////////////////////////////////// | ||
|
||
// For ESP32-S3 | ||
// Optional values to override default settings | ||
// Don't change unless you know what you're doing | ||
//#define ETH_SPI_HOST SPI3_HOST | ||
//#define SPI_CLOCK_MHZ 25 | ||
|
||
// Must connect INT to GPIOxx or not working | ||
//#define INT_GPIO 4 | ||
|
||
//#define MISO_GPIO 13 | ||
//#define MOSI_GPIO 11 | ||
//#define SCK_GPIO 12 | ||
//#define CS_GPIO 10 | ||
|
||
// For ESP32_C3 | ||
// Optional values to override default settings | ||
// Don't change unless you know what you're doing | ||
//#define ETH_SPI_HOST SPI2_HOST | ||
//#define SPI_CLOCK_MHZ 25 | ||
|
||
// Must connect INT to GPIOxx or not working | ||
//#define INT_GPIO 10 | ||
|
||
//#define MISO_GPIO 5 | ||
//#define MOSI_GPIO 6 | ||
//#define SCK_GPIO 4 | ||
//#define CS_GPIO 7 | ||
|
||
////////////////////////////////////////////////////////// | ||
|
||
#include <WebServer_ESP32_SC_W6100.h> | ||
|
||
////////////////////////////////////////////////// | ||
|
||
// Enter a MAC address and IP address for your controller below. | ||
#define NUMBER_OF_MAC 20 | ||
|
||
byte mac[][NUMBER_OF_MAC] = | ||
{ | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 }, | ||
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 }, | ||
}; | ||
|
||
// Select the IP address according to your local network | ||
IPAddress myIP(192, 168, 2, 232); | ||
IPAddress myGW(192, 168, 2, 1); | ||
IPAddress mySN(255, 255, 255, 0); | ||
|
||
// Google DNS Server IP | ||
IPAddress myDNS(8, 8, 8, 8); | ||
|
||
////////////////////////////////////////////////// | ||
|
||
#include <HTTPS_Server_Generic.h> | ||
|
||
// The HTTPS Server comes in a separate namespace. For easier use, include it here. | ||
using namespace httpsserver; | ||
|
||
// Create an SSL certificate object from the files included above | ||
SSLCert cert = SSLCert( | ||
example_crt_DER, example_crt_DER_len, | ||
example_key_DER, example_key_DER_len | ||
); | ||
|
||
// Create an SSL-enabled server that uses the certificate | ||
HTTPSServer secureServer = HTTPSServer(&cert); | ||
|
||
void serverTask(void *params) | ||
{ | ||
// In the separate task we first do everything that we would have done in the | ||
// setup() function, if we would run the server synchronously. | ||
|
||
// Note: The second task has its own stack, so you need to think about where | ||
// you create the server's resources and how to make sure that the server | ||
// can access everything it needs to access. Also make sure that concurrent | ||
// access is no problem in your sketch or implement countermeasures like locks | ||
// or mutexes. | ||
|
||
// Create nodes | ||
ResourceNode * nodeRoot = new ResourceNode("/", "GET", &handleRoot); | ||
ResourceNode * node404 = new ResourceNode("", "GET", &handle404); | ||
|
||
// Add nodes to the server | ||
secureServer.registerNode(nodeRoot); | ||
secureServer.setDefaultNode(node404); | ||
|
||
Serial.println("Starting server..."); | ||
secureServer.start(); | ||
|
||
if (secureServer.isRunning()) | ||
{ | ||
Serial.println("Server ready."); | ||
|
||
// "loop()" function of the separate task | ||
while (true) | ||
{ | ||
// This call will let the server do its work | ||
secureServer.loop(); | ||
|
||
// Other code would go here... | ||
delay(1); | ||
} | ||
} | ||
} | ||
|
||
void handleRoot(HTTPRequest * req, HTTPResponse * res) | ||
{ | ||
// Status code is 200 OK by default. | ||
// We want to deliver a simple HTML page, so we send a corresponding content type: | ||
res->setHeader("Content-Type", "text/html"); | ||
|
||
// The response implements the Print interface, so you can use it just like | ||
// you would write to Serial etc. | ||
res->println("<!DOCTYPE html>"); | ||
res->println("<html>"); | ||
res->println("<head><title>Hello World!</title></head>"); | ||
res->println("<body>"); | ||
res->println("<h1>Hello World!</h1>"); | ||
res->print("<p>Your server is running for "); | ||
// A bit of dynamic data: Show the uptime | ||
res->print((int)(millis() / 1000), DEC); | ||
res->println(" seconds.</p>"); | ||
res->println("</body>"); | ||
res->println("</html>"); | ||
} | ||
|
||
void handle404(HTTPRequest * req, HTTPResponse * res) | ||
{ | ||
// Discard request body, if we received any | ||
// We do this, as this is the default node and may also server POST/PUT requests | ||
req->discardRequestBody(); | ||
|
||
// Set the response status | ||
res->setStatusCode(404); | ||
res->setStatusText("Not Found"); | ||
|
||
// Set content type of the response | ||
res->setHeader("Content-Type", "text/html"); | ||
|
||
// Write a tiny HTTP page | ||
res->println("<!DOCTYPE html>"); | ||
res->println("<html>"); | ||
res->println("<head><title>Not Found</title></head>"); | ||
res->println("<body><h1>404 Not Found</h1><p>The requested resource was not found on this server.</p></body>"); | ||
res->println("</html>"); | ||
} | ||
|
||
void setup() | ||
{ | ||
// For logging | ||
Serial.begin(115200); | ||
|
||
while (!Serial && millis() < 5000); | ||
|
||
delay(500); | ||
|
||
/////////////////////////////////////////////// | ||
|
||
Serial.print("\nStarting Async_Server on " + String(ARDUINO_BOARD)); | ||
Serial.println(" with " + String(SHIELD_TYPE)); | ||
Serial.println(WEBSERVER_ESP32_SC_W6100_VERSION); | ||
Serial.println(HTTPS_SERVER_GENERIC_VERSION); | ||
|
||
/////////////////////////////////// | ||
|
||
// To be called before ETH.begin() | ||
ESP32_W6100_onEvent(); | ||
|
||
// start the ethernet connection and the server: | ||
// Use DHCP dynamic IP and random mac | ||
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ, | ||
// int SPI_HOST, uint8_t *W6100_Mac = W6100_Default_Mac); | ||
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST ); | ||
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[millis() % NUMBER_OF_MAC] ); | ||
|
||
// Static IP, leave without this line to get IP via DHCP | ||
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); | ||
//ETH.config(myIP, myGW, mySN, myDNS); | ||
|
||
ESP32_W6100_waitForConnect(); | ||
|
||
/////////////////////////////////// | ||
|
||
Serial.print(F("HTTPS EthernetWebServer is @ IP : ")); | ||
Serial.println(ETH.localIP()); | ||
|
||
Serial.print(F("To access, use https://")); | ||
Serial.println(ETH.localIP()); | ||
|
||
/////////////////////////////////////////////// | ||
|
||
// Setup the server as a separate task. | ||
Serial.println("Creating server task... "); | ||
// We pass: | ||
// serverTask - the function that should be run as separate task | ||
// "https443" - a name for the task (mainly used for logging) | ||
// 6144 - stack size in byte. If you want up to four clients, you should | ||
// not go below 6kB. If your stack is too small, you will encounter | ||
// Panic and stack canary exceptions, usually during the call to | ||
// SSL_accept. | ||
xTaskCreatePinnedToCore(serverTask, "https443", 6144, NULL, 1, NULL, ARDUINO_RUNNING_CORE); | ||
} | ||
|
||
void loop() | ||
{ | ||
Serial.println("loop()"); | ||
delay(5000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#ifndef CERT_H_ | ||
#define CERT_H_ | ||
#error You have to run the script extras/create_cert.sh to recreate these files | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#ifndef PRIVATE_KEY_H_ | ||
#define PRIVATE_KEY_H_ | ||
#error You have to run the script extras/create_cert.sh to recreate these files | ||
#endif |
Oops, something went wrong.