- Notifications
You must be signed in to change notification settings - Fork30
Simple Ethernet WebServer, HTTP/HTTPS Client wrapper library for WT32_ETH01 boards using LAN8720 Ethernet. The WebServer supports HTTP(S) GET and POST requests, provides argument parsing, handles one client at a time. It provides HTTP(S), MQTT(S) Client and supports WebServer serving from LittleFS/SPIFFS. Now supporting ESP32 core v2.0.0+
License
khoih-prog/WebServer_WT32_ETH01
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- Important Change from v1.5.0
- Why do we need this WebServer_WT32_ETH01 library
- Changelog
- Prerequisites
- Installation
- Libraries' Patches
- HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)
- Usage
- Examples
- Original Examples
- 1. AdvancedWebServer
- 2. HelloServer
- 3. HelloServer2
- 4. HttpBasicAuth
- 5.MQTTClient_Auth
- 6.MQTTClient_Basic
- 7.MQTT_ThingStream
- 8. PostServer
- 9. SimpleAuthentication
- 10. UdpNTPClient
- 11. UdpSendReceive
- 12. WebClient
- 13. WebClientRepeating
- 14. WebServer
- 15.ESP32_FS_EthernetWebServer
- 16.serveStatic
- 17.serveStaticLoadFile
- 18.multiFileProjectNew
- HTTPClient Examples
- HTTPS and MQTTS Examples
- OTA Example
- Original Examples
- Example AdvancedWebServer
- Debug Terminal Output Samples
- 1. AdvancedWebServer on ESP32_DEV with ETH_PHY_LAN8720
- 2. ESP32_FS_EthernetWebServer on ESP32_DEV with ETH_PHY_LAN8720
- 3. MQTT_ThingStream on ESP32_DEV with ETH_PHY_LAN8720
- 4. MQTTClient_Auth on ESP32_DEV with ETH_PHY_LAN8720
- 5. MQTTClient_Basic on ESP32_DEV with ETH_PHY_LAN8720
- 6. WebClient on ESP32_DEV with ETH_PHY_LAN8720
- 7. UdpNTPClient on ESP32_DEV with ETH_PHY_LAN8720
- 8. BasicHttpClient on ESP32_DEV with ETH_PHY_LAN8720
- 9. BasicHttpsClient on ESP32_DEV with ETH_PHY_LAN8720
- 10. WebClientMulti_SSL on ESP32_DEV with ETH_PHY_LAN8720
- 11. MQTTClient_SSL_Complex on ESP32_DEV with ETH_PHY_LAN8720
- 12. MQTTS_ThingStream on ESP32_DEV with ETH_PHY_LAN8720
- 13. MQTTClient_SSL on ESP32_DEV with ETH_PHY_LAN8720
- 14. MQTTClient_SSL_Auth on ESP32_DEV with ETH_PHY_LAN8720
- Debug
- Troubleshooting
- Releases
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License
- Copyright
Please have a look atHOWTO FixMultiple Definitions Linker Error
Why do we need thisWebServer_WT32_ETH01 library
ESP32 Corev2.0.0+ introduces new enum breaking almost allWT32_ETH01 codes written for corev1.0.6-.
It's really strange to define a breaking enumarduino_event_id_t inWiFiGeneric.h#L36-L78, compared to the oldsystem_event_id_t, now placed inesp_event_legacy.h#L29-L63
It's better to preserve the old enum order and just adding new itemsto do no harm to pre-2.0.0 codes
- Releases
v1.2.0-to be used for ESP32 corev1.0.6-only - Releases
v1.3.0can be used for either ESP32 corev2.0.0+orv1.0.6-.Default is using corev2.0.0+
To use with core v1.0.6-, just define in your sketch
#defineUSING_CORE_ESP32_CORE_V200_PLUSfalse
- Releases
v1.4.0+can be used for either ESP32 corev2.0.0+orv1.0.6-.Autodetect core
ThisWebServer_WT32_ETH01 library is a simple yet complete WebServer wrapper library forESP32-based WT32_ETH01 boards using LAN8720 Ethernet. The functions are similar and compatible to those ofESP32 WebServer andESP8266WebServer libraries to make life much easier to port sketches from ESP8266/ESP32.
ThisWebServer_WT32_ETH01 library also provides high-levelHTTP(S), MQTT(S) and WebSockets Client by using the functions from ESP32'sHTTPClient Library
The library provides these features:
- TCP Server and Client
- UDP Server and Client
- HTTP(S) Server and Client
- HTTP(S) GET and POST requests, provides argument parsing, handles one client at a time.
- High-level HTTP(S) (GET, POST, PUT, PATCH, DELETE), MQTT(S) and WebSocket Client.
Library is just a wrapper for:
ThisWebServer_WT32_ETH01 library currently supports these following boards:
- WT32_ETH01 boards using ESP32-based boards and LAN8720 Ethernet
Arduino IDE 1.8.19+for Arduino.ESP32 Core 2.0.5+for ESP32-based WT32_ETH01 boards using releasev1.3.0+.ESP32 Core 1.0.6-for ESP32-based WT32_ETH01 boards using releasev1.2.0-
The best and easiest way is to useArduino Library Manager. Search forWebServer_WT32_ETH01, then select / install the latest version.You can also use this link for more detailed instructions.
- Navigate toWebServer_WT32_ETH01 page.
- Download the latest release
WebServer_WT32_ETH01-main.zip. - Extract the zip file to
WebServer_WT32_ETH01-maindirectory - Copy the whole
WebServer_WT32_ETH01-mainfolder to Arduino libraries' directory such as~/Arduino/libraries/.
- InstallVS Code
- InstallPlatformIO
- InstallWebServer_WT32_ETH01 library by usingLibrary Manager. Search for WebServer_WT32_ETH01 inPlatform.io Author's Libraries
- Use includedplatformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples atProject Configuration File
To fixESP32 compile error, just copy the following file into theESP32 cores/esp32 directory (e.g. ./arduino-1.8.16/hardware/espressif/cores/esp32) to overwrite the old file:
The current library implementation, usingxyz-Impl.h instead of standardxyz.cpp, possibly creates certainMultiple Definitions Linker error in certain use cases.
You can include this.hpp file
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error#include"WebServer_WT32_ETH01.hpp"//https://github.com/khoih-prog/WebServer_WT32_ETH01
in many files. But be sure to use the following.h filein just 1.h,.cpp or.ino file, which mustnot be included in any other file, to avoidMultiple Definitions Linker Error
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error#include"WebServer_WT32_ETH01.h"//https://github.com/khoih-prog/WebServer_WT32_ETH01
Check the newmultiFileProject example for aHOWTO demo.
Please have a look atESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example to have more detailed description and solution of the issue.
- ADC1 controls ADC function for pinsGPIO32-GPIO39
- ADC2 controls ADC function for pinsGPIO0, 2, 4, 12-15, 25-27
Look in fileadc_common.c
In ADC2, there're two locks used for different cases:
lock shared with app and Wi-Fi:ESP32:When Wi-Fi using the ADC2, we assume it will never stop, so app checks the lock and returns immediately if failed.ESP32S2:The controller's control over the ADC is determined by the arbiter. There is no need to control by lock.
lock shared between tasks:when several tasks sharing the ADC2, we want to guaranteeall the requests will be handled.Since conversions are short (about 31us), app returns the lock very soon,we use a spinlock to stand there waiting to do conversions one by one.
adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock.
- In order to use ADC2 for other functions, we have toacquire complicated firmware locks and very difficult to do
- So, it's not advisable to use ADC2 with WiFi/BlueTooth (BT/BLE).
- Use ADC1, and pins GPIO32-GPIO39
- If somehow it's a must to use those pins serviced by ADC2 (GPIO0, 2, 4, 12, 13, 14, 15, 25, 26 and 27), use thefix mentioned at the end ofESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example to work with ESP32 WiFi/BlueTooth (BT/BLE).
WebServerserver(80);
Creates the WebServer_WT32_ETH01 class object.
Parameters:
host port number:int port (default is the standard HTTP port 80)
Starting the server
voidbegin();
Handling incoming client requests
voidhandleClient();
Disabling the server
voidclose();voidstop();
Both methods function the same
Client request handlers
voidon();voidaddHandler();voidonNotFound();voidonFileUpload();
Example:
server.on("/", handlerFunction); server.onNotFound(handlerFunction);// called when handler is not assigned server.onFileUpload(handlerFunction);// handle file uploads
Sending responses to the client
voidsend();voidsend_P();
Parameters:
code - HTTP response code, can be200 or404, etc.
content_type - HTTP content type, like"text/plain" or"image/png", etc.
content - actual content body
Getting information about request arguments
const String &arg();const String &argName();intargs();boolhasArg();
Function usage:
arg - get request argument value, usearg("plain") to get POST body
argName - get request argument name
args - get arguments count
hasArg - check if argument exist
Getting information about request headers
const String &header();const String &headerName();const String &hostHeader();intheaders();boolhasHeader();
Function usage:
header - get request header value
headerName - get request header name
hostHeader - get request host header if available, else empty string
headers - get header count
hasHeader - check if header exist
Authentication
boolauthenticate();voidrequestAuthentication();
Function usage:
authenticate - server authentication, returns true if client is authenticated else false
requestAuthentication - sends authentication failure response to the client
Example Usage:
if(!server.authenticate(username, password)){ server.requestAuthentication(); }
const String &uri();// get the current uri HTTPMethodmethod();// get the current method WiFiClientclient();// get the current client HTTPUpload &upload();// get the current uploadvoidsetContentLength();// set content lengthvoidsendHeader();// send HTTP headervoidsendContent();// send contentvoidsendContent_P();voidcollectHeaders();// set the request headers to collectvoidserveStatic();size_tstreamFile();
- AdvancedWebServer
- HelloServer
- HelloServer2
- HttpBasicAuth
- MQTTClient_Auth
- MQTTClient_Basic
- MQTT_ThingStream
- PostServer
- SimpleAuthentication
- UdpNTPClient
- UdpSendReceive
- WebClient
- WebClientRepeating
- WebServer
- ESP32_FS_EthernetWebServer
- serveStatic
- serveStaticLoadFile
- multiFileProjectNew
- MQTTClient_SSL
- MQTTClient_SSL_Auth
- MQTTClient_SSL_Complex
- MQTTS_ThingStream
- WebClientMulti_SSL
- WebClient_SSL
ExampleAdvancedWebServer
WebServer_WT32_ETH01/examples/AdvancedWebServer/AdvancedWebServer.ino
Lines 41 to 210 in49acabe
| #defineDEBUG_ETHERNET_WEBSERVER_PORT Serial | |
| // Debug Level from 0 to 4 | |
| #define_ETHERNET_WEBSERVER_LOGLEVEL_3 | |
| #include<WebServer_WT32_ETH01.h> | |
| WebServerserver(80); | |
| // Select the IP address according to your local network | |
| IPAddressmyIP(192,168,2,232); | |
| IPAddressmyGW(192,168,2,1); | |
| IPAddressmySN(255,255,255,0); | |
| // Google DNS Server IP | |
| IPAddressmyDNS(8,8,8,8); | |
| int reqCount =0;// number of requests received | |
| voidhandleRoot() | |
| { | |
| #defineBUFFER_SIZE400 | |
| char temp[BUFFER_SIZE]; | |
| int sec =millis() /1000; | |
| int min = sec /60; | |
| int hr = min /60; | |
| int day = hr /24; | |
| hr = hr %24; | |
| snprintf(temp, BUFFER_SIZE -1, | |
| "<html>\ | |
| <head>\ | |
| <meta http-equiv='refresh' content='5'/>\ | |
| <title>AdvancedWebServer %s</title>\ | |
| <style>\ | |
| body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\ | |
| </style>\ | |
| </head>\ | |
| <body>\ | |
| <h2>Hi from WebServer_WT32_ETH01!</h2>\ | |
| <h3>on %s</h3>\ | |
| <p>Uptime: %d d %02d:%02d:%02d</p>\ | |
| <img src=\"/test.svg\" />\ | |
| </body>\ | |
| </html>", BOARD_NAME, BOARD_NAME, day, hr %24, min %60, sec %60); | |
| server.send(200,F("text/html"), temp); | |
| } | |
| voidhandleNotFound() | |
| { | |
| String message =F("File Not Found\n\n"); | |
| message +=F("URI:"); | |
| message += server.uri(); | |
| message +=F("\nMethod:"); | |
| message += (server.method() == HTTP_GET) ?F("GET") :F("POST"); | |
| message +=F("\nArguments:"); | |
| message += server.args(); | |
| message +=F("\n"); | |
| for (uint8_t i =0; i < server.args(); i++) | |
| { | |
| message +="" + server.argName(i) +":" + server.arg(i) +"\n"; | |
| } | |
| server.send(404,F("text/plain"), message); | |
| } | |
| voiddrawGraph() | |
| { | |
| String out; | |
| out.reserve(3000); | |
| char temp[70]; | |
| out +=F("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n"); | |
| out +=F("<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"1\" stroke=\"rgb(0, 0, 0)\" />\n"); | |
| out +=F("<g stroke=\"black\">\n"); | |
| int y =rand() %130; | |
| for (int x =10; x <300; x +=10) | |
| { | |
| int y2 =rand() %130; | |
| sprintf(temp,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"1\" />\n", x,140 - y, x +10,140 - y2); | |
| out += temp; | |
| y = y2; | |
| } | |
| out +=F("</g>\n</svg>\n"); | |
| server.send(200,F("image/svg+xml"), out); | |
| } | |
| voidsetup() | |
| { | |
| Serial.begin(115200); | |
| while (!Serial); | |
| // Using this if Serial debugging is not necessary or not using Serial port | |
| //while (!Serial && (millis() < 3000)); | |
| Serial.print("\nStarting AdvancedWebServer on" +String(ARDUINO_BOARD)); | |
| Serial.println(" with" +String(SHIELD_TYPE)); | |
| Serial.println(WEBSERVER_WT32_ETH01_VERSION); | |
| // To be called before ETH.begin() | |
| WT32_ETH01_onEvent(); | |
| //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, | |
| // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); | |
| //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); | |
| ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); | |
| // 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); | |
| WT32_ETH01_waitForConnect(); | |
| server.on(F("/"), handleRoot); | |
| server.on(F("/test.svg"), drawGraph); | |
| server.on(F("/inline"), []() | |
| { | |
| server.send(200,F("text/plain"),F("This works as well")); | |
| }); | |
| server.onNotFound(handleNotFound); | |
| server.begin(); | |
| Serial.print(F("HTTP EthernetWebServer is @ IP :")); | |
| Serial.println(ETH.localIP()); | |
| } | |
| voidheartBeatPrint() | |
| { | |
| staticint num =1; | |
| Serial.print(F(".")); | |
| if (num ==80) | |
| { | |
| Serial.println(); | |
| num =1; | |
| } | |
| elseif (num++ %10 ==0) | |
| { | |
| Serial.print(F("")); | |
| } | |
| } | |
| voidcheck_status() | |
| { | |
| staticunsignedlong checkstatus_timeout =0; | |
| #defineSTATUS_CHECK_INTERVAL10000L | |
| // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. | |
| if ((millis() > checkstatus_timeout) || (checkstatus_timeout ==0)) | |
| { | |
| heartBeatPrint(); | |
| checkstatus_timeout =millis() + STATUS_CHECK_INTERVAL; | |
| } | |
| } | |
| voidloop() | |
| { | |
| server.handleClient(); | |
| check_status(); | |
| } |
The following are debug terminal output and screen shot when running exampleAdvancedWebServer on ESP32_DEV with ETH_PHY_LAN8720 (WT32_ETH01)
Starting AdvancedWebServer on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH StartedETH ConnectedETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.127, FULL_DUPLEX, 100MbpsHTTP EthernetWebServer is @ IP :192.168.2.127..
The terminal output ofWT32_ETH01 runningESP32_FS_EthernetWebServer
Starting ESP32_FS_EthernetWebServer on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH StartedETH ConnectedETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.127, FULL_DUPLEX, 100Mbps/home/kh/Arduino/libraries/LITTLEFS-master/src/lfs.c:1003:error: Corrupted dir pair at {0x0,0x1}E (4029) esp_littlefs: mount failed, (-84)E (4033) esp_littlefs: Failed to initialize LittleFSHTTP server started @192.168.2.127Open http://192.168.2.127/edit to see the file browserhandleFileRead: /handleFileUpload Name: /CanadaFlag_1.pnghandleFileUpload Size: 41214handleFileUpload Name: /CanadaFlag_2.pnghandleFileUpload Size: 8311handleFileUpload Name: /CanadaFlag_3.jpghandleFileUpload Size: 11156handleFileUpload Name: /edit.htm.gzhandleFileUpload Size: 4116handleFileUpload Name: /favicon.icohandleFileUpload Size: 1150handleFileUpload Name: /graphs.js.gzhandleFileUpload Size: 1971handleFileUpload Name: /index.htmhandleFileUpload Size: 3721handleFileRead: /handleFileRead: /graphs.jshandleFileRead: /edit.htmhandleFileRead: /index.htmhandleFileList: /handleFileList: [{"type":"file","name":"CanadaFlag_1.png"},{"type":"file","name":"CanadaFlag_2.png"},{"type":"file","name":"CanadaFlag_3.jpg"},{"type":"file","name":"edit.htm.gz"},{"type":"file","name":"favicon.ico"},{"type":"file","name":"graphs.js.gz"},{"type":"file","name":"index.htm"}]handleFileRead: /CanadaFlag_1.png
and the screen shot of the WebServer
The terminal output ofWT32_ETH01 runningMQTT_ThingStream example
Starting MQTT_ThingStream on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.232, FULL_DUPLEX, 100Mbps***************************************esp32-sniffer/12345678/ble***************************************Attempting MQTT connection to mqtt.thingstream.io...connectedPublished connection message successfully!Subscribed to: esp32-sniffer/12345678/bleMQTT Message Send : esp32-sniffer/12345678/ble => Hello from MQTT_ThingStream on WT32-ETH01 with ETH_PHY_LAN8720MQTT Message receive [esp32-sniffer/12345678/ble] Hello from MQTT_ThingStream on WT32-ETH01 with ETH_PHY_LAN8720MQTT Message Send : esp32-sniffer/12345678/ble => Hello from MQTT_ThingStream on WT32-ETH01 with ETH_PHY_LAN8720MQTT Message receive [esp32-sniffer/12345678/ble] Hello from MQTT_ThingStream on WT32-ETH01 with ETH_PHY_LAN8720
The terminal output ofWT32_ETH01 runningMQTTClient_Auth example
Starting MQTTClient_Auth on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.232, FULL_DUPLEX, 100MbpsAttempting MQTT connection to broker.emqx.io...connectedMessage Send : MQTT_Pub => Hello from MQTTClient_Auth on WT32-ETH01 with ETH_PHY_LAN8720Message arrived [MQTT_Pub] Hello from MQTTClient_Auth on WT32-ETH01 with ETH_PHY_LAN8720Message Send : MQTT_Pub => Hello from MQTTClient_Auth on WT32-ETH01 with ETH_PHY_LAN8720Message arrived [MQTT_Pub] Hello from MQTTClient_Auth on WT32-ETH01 with ETH_PHY_LAN8720
The terminal output ofWT32_ETH01 runningMQTTClient_Basic example
Starting MQTTClient_Basic on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.232, FULL_DUPLEX, 100MbpsAttempting MQTT connection to broker.emqx.io...connectedMessage Send : MQTT_Pub => Hello from MQTTClient_Basic on WT32-ETH01 with ETH_PHY_LAN8720Message arrived [MQTT_Pub] Hello from MQTTClient_Basic on WT32-ETH01 with ETH_PHY_LAN8720Message Send : MQTT_Pub => Hello from MQTTClient_Basic on WT32-ETH01 with ETH_PHY_LAN8720Message arrived [MQTT_Pub] Hello from MQTTClient_Basic on WT32-ETH01 with ETH_PHY_LAN8720Message Send : MQTT_Pub => Hello from MQTTClient_Basic on WT32-ETH01 with ETH_PHY_LAN8720Message arrived [MQTT_Pub] Hello from MQTTClient_Basic on WT32-ETH01 with ETH_PHY_LAN8720
The terminal output ofWT32_ETH01 runningWebClient example
Starting WebClient on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.232, FULL_DUPLEX, 100MbpsStarting connection to server...Connected to serverHTTP/1.1200 OKServer: nginx/1.4.2Date: Tue,06 Jul202104:36:48 GMTContent-Type: text/plainContent-Length:2263Last-Modified: Wed,02 Oct201313:46:47 GMTConnection: closeVary: Accept-EncodingETag:"524c23c7-8d7"Accept-Ranges: bytes `:;;;,` .:;;:. .;;;;;;;;;;;` :;;;;;;;;;;: TM `;;;;;;;;;;;;;;;` :;;;;;;;;;;;;;;; :;;;;;;;;;;;;;;;;;; `;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;; .;;;;;;;;;;;;;;;;;;;; ;;;;;;;;:` `;;;;;;;;; ,;;;;;;;;.` .;;;;;;;; .;;;;;;, :;;;;;;; .;;;;;;; ;;;;;;; ;;;;;; ;;;;;;; ;;;;;;, ;;;;;;. ,;;;;; ;;;;;;.;;;;;;` ;;;;;; ;;;;;. ;;;;;;;;;;;` ``` ;;;;;` ;;;;; ;;;;;;;;;, ;;; .;;;;;`;;;;: `;;;;;;;; ;;; ;;;;;,;;;;` `,,,,,,,, ;;;;;;; .,,;;;,,, ;;;;;:;;;;` .;;;;;;;; ;;;;;, :;;;;;;;; ;;;;;:;;;;` .;;;;;;;; `;;;;;; :;;;;;;;; ;;;;;.;;;;. ;;;;;;;. ;;; ;;;;; ;;;;; ;;;;;;;;; ;;; ;;;;; ;;;;; .;;;;;;;;;; ;;; ;;;;;, ;;;;;; `;;;;;;;;;;;; ;;;;; `;;;;;, .;;;;;; ;;;;;;; ;;;;;; ;;;;;;: :;;;;;;. ;;;;;;; ;;;;;; ;;;;;;;` .;;;;;;;, ;;;;;;;; ;;;;;;;: ;;;;;;;;;:,:;;;;;;;;;: ;;;;;;;;;;:,;;;;;;;;;; `;;;;;;;;;;;;;;;;;;;. ;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; :;;;;;;;;;;;;;;;;: ,;;;;;;;;;;;;;, ;;;;;;;;;;;;;; .;;;;;;;;;` ,;;;;;;;;: ;;; ;;;;;` ;;;;: .;; ;; ,;;;;;, ;;. `;, ;;;; ;;; ;;:;;; ;;;;;; .;; ;; ,;;;;;: ;;; `;, ;;;:;; ,;:; ;; ;; ;; ;; .;; ;; ,;, ;;;,`;, ;; ;; ;; ;: ;; ;; ;; ;; .;; ;; ,;, ;;;;`;, ;; ;;. ;: ;; ;;;;;: ;; ;; .;; ;; ,;, ;;`;;;, ;; ;;` ,;;;;; ;;`;; ;; ;; .;; ;; ,;, ;; ;;;, ;; ;; ;; ,;, ;; .;; ;;;;;: ;;;;;: ,;;;;;: ;; ;;, ;;;;;; ;; ;; ;; ;;` ;;;;. `;;;: ,;;;;;, ;; ;;, ;;;; Disconnecting from server...
The terminal output ofWT32_ETH01 runningUdpNTPClient example
Starting UdpNTPClient on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH StartedETH ConnectedETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.95FULL_DUPLEX, 100MbpsUDP Packet received, size48From132.163.96.4, port123Seconds since Jan11900 =3847154050Unix time =1638165250The UTC time is5:54:10UDP Packet received, size48From132.163.96.4, port123Seconds since Jan11900 =3847154062Unix time =1638165262The UTC time is5:54:22UDP Packet received, size48From132.163.96.4, port123Seconds since Jan11900 =3847154074Unix time =1638165274The UTC time is5:54:34UDP Packet received, size48From132.163.96.4, port123Seconds since Jan11900 =3847154086Unix time =1638165286The UTC time is5:54:46
The terminal output ofWT32_ETH01 runningBasicHttpClient example
Starting BasicHttpClient on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.232, FULL_DUPLEX, 100Mbps[HTTP] begin...[HTTP] GET...[HTTP] GET... code:200<!doctype html><html><head> <title>Example Domain</title> <meta charset="utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style type="text/css"> body { background-color: #f0f0f2; margin:0; padding:0; font-family: -apple-system, system-ui, BlinkMacSystemFont,"Segoe UI","Open Sans","Helvetica Neue", Helvetica, Arial, sans-serif; } div { width: 600px; margin: 5emauto; padding: 2em; background-color: #fdfdff; border-radius:0.5em; box-shadow: 2px 3px 7px 2pxrgba(0,0,0,0.02); } a:link, a:visited { color: #38488f; text-decoration: none; } @media (max-width: 700px) { div { margin:0auto; width:auto; } } </style> </head><body><div> <h1>Example Domain</h1> <p>This domain isfor use in illustrative examples in documents. You may usethis domain in literature without prior coordinationor askingfor permission.</p> <p><a href="https://www.iana.org/domains/example">More information...</a></p></div></body></html>
The terminal output ofWT32_ETH01 runningBasicHttpsClient example
Starting BasicHttpsClient on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.232, FULL_DUPLEX, 100MbpsWaitingfor NTP time sync: .Current time: Tue Jul605:29:392021[HTTPS] begin...[HTTPS] GET...[HTTPS] GET... code:200<HTML><HEAD> <!-- Created with AOLpress/2.0 --> <TITLE>Connection Header</TITLE></HEAD><BODY><P><IMG ALT="Jigsaw" BORDER="0" WIDTH="212" HEIGHT="49" SRC="/icons/jigsaw"><H1> The <I>Connection</I> header</H1><P>This page will be served to you with the following headers:<P><CODE>ExtensionHeader: ExtensionValue<BR>Connection: ExtensionHeader</CODE><P>If you're getting this page through a proxy, you should <I>not</I> see the<I>ExtensionHeader</I> !<P> <HR><BR><A HREF="mailto:jigsaw@w3.org">jigsaw@w3.org</A></BODY></HTML>Waiting 10s before the next round...
The terminal output ofWT32_ETH01 runningWebClientMulti_SSL example
Starting WebClientMulti_SSL on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.232, FULL_DUPLEX, 100MbpsWaitingfor NTP time sync: .Current time: Tue Jul619:58:272021Connecting to www.arduino.cc...Took:2312HTTP/1.1200 OKDate: Tue,06 Jul202119:58:31 GMTContent-Type: text/plainTransfer-Encoding: chunkedConnection: closeLast-Modified: Wed,02 Oct201313:46:47 GMTVary: Accept-EncodingStrict-Transport-Security: max-age=500; includeSubDomainsX-Content-Type-Options: nosniffX-XSS-Protection:1; mode=blockCF-Cache-Status: DYNAMICExpect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"Server: cloudflareCF-RAY: 66ab6888bbc63fd9-YYZalt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400, h3=":443"; ma=864008d7 `:;;;,` .:;;:. .;;;;;;;;;;;` :;;;;;;;;;;: TM `;;;;;;;;;;;;;;;` :;;;;;;;;;;;;;;; :;;;;;;;;;;;;;;;;;; `;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;; .;;;;;;;;;;;;;;;;;;;; ;;;;;;;;:` `;;;;;;;;; ,;;;;;;;;.` .;;;;;;;; .;;;;;;, :;;;;;;; .;;;;;;; ;;;;;;; ;;;;;; ;;;;;;; ;;;;;;, ;;;;;;. ,;;;;; ;;;;;;.;;;;;;` ;;;;;; ;;;;;. ;;;;;;;;;;;` ``` ;;;;;` ;;;;; ;;;;;;;;;, ;;; .;;;;;`;;;;: `;;;;;;;; ;;; ;;;;;,;;;;` `,,,,,,,, ;;;;;;; .,,;;;,,, ;;;;;:;;;;` .;;;;;;;; ;;;;;, :;;;;;;;; ;;;;;:;;;;` .;;;;;;;; `;;;;;; :;;;;;;;; ;;;;;.;;;;. ;;;;;;;. ;;; ;;;;; ;;;;; ;;;;;;;;; ;;; ;;;;; ;;;;; .;;;;;;;;;; ;;; ;;;;;, ;;;;;; `;;;;;;;;;;;; ;;;;; `;;;;;, .;;;;;; ;;;;;;; ;;;;;; ;;;;;;: :;;;;;;. ;;;;;;; ;;;;;; ;;;;;;;` .;;;;;;;, ;;;;;;;; ;;;;;;;: ;;;;;;;;;:,:;;;;;;;;;: ;;;;;;;;;;:,;;;;;;;;;; `;;;;;;;;;;;;;;;;;;;. ;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; :;;;;;;;;;;;;;;;;: ,;;;;;;;;;;;;;, ;;;;;;;;;;;;;; .;;;;;;;;;` ,;;;;;;;;: ;;; ;;;;;` ;;;;: .;; ;; ,;;;;;, ;;. `;, ;;;; ;;; ;;:;;; ;;;;;; .;; ;; ,;;;;;: ;;; `;, ;;;:;; ,;:; ;; ;; ;; ;; .;; ;; ,;, ;;;,`;, ;; ;; ;; ;: ;; ;; ;; ;; .;; ;; ,;, ;;;;`;, ;; ;;. ;: ;; ;;;;;: ;; ;; .;; ;; ,;, ;;`;;;, ;; ;;` ,;;;;; ;;`;; ;; ;; .;; ;; ,;, ;; ;;;, ;; ;; ;; ,;, ;; .;; ;;;;;: ;;;;;: ,;;;;;: ;; ;;, ;;;;;; ;; ;; ;; ;;` ;;;;. `;;;: ,;;;;;, ;; ;;, ;;;;0LoopCount1, Received2876 bytesDisconnecting.Connecting to www.cloudflare.com...Took:2249HTTP/1.1200 OKDate: Tue,06 Jul202119:58:54 GMTContent-Type: text/plainTransfer-Encoding: chunkedConnection: closeAccess-Control-Allow-Origin: *Server: cloudflareCF-RAY: 66ab6913cedb3ff1-YYZX-Frame-Options: DENYX-Content-Type-Options: nosniffExpires: Thu,01 Jan197000:00:01 GMTCache-Control: no-cachebafl=29f93h=www.cloudflare.comip=45.72.193.56ts=1625601534.066visit_scheme=httpsuag=SSLClientOverEthernetcolo=YYZhttp=http/1.1loc=CAtls=TLSv1.2sni=plaintextwarp=offgateway=off0LoopCount2, Received529 bytesDisconnecting.
The terminal output ofWT32_ETH01 runningMQTTClient_SSL_Complex example
Starting MQTTClient_SSL_Complex on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.232, FULL_DUPLEX, 100MbpsWaitingfor NTP time sync: .Current time: Tue Jul618:14:022021Attempting MQTT connection to broker.emqx.io...connectedMessage Send : MQTT_Pub => Hello from MQTTClient_SSL_Complex on WT32-ETH01, millis =5718Message arrived [MQTT_Pub] Hello from MQTTClient_SSL_Complex on WT32-ETH01, millis =5718Message Send : MQTT_Pub => Hello from MQTTClient_SSL_Complex on WT32-ETH01, millis =10719Message arrived [MQTT_Pub] Hello from MQTTClient_SSL_Complex on WT32-ETH01, millis =10719
The terminal output ofWT32_ETH01 runningMQTTS_ThingStream example
Starting MQTTS_ThingStream on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.232, FULL_DUPLEX, 100MbpsWaitingfor NTP time sync: .Current time: Tue Jul618:38:222021***************************************esp32-sniffer/12345678/ble***************************************Attempting MQTT connection to mqtt.thingstream.io...connectedPublished connection message successfully!Subscribed to: esp32-sniffer/12345678/bleMQTT Message Send : esp32-sniffer/12345678/ble => Hello from MQTTS_ThingStream on WT32-ETH01 with ETH_PHY_LAN8720MQTT Message receive [esp32-sniffer/12345678/ble] Hello from MQTTS_ThingStream on WT32-ETH01 with ETH_PHY_LAN8720MQTT Message Send : esp32-sniffer/12345678/ble => Hello from MQTTS_ThingStream on WT32-ETH01 with ETH_PHY_LAN8720MQTT Message receive [esp32-sniffer/12345678/ble] Hello from MQTTS_ThingStream on WT32-ETH01 with ETH_PHY_LAN8720
The terminal output ofWT32_ETH01 runningMQTTClient_SSL example
Starting MQTTClient_SSL on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.232, FULL_DUPLEX, 100MbpsWaitingfor NTP time sync: .Current time: Tue Jul617:11:002021Attempting MQTTS connection to broker.emqx.io...connectedMessage Send : MQTT_Pub => Hello from MQTTClient_SSL on WT32-ETH01Message arrived [MQTT_Pub] Hello from MQTTClient_SSL on WT32-ETH01Message Send : MQTT_Pub => Hello from MQTTClient_SSL on WT32-ETH01Message arrived [MQTT_Pub] Hello from MQTTClient_SSL on WT32-ETH01Message Send : MQTT_Pub => Hello from MQTTClient_SSL on WT32-ETH01Message arrived [MQTT_Pub] Hello from MQTTClient_SSL on WT32-ETH01Message Send : MQTT_Pub => Hello from MQTTClient_SSL on WT32-ETH01Message arrived [MQTT_Pub] Hello from MQTTClient_SSL on WT32-ETH01Message Send : MQTT_Pub => Hello from MQTTClient_SSL on WT32-ETH01Message arrived [MQTT_Pub] Hello from MQTTClient_SSL on WT32-ETH01
The terminal output ofWT32_ETH01 runningMQTTClient_SSL_Auth example
Starting MQTTClient_SSL_Auth on ESP32_DEV with ETH_PHY_LAN8720WebServer_WT32_ETH01 v1.5.1for core v2.0.0+ETH MAC: A8:03:2A:A1:61:73, IPv4:192.168.2.232, FULL_DUPLEX, 100MbpsWaitingfor NTP time sync: .Current time: Tue Jul618:05:142021Attempting MQTTS connection to broker.emqx.io...connectedMessage Send : MQTT_Pub => Hello from MQTTClient_SSL_Auth on WT32-ETH01Message arrived [MQTT_Pub] Hello from MQTTClient_SSL_Auth on WT32-ETH01Message Send : MQTT_Pub => Hello from MQTTClient_SSL_Auth on WT32-ETH01Message arrived [MQTT_Pub] Hello from MQTTClient_SSL_Auth on WT32-ETH01Message Send : MQTT_Pub => Hello from MQTTClient_SSL_Auth on WT32-ETH01Message arrived [MQTT_Pub] Hello from MQTTClient_SSL_Auth on WT32-ETH01Message Send : MQTT_Pub => Hello from MQTTClient_SSL_Auth on WT32-ETH01Message arrived [MQTT_Pub] Hello from MQTTClient_SSL_Auth on WT32-ETH01Message Send : MQTT_Pub => Hello from MQTTClient_SSL_Auth on WT32-ETH01Message arrived [MQTT_Pub] Hello from MQTTClient_SSL_Auth on WT32-ETH01
Debug is enabled by default on Serial. Debug Level from 0 to 4. To disable, change theETHERNET_WEBSERVER_LOGLEVEL to 0
// Use this to output debug msgs to Serial#defineDEBUG_ETHERNET_WEBSERVER_PORT Serial// Use this to disable all output debug msgs// Debug Level from 0 to 4#define_ETHERNET_WEBSERVER_LOGLEVEL_0
If you get compilation errors, more often than not, you may need to install a newer version of the board's core, applying Libraries' Patches, Packages' Patches or this library latest version.
Submit issues to:WebServer_WT32_ETH01 issues
- Bug Searching and Killing
- Add support to ESP32-basedWT32_ETH01 using LAN8720 Ethernet
- Add SSL support
- Add HTTPS and MQTTS examples
- Support breaking ESP32 core v2.0.0+ as well as v1.0.6-
- Auto detect ESP32 core v1.0.6- or v2.0.0+ to use correct settings
- Fix
multiple-definitionslinker error. - Add examplemultiFileProject to demo for multiple-file project
- Add exampleMQTT_And_OTA_Ethernet to demo how to use OTA
- Fix compile error for examplesserveStatic andserveStaticLoadFile to use built-in LittleFS library for new ESP32 cores
- Fix compile error for examplesESP32_FS_EthernetWebServer if WT32_ETH01 is selected as A0 (and many pins) not defined in new ESP32 cores
Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.
- Based on theIvan Grokhotkov's ESP32 WebServer andHTTPClient Library libraries.
- Thanks toSardar Azari to make PR instreamFile and serveStatic for ESP8266/ESP32 boards #22 to add WebServer feature to serve static from LittleFS/SPIFFS for ESP32. The exampleserveStatic andserveStaticLoadFile are also contributed bySardar Azari
- Thanks toDSikes to make PR inAdded MQTT and OTA over Ethernet example to examples folder #9 to add OTA feature, leading to v1.5.1
![]() ⭐️ Ivan Grokhotkov | ![]() Sardar Azari | ![]() DSikes |
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
- The library is licensed underGPLv3
Copyright (c) 2021- Khoi Hoang
About
Simple Ethernet WebServer, HTTP/HTTPS Client wrapper library for WT32_ETH01 boards using LAN8720 Ethernet. The WebServer supports HTTP(S) GET and POST requests, provides argument parsing, handles one client at a time. It provides HTTP(S), MQTT(S) Client and supports WebServer serving from LittleFS/SPIFFS. Now supporting ESP32 core v2.0.0+
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.





