├── .codespellrc ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── dependabot.yml ├── stale.yml └── workflows │ ├── auto-github-actions.yml │ ├── check-arduino.yml │ ├── report-size-deltas.yml │ └── spell-check.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── LibraryPatches └── esp32 │ └── cores │ └── esp32 │ └── Server.h ├── README.md ├── changelog.md ├── examples ├── AdvancedWebServer │ └── AdvancedWebServer.ino ├── ESP32_FS_EthernetWebServer │ ├── ESP32_FS_EthernetWebServer.ino │ └── data │ │ ├── CanadaFlag_1.png │ │ ├── CanadaFlag_2.png │ │ ├── CanadaFlag_3.jpg │ │ ├── edit.htm.gz │ │ ├── favicon.ico │ │ ├── graphs.js.gz │ │ └── index.htm ├── HTTPClient │ ├── Authorization │ │ └── Authorization.ino │ ├── BasicHttpClient │ │ └── BasicHttpClient.ino │ ├── BasicHttpsClient │ │ └── BasicHttpsClient.ino │ ├── StreamHttpClient │ │ └── StreamHttpClient.ino │ └── node_test_server │ │ ├── getPostPutDelete.js │ │ └── package.json ├── HelloServer │ └── HelloServer.ino ├── HelloServer2 │ └── HelloServer2.ino ├── HttpBasicAuth │ └── HttpBasicAuth.ino ├── MQTTClient_Auth │ └── MQTTClient_Auth.ino ├── MQTTClient_Basic │ └── MQTTClient_Basic.ino ├── MQTT_And_OTA_Ethernet │ └── MQTT_And_OTA_Ethernet.ino ├── MQTT_ThingStream │ └── MQTT_ThingStream.ino ├── PostServer │ └── PostServer.ino ├── SSL │ ├── MQTTClient_SSL │ │ ├── MQTTClient_SSL.ino │ │ └── certificates.h │ ├── MQTTClient_SSL_Auth │ │ ├── MQTTClient_SSL_Auth.ino │ │ └── certificates.h │ ├── MQTTClient_SSL_Complex │ │ ├── MQTTClient_SSL_Complex.ino │ │ └── certificates.h │ ├── MQTTS_ThingStream │ │ ├── MQTTS_ThingStream.ino │ │ └── certificates.h │ ├── WebClientMulti_SSL │ │ ├── WebClientMulti_SSL.ino │ │ └── certificates.h │ └── WebClient_SSL │ │ ├── WebClient_SSL.ino │ │ └── certificates.h ├── SimpleAuthentication │ └── SimpleAuthentication.ino ├── UdpNTPClient │ └── UdpNTPClient.ino ├── UdpSendReceive │ └── UdpSendReceive.ino ├── WebClient │ └── WebClient.ino ├── WebClientRepeating │ └── WebClientRepeating.ino ├── WebServer │ └── WebServer.ino ├── multiFileProject │ ├── multiFileProject.cpp │ ├── multiFileProject.h │ └── multiFileProject.ino ├── serveStatic │ ├── data │ │ ├── page1.html │ │ ├── page2.html │ │ └── page3.html │ └── serveStatic.ino └── serveStaticLoadFile │ ├── data │ ├── page1.html │ ├── page2.html │ └── page3.html │ └── serveStaticLoadFile.ino ├── library.json ├── library.properties ├── pics ├── AdvancedWebServer.png ├── ESP32_FS_EthernetWebServer.png └── serveStatic.png ├── platformio └── platformio.ini ├── src ├── WebServer_WT32_ETH01.h ├── WebServer_WT32_ETH01.hpp ├── WebServer_WT32_ETH01_Debug.h └── WebServer_WT32_ETH01_Impl.h └── utils ├── astyle_library.conf └── restyle.sh /.codespellrc: -------------------------------------------------------------------------------- 1 | # See: https://github.com/codespell-project/codespell#using-a-config-file 2 | [codespell] 3 | # In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: 4 | ignore-words-list = , 5 | check-filenames = 6 | check-hidden = 7 | skip = ./.git,./src,./examples,./Packages_Patches,./LibraryPatches 8 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Describe the bug 11 | 12 | A clear and concise description of what the bug is. 13 | 14 | ### Steps to Reproduce 15 | 16 | Steps to reproduce the behavior. Including the [MRE](https://stackoverflow.com/help/minimal-reproducible-example) sketches 17 | 18 | ### Expected behavior 19 | 20 | A clear and concise description of what you expected to happen. 21 | 22 | ### Actual behavior 23 | 24 | A clear and concise description of what you expected to happen. 25 | 26 | ### Debug and AT-command log (if applicable) 27 | 28 | A clear and concise description of what you expected to happen. 29 | 30 | ### Screenshots 31 | 32 | If applicable, add screenshots to help explain your problem. 33 | 34 | ### Information 35 | 36 | Please ensure to specify the following: 37 | 38 | * Arduino IDE version (e.g. 1.8.19) or Platform.io version 39 | * Board Core Version (e.g. ESP32 core v2.0.5) 40 | * Contextual information (e.g. what you were trying to achieve) 41 | * Simplest possible steps to reproduce 42 | * Anything that might be relevant in your opinion, such as: 43 | * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` 44 | * Network configuration 45 | 46 | 47 | ### Example 48 | 49 | ``` 50 | Arduino IDE version: 1.8.19 51 | WT32_ETH01 board 52 | ESP32 core v2.0.5 53 | OS: Ubuntu 20.04 LTS 54 | Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux 55 | 56 | Context: 57 | I encountered a crash while using this library 58 | 59 | Steps to reproduce: 60 | 1. ... 61 | 2. ... 62 | 3. ... 63 | 4. ... 64 | ``` 65 | 66 | --- 67 | 68 | ### Sending Feature Requests 69 | 70 | Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. 71 | 72 | There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/WebServer_WT32_ETH01/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. 73 | 74 | --- 75 | 76 | ### Sending Pull Requests 77 | 78 | Pull Requests with changes and fixes are also welcome! 79 | 80 | Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux) 81 | 82 | 1. Change directory to the library GitHub 83 | 84 | ``` 85 | xy@xy-Inspiron-3593:~$ cd Arduino/xy/WebServer_WT32_ETH01_GitHub/ 86 | xy@xy-Inspiron-3593:~/Arduino/xy/WebServer_WT32_ETH01_GitHub$ 87 | ``` 88 | 89 | 2. Issue astyle command 90 | 91 | ``` 92 | xy@xy-Inspiron-3593:~/Arduino/xy/WebServer_WT32_ETH01_GitHub$ bash utils/restyle.sh 93 | ``` 94 | 95 | 96 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Is your feature request related to a problem? Please describe. 11 | 12 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 13 | 14 | ### Describe the solution you'd like 15 | 16 | A clear and concise description of what you want to happen. 17 | 18 | ### Describe alternatives you've considered 19 | 20 | A clear and concise description of any alternative solutions or features you've considered. 21 | 22 | ### Additional context 23 | 24 | Add any other context or screenshots about the feature request here. 25 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # See: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#about-the-dependabotyml-file 2 | version: 2 3 | 4 | updates: 5 | # Configure check for outdated GitHub Actions actions in workflows. 6 | # See: https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot 7 | - package-ecosystem: github-actions 8 | directory: / # Check the repository's workflows under /.github/workflows/ 9 | schedule: 10 | interval: daily 11 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-stale - https://github.com/probot/stale 2 | 3 | daysUntilStale: 60 4 | daysUntilClose: 14 5 | limitPerRun: 30 6 | staleLabel: stale 7 | exemptLabels: 8 | - pinned 9 | - security 10 | - "to be implemented" 11 | - "for reference" 12 | - "move to PR" 13 | - "enhancement" 14 | 15 | only: issues 16 | onlyLabels: [] 17 | exemptProjects: false 18 | exemptMilestones: false 19 | exemptAssignees: false 20 | 21 | markComment: > 22 | [STALE_SET] This issue has been automatically marked as stale because it has not had 23 | recent activity. It will be closed in 14 days if no further activity occurs. Thank you 24 | for your contributions. 25 | 26 | unmarkComment: > 27 | [STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it opening the future. 28 | 29 | closeComment: > 30 | [STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. 31 | 32 | -------------------------------------------------------------------------------- /.github/workflows/auto-github-actions.yml: -------------------------------------------------------------------------------- 1 | name: auto-github-actions 2 | on: [push] 3 | jobs: 4 | check-bats-version: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v3 8 | - uses: actions/setup-node@v3 9 | with: 10 | node-version: '14' 11 | - run: npm install -g bats 12 | - run: bats -v 13 | -------------------------------------------------------------------------------- /.github/workflows/check-arduino.yml: -------------------------------------------------------------------------------- 1 | name: Check Arduino 2 | 3 | # See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows 4 | on: 5 | push: 6 | pull_request: 7 | schedule: 8 | # Run every Tuesday at 8 AM UTC to catch breakage caused by new rules added to Arduino Lint. 9 | - cron: "0 8 * * TUE" 10 | workflow_dispatch: 11 | repository_dispatch: 12 | 13 | jobs: 14 | lint: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Checkout repository 19 | uses: actions/checkout@v3 20 | 21 | - name: Arduino Lint 22 | uses: arduino/arduino-lint-action@v1 23 | with: 24 | compliance: specification 25 | library-manager: update 26 | # Always use this setting for official repositories. Remove for 3rd party projects. 27 | official: true 28 | project-type: library 29 | -------------------------------------------------------------------------------- /.github/workflows/report-size-deltas.yml: -------------------------------------------------------------------------------- 1 | name: Report Size Deltas 2 | 3 | on: 4 | schedule: 5 | - cron: '*/5 * * * *' 6 | 7 | jobs: 8 | report: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Comment size deltas reports to PRs 13 | uses: arduino/report-size-deltas@v1 14 | with: 15 | # The name of the workflow artifact created by the "Compile Examples" workflow 16 | sketches-reports-source: sketches-reports 17 | -------------------------------------------------------------------------------- /.github/workflows/spell-check.yml: -------------------------------------------------------------------------------- 1 | name: Spell Check 2 | 3 | on: 4 | pull_request: 5 | push: 6 | schedule: 7 | # run every Tuesday at 3 AM UTC 8 | - cron: "0 3 * * 2" 9 | workflow_dispatch: 10 | repository_dispatch: 11 | 12 | jobs: 13 | spellcheck: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v3 19 | 20 | # See: https://github.com/codespell-project/actions-codespell/blob/master/README.md 21 | - name: Spell check 22 | uses: codespell-project/actions-codespell@master 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing to WebServer_WT32_ETH01 2 | 3 | ### Reporting Bugs 4 | 5 | Please report bugs in WebServer_WT32_ETH01 if you find them. 6 | 7 | However, before reporting a bug please check through the following: 8 | 9 | * [Existing Open Issues](https://github.com/khoih-prog/WebServer_WT32_ETH01/issues) - someone might have already encountered this. 10 | 11 | If you don't find anything, please [open a new issue](https://github.com/khoih-prog/WebServer_WT32_ETH01/issues/new). 12 | 13 | ### How to submit a bug report 14 | 15 | Please ensure to specify the following: 16 | 17 | * Arduino IDE version (e.g. 1.8.19) or Platform.io version 18 | * Board Core Version (e.g. ESP32 core v2.0.5) 19 | * Contextual information (e.g. what you were trying to achieve) 20 | * Simplest possible steps to reproduce 21 | * Anything that might be relevant in your opinion, such as: 22 | * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` 23 | * Network configuration 24 | 25 | 26 | ### Example 27 | 28 | ``` 29 | Arduino IDE version: 1.8.19 30 | WT32_ETH01 board 31 | ESP32 core v2.0.5 32 | OS: Ubuntu 20.04 LTS 33 | Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux 34 | 35 | Context: 36 | I encountered a crash while using this library 37 | 38 | Steps to reproduce: 39 | 1. ... 40 | 2. ... 41 | 3. ... 42 | 4. ... 43 | ``` 44 | 45 | --- 46 | 47 | ### Sending Feature Requests 48 | 49 | Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. 50 | 51 | There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/WebServer_WT32_ETH01/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. 52 | 53 | --- 54 | 55 | ### Sending Pull Requests 56 | 57 | Pull Requests with changes and fixes are also welcome! 58 | 59 | Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux) 60 | 61 | 1. Change directory to the library GitHub 62 | 63 | ``` 64 | xy@xy-Inspiron-3593:~$ cd Arduino/xy/WebServer_WT32_ETH01_GitHub/ 65 | xy@xy-Inspiron-3593:~/Arduino/xy/WebServer_WT32_ETH01_GitHub$ 66 | ``` 67 | 68 | 2. Issue astyle command 69 | 70 | ``` 71 | xy@xy-Inspiron-3593:~/Arduino/xy/WebServer_WT32_ETH01_GitHub$ bash utils/restyle.sh 72 | ``` 73 | 74 | 75 | -------------------------------------------------------------------------------- /LibraryPatches/esp32/cores/esp32/Server.h: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - Base class that provides Server 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef server_h 21 | #define server_h 22 | 23 | #include "Print.h" 24 | 25 | class Server: public Print 26 | { 27 | public: 28 | // KH, change to fix compiler error for EthernetWebServer 29 | // error: cannot declare field 'EthernetWebServer::_server' to be of abstract type 'EthernetServer' 30 | // virtual void begin(uint16_t port=0) =0; 31 | //virtual void begin() = 0; 32 | void begin() {}; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | ## WebServer_WT32_ETH01 Library 2 | 3 | [![arduino-library-badge](https://www.ardu-badge.com/badge/WebServer_WT32_ETH01.svg?)](https://www.ardu-badge.com/WebServer_WT32_ETH01) 4 | [![GitHub release](https://img.shields.io/github/release/khoih-prog/WebServer_WT32_ETH01.svg)](https://github.com/khoih-prog/WebServer_WT32_ETH01/releases) 5 | [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) 6 | [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/WebServer_WT32_ETH01.svg)](http://github.com/khoih-prog/WebServer_WT32_ETH01/issues) 7 | 8 | 9 | Donate to my libraries using BuyMeACoffee 10 | 11 | 12 | --- 13 | --- 14 | 15 | ## Table of Contents 16 | 17 | 18 | * [Changelog](#changelog) 19 | * [Releases v1.5.1](#releases-v151) 20 | * [Releases v1.5.0](#releases-v150) 21 | * [Releases v1.4.1](#releases-v141) 22 | * [Releases v1.4.0](#releases-v140) 23 | * [Releases v1.3.0](#releases-v130) 24 | * [Releases v1.2.0](#releases-v120) 25 | * [Releases v1.1.0](#releases-v110) 26 | * [Releases v1.0.0](#releases-v100) 27 | 28 | --- 29 | --- 30 | 31 | ## Changelog 32 | 33 | #### Releases v1.5.1 34 | 35 | 1. Add example [MQTT_And_OTA_Ethernet](https://github.com/khoih-prog/WebServer_WT32_ETH01/tree/main/examples/MQTT_And_OTA_Ethernet) to demo how to use OTA. Check [Added MQTT and OTA over Ethernet example to examples folder #9](https://github.com/khoih-prog/WebServer_WT32_ETH01/pull/9) 36 | 2. Fix compile error for examples [serveStatic](https://github.com/khoih-prog/WebServer_WT32_ETH01/tree/main/examples/serveStatic) and [serveStaticLoadFile](https://github.com/khoih-prog/WebServer_WT32_ETH01/tree/main/examples/serveStaticLoadFile) to use built-in LittleFS library for new ESP32 cores 37 | 3. Fix compile error for examples [ESP32_FS_EthernetWebServer](https://github.com/khoih-prog/WebServer_WT32_ETH01/tree/main/examples/ESP32_FS_EthernetWebServer) if WT32_ETH01 is selected as A0 (and many pins) not defined in new ESP32 cores 38 | 39 | #### Releases v1.5.0 40 | 41 | 1. Fix multiple-definitions linker error. 42 | 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project to avoid `multiple-definitions` linker error 43 | 44 | #### Releases v1.4.1 45 | 46 | 1. Fix bug in examples to reduce connection time 47 | 48 | #### Releases v1.4.0 49 | 50 | ##### Warning: Releases v1.4.0+ can be used and autodetect ESP32 core v2.0.0+ or v1.0.6-. 51 | 52 | 1. Auto detect ESP32 core 53 | 2. Renew examples 54 | 55 | #### Releases v1.3.0 56 | 57 | ##### Warning: Releases v1.3.0+ can be used for either ESP32 core v2.0.0+ or v1.0.6-. Default is v2.0.0+ now 58 | 59 | 1. Making compatible either with breaking core v2.0.0+ or core v1.0.6- 60 | 2. Renew examples 61 | 62 | 63 | #### Releases v1.2.0 64 | 65 | ##### Warning: Releases v1.2.0- to be used for ESP32 core v1.0.6- only 66 | 67 | 1. Add common code to library 68 | 2. Renew examples 69 | 70 | #### Releases v1.1.0 71 | 72 | 1. Add SSL support 73 | 2. Add HTTPS and MQTTS examples 74 | 75 | #### Releases v1.0.0 76 | 77 | 1. Initial coding to support WT32_ETH01 boards 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /examples/AdvancedWebServer/AdvancedWebServer.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | AdvancedWebServer.h - Dead simple web-server for Ethernet shields 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | 12 | Copyright (c) 2015, Majenko Technologies 13 | All rights reserved. 14 | 15 | Redistribution and use in source and binary forms, with or without modification, 16 | are permitted provided that the following conditions are met: 17 | 18 | Redistributions of source code must retain the above copyright notice, this 19 | list of conditions and the following disclaimer. 20 | 21 | Redistributions in binary form must reproduce the above copyright notice, this 22 | list of conditions and the following disclaimer in the documentation and/or 23 | other materials provided with the distribution. 24 | 25 | Neither the name of Majenko Technologies nor the names of its 26 | contributors may be used to endorse or promote products derived from 27 | this software without specific prior written permission. 28 | 29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 30 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 31 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 32 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 33 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 35 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 36 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 38 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | *****************************************************************************************************************************/ 40 | 41 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 42 | 43 | // Debug Level from 0 to 4 44 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 45 | 46 | #include 47 | 48 | WebServer server(80); 49 | 50 | // Select the IP address according to your local network 51 | IPAddress myIP(192, 168, 2, 232); 52 | IPAddress myGW(192, 168, 2, 1); 53 | IPAddress mySN(255, 255, 255, 0); 54 | 55 | // Google DNS Server IP 56 | IPAddress myDNS(8, 8, 8, 8); 57 | 58 | int reqCount = 0; // number of requests received 59 | 60 | void handleRoot() 61 | { 62 | #define BUFFER_SIZE 400 63 | 64 | char temp[BUFFER_SIZE]; 65 | int sec = millis() / 1000; 66 | int min = sec / 60; 67 | int hr = min / 60; 68 | int day = hr / 24; 69 | 70 | hr = hr % 24; 71 | 72 | snprintf(temp, BUFFER_SIZE - 1, 73 | "\ 74 | \ 75 | \ 76 | AdvancedWebServer %s\ 77 | \ 80 | \ 81 | \ 82 |

Hi from WebServer_WT32_ETH01!

\ 83 |

on %s

\ 84 |

Uptime: %d d %02d:%02d:%02d

\ 85 | \ 86 | \ 87 | ", BOARD_NAME, BOARD_NAME, day, hr % 24, min % 60, sec % 60); 88 | 89 | server.send(200, F("text/html"), temp); 90 | } 91 | 92 | void handleNotFound() 93 | { 94 | String message = F("File Not Found\n\n"); 95 | 96 | message += F("URI: "); 97 | message += server.uri(); 98 | message += F("\nMethod: "); 99 | message += (server.method() == HTTP_GET) ? F("GET") : F("POST"); 100 | message += F("\nArguments: "); 101 | message += server.args(); 102 | message += F("\n"); 103 | 104 | for (uint8_t i = 0; i < server.args(); i++) 105 | { 106 | message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; 107 | } 108 | 109 | server.send(404, F("text/plain"), message); 110 | } 111 | 112 | void drawGraph() 113 | { 114 | String out; 115 | out.reserve(3000); 116 | char temp[70]; 117 | 118 | out += F("\n"); 119 | out += F("\n"); 120 | out += F("\n"); 121 | int y = rand() % 130; 122 | 123 | for (int x = 10; x < 300; x += 10) 124 | { 125 | int y2 = rand() % 130; 126 | sprintf(temp, "\n", x, 140 - y, x + 10, 140 - y2); 127 | out += temp; 128 | y = y2; 129 | } 130 | 131 | out += F("\n\n"); 132 | 133 | server.send(200, F("image/svg+xml"), out); 134 | } 135 | 136 | void setup() 137 | { 138 | Serial.begin(115200); 139 | 140 | while (!Serial); 141 | 142 | // Using this if Serial debugging is not necessary or not using Serial port 143 | //while (!Serial && (millis() < 3000)); 144 | 145 | Serial.print("\nStarting AdvancedWebServer on " + String(ARDUINO_BOARD)); 146 | Serial.println(" with " + String(SHIELD_TYPE)); 147 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 148 | 149 | // To be called before ETH.begin() 150 | WT32_ETH01_onEvent(); 151 | 152 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 153 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 154 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 155 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 156 | 157 | // Static IP, leave without this line to get IP via DHCP 158 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 159 | ETH.config(myIP, myGW, mySN, myDNS); 160 | 161 | WT32_ETH01_waitForConnect(); 162 | 163 | server.on(F("/"), handleRoot); 164 | server.on(F("/test.svg"), drawGraph); 165 | server.on(F("/inline"), []() 166 | { 167 | server.send(200, F("text/plain"), F("This works as well")); 168 | }); 169 | 170 | server.onNotFound(handleNotFound); 171 | server.begin(); 172 | 173 | Serial.print(F("HTTP EthernetWebServer is @ IP : ")); 174 | Serial.println(ETH.localIP()); 175 | } 176 | 177 | void heartBeatPrint() 178 | { 179 | static int num = 1; 180 | 181 | Serial.print(F(".")); 182 | 183 | if (num == 80) 184 | { 185 | Serial.println(); 186 | num = 1; 187 | } 188 | else if (num++ % 10 == 0) 189 | { 190 | Serial.print(F(" ")); 191 | } 192 | } 193 | 194 | void check_status() 195 | { 196 | static unsigned long checkstatus_timeout = 0; 197 | 198 | #define STATUS_CHECK_INTERVAL 10000L 199 | 200 | // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. 201 | if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0)) 202 | { 203 | heartBeatPrint(); 204 | checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; 205 | } 206 | } 207 | 208 | void loop() 209 | { 210 | server.handleClient(); 211 | check_status(); 212 | } 213 | -------------------------------------------------------------------------------- /examples/ESP32_FS_EthernetWebServer/data/CanadaFlag_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/WebServer_WT32_ETH01/593fe6211a30329499952ba0b29f6d37fc7b5144/examples/ESP32_FS_EthernetWebServer/data/CanadaFlag_1.png -------------------------------------------------------------------------------- /examples/ESP32_FS_EthernetWebServer/data/CanadaFlag_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/WebServer_WT32_ETH01/593fe6211a30329499952ba0b29f6d37fc7b5144/examples/ESP32_FS_EthernetWebServer/data/CanadaFlag_2.png -------------------------------------------------------------------------------- /examples/ESP32_FS_EthernetWebServer/data/CanadaFlag_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/WebServer_WT32_ETH01/593fe6211a30329499952ba0b29f6d37fc7b5144/examples/ESP32_FS_EthernetWebServer/data/CanadaFlag_3.jpg -------------------------------------------------------------------------------- /examples/ESP32_FS_EthernetWebServer/data/edit.htm.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/WebServer_WT32_ETH01/593fe6211a30329499952ba0b29f6d37fc7b5144/examples/ESP32_FS_EthernetWebServer/data/edit.htm.gz -------------------------------------------------------------------------------- /examples/ESP32_FS_EthernetWebServer/data/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/WebServer_WT32_ETH01/593fe6211a30329499952ba0b29f6d37fc7b5144/examples/ESP32_FS_EthernetWebServer/data/favicon.ico -------------------------------------------------------------------------------- /examples/ESP32_FS_EthernetWebServer/data/graphs.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/WebServer_WT32_ETH01/593fe6211a30329499952ba0b29f6d37fc7b5144/examples/ESP32_FS_EthernetWebServer/data/graphs.js.gz -------------------------------------------------------------------------------- /examples/ESP32_FS_EthernetWebServer/data/index.htm: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | 22 | ESP Monitor 23 | 24 | 85 | 86 | 87 |
88 | 89 | 90 | 91 | 92 |
93 |
94 |
95 |
96 | 97 | -------------------------------------------------------------------------------- /examples/HTTPClient/Authorization/Authorization.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | Authorization.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 17 | 18 | #include 19 | #include 20 | 21 | // Select the IP address according to your local network 22 | IPAddress myIP(192, 168, 2, 232); 23 | IPAddress myGW(192, 168, 2, 1); 24 | IPAddress mySN(255, 255, 255, 0); 25 | 26 | // Google DNS Server IP 27 | IPAddress myDNS(8, 8, 8, 8); 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | 33 | while (!Serial); 34 | 35 | // Using this if Serial debugging is not necessary or not using Serial port 36 | //while (!Serial && (millis() < 3000)); 37 | 38 | Serial.print("\nStarting Authorization on " + String(ARDUINO_BOARD)); 39 | Serial.println(" with " + String(SHIELD_TYPE)); 40 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 41 | 42 | // To be called before ETH.begin() 43 | WT32_ETH01_onEvent(); 44 | 45 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 46 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 47 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 48 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 49 | 50 | // Static IP, leave without this line to get IP via DHCP 51 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 52 | ETH.config(myIP, myGW, mySN, myDNS); 53 | 54 | WT32_ETH01_waitForConnect(); 55 | } 56 | 57 | void loop() 58 | { 59 | if (WT32_ETH01_isConnected()) 60 | { 61 | HTTPClient http; 62 | 63 | Serial.print("[HTTP] begin...\n"); 64 | 65 | http.begin("http://user:password@192.168.2.112/test.html"); 66 | 67 | /* 68 | // or 69 | http.begin("http://192.168.2.112/test.html"); 70 | http.setAuthorization("user", "password"); 71 | // or 72 | http.begin("http://192.168.2.112/test.html"); 73 | http.setAuthorization("dXNlcjpwYXN3b3Jk"); 74 | */ 75 | 76 | Serial.print("[HTTP] GET...\n"); 77 | // start connection and send HTTP header 78 | int httpCode = http.GET(); 79 | 80 | // httpCode will be negative on error 81 | if (httpCode > 0) 82 | { 83 | // HTTP header has been send and Server response header has been handled 84 | Serial.printf("[HTTP] GET... code: %d\n", httpCode); 85 | 86 | // file found at server 87 | if (httpCode == HTTP_CODE_OK) 88 | { 89 | String payload = http.getString(); 90 | Serial.println(payload); 91 | } 92 | } 93 | else 94 | { 95 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 96 | } 97 | 98 | http.end(); 99 | } 100 | 101 | delay(10000); 102 | } 103 | -------------------------------------------------------------------------------- /examples/HTTPClient/BasicHttpClient/BasicHttpClient.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | BasicHttpClient.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 17 | 18 | #include 19 | #include 20 | 21 | // Select the IP address according to your local network 22 | IPAddress myIP(192, 168, 2, 232); 23 | IPAddress myGW(192, 168, 2, 1); 24 | IPAddress mySN(255, 255, 255, 0); 25 | 26 | // Google DNS Server IP 27 | IPAddress myDNS(8, 8, 8, 8); 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | 33 | while (!Serial); 34 | 35 | // Using this if Serial debugging is not necessary or not using Serial port 36 | //while (!Serial && (millis() < 3000)); 37 | 38 | Serial.print("\nStarting BasicHttpClient on " + String(ARDUINO_BOARD)); 39 | Serial.println(" with " + String(SHIELD_TYPE)); 40 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 41 | 42 | // To be called before ETH.begin() 43 | WT32_ETH01_onEvent(); 44 | 45 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 46 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 47 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 48 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 49 | 50 | // Static IP, leave without this line to get IP via DHCP 51 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 52 | ETH.config(myIP, myGW, mySN, myDNS); 53 | 54 | WT32_ETH01_waitForConnect(); 55 | } 56 | 57 | void loop() 58 | { 59 | if (WT32_ETH01_isConnected()) 60 | { 61 | HTTPClient http; 62 | 63 | Serial.print("[HTTP] begin...\n"); 64 | // configure traged server and url 65 | //http.begin("https://www.howsmyssl.com/a/check", ca); //HTTPS 66 | http.begin("http://example.com/index.html"); //HTTP 67 | 68 | Serial.print("[HTTP] GET...\n"); 69 | // start connection and send HTTP header 70 | int httpCode = http.GET(); 71 | 72 | // httpCode will be negative on error 73 | if (httpCode > 0) 74 | { 75 | // HTTP header has been send and Server response header has been handled 76 | Serial.printf("[HTTP] GET... code: %d\n", httpCode); 77 | 78 | // file found at server 79 | if (httpCode == HTTP_CODE_OK) 80 | { 81 | String payload = http.getString(); 82 | Serial.println(payload); 83 | } 84 | } 85 | else 86 | { 87 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 88 | } 89 | 90 | http.end(); 91 | } 92 | 93 | delay(5000); 94 | } 95 | -------------------------------------------------------------------------------- /examples/HTTPClient/BasicHttpsClient/BasicHttpsClient.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | BasicHttpsClient.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | // Select the IP address according to your local network 24 | IPAddress myIP(192, 168, 2, 232); 25 | IPAddress myGW(192, 168, 2, 1); 26 | IPAddress mySN(255, 255, 255, 0); 27 | 28 | // Google DNS Server IP 29 | IPAddress myDNS(8, 8, 8, 8); 30 | 31 | // This is GandiStandardSSLCA2.pem, the root Certificate Authority that signed 32 | // the server certifcate for the demo server https://jigsaw.w3.org in this 33 | // example. This certificate is valid until Sep 11 23:59:59 2024 GMT 34 | const char* rootCACertificate = 35 | "-----BEGIN CERTIFICATE-----\n" \ 36 | "MIIF6TCCA9GgAwIBAgIQBeTcO5Q4qzuFl8umoZhQ4zANBgkqhkiG9w0BAQwFADCB\n" \ 37 | "iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl\n" \ 38 | "cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV\n" \ 39 | "BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTQw\n" \ 40 | "OTEyMDAwMDAwWhcNMjQwOTExMjM1OTU5WjBfMQswCQYDVQQGEwJGUjEOMAwGA1UE\n" \ 41 | "CBMFUGFyaXMxDjAMBgNVBAcTBVBhcmlzMQ4wDAYDVQQKEwVHYW5kaTEgMB4GA1UE\n" \ 42 | "AxMXR2FuZGkgU3RhbmRhcmQgU1NMIENBIDIwggEiMA0GCSqGSIb3DQEBAQUAA4IB\n" \ 43 | "DwAwggEKAoIBAQCUBC2meZV0/9UAPPWu2JSxKXzAjwsLibmCg5duNyj1ohrP0pIL\n" \ 44 | "m6jTh5RzhBCf3DXLwi2SrCG5yzv8QMHBgyHwv/j2nPqcghDA0I5O5Q1MsJFckLSk\n" \ 45 | "QFEW2uSEEi0FXKEfFxkkUap66uEHG4aNAXLy59SDIzme4OFMH2sio7QQZrDtgpbX\n" \ 46 | "bmq08j+1QvzdirWrui0dOnWbMdw+naxb00ENbLAb9Tr1eeohovj0M1JLJC0epJmx\n" \ 47 | "bUi8uBL+cnB89/sCdfSN3tbawKAyGlLfOGsuRTg/PwSWAP2h9KK71RfWJ3wbWFmV\n" \ 48 | "XooS/ZyrgT5SKEhRhWvzkbKGPym1bgNi7tYFAgMBAAGjggF1MIIBcTAfBgNVHSME\n" \ 49 | "GDAWgBRTeb9aqitKz1SA4dibwJ3ysgNmyzAdBgNVHQ4EFgQUs5Cn2MmvTs1hPJ98\n" \ 50 | "rV1/Qf1pMOowDgYDVR0PAQH/BAQDAgGGMBIGA1UdEwEB/wQIMAYBAf8CAQAwHQYD\n" \ 51 | "VR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMCIGA1UdIAQbMBkwDQYLKwYBBAGy\n" \ 52 | "MQECAhowCAYGZ4EMAQIBMFAGA1UdHwRJMEcwRaBDoEGGP2h0dHA6Ly9jcmwudXNl\n" \ 53 | "cnRydXN0LmNvbS9VU0VSVHJ1c3RSU0FDZXJ0aWZpY2F0aW9uQXV0aG9yaXR5LmNy\n" \ 54 | "bDB2BggrBgEFBQcBAQRqMGgwPwYIKwYBBQUHMAKGM2h0dHA6Ly9jcnQudXNlcnRy\n" \ 55 | "dXN0LmNvbS9VU0VSVHJ1c3RSU0FBZGRUcnVzdENBLmNydDAlBggrBgEFBQcwAYYZ\n" \ 56 | "aHR0cDovL29jc3AudXNlcnRydXN0LmNvbTANBgkqhkiG9w0BAQwFAAOCAgEAWGf9\n" \ 57 | "crJq13xhlhl+2UNG0SZ9yFP6ZrBrLafTqlb3OojQO3LJUP33WbKqaPWMcwO7lWUX\n" \ 58 | "zi8c3ZgTopHJ7qFAbjyY1lzzsiI8Le4bpOHeICQW8owRc5E69vrOJAKHypPstLbI\n" \ 59 | "FhfFcvwnQPYT/pOmnVHvPCvYd1ebjGU6NSU2t7WKY28HJ5OxYI2A25bUeo8tqxyI\n" \ 60 | "yW5+1mUfr13KFj8oRtygNeX56eXVlogMT8a3d2dIhCe2H7Bo26y/d7CQuKLJHDJd\n" \ 61 | "ArolQ4FCR7vY4Y8MDEZf7kYzawMUgtN+zY+vkNaOJH1AQrRqahfGlZfh8jjNp+20\n" \ 62 | "J0CT33KpuMZmYzc4ZCIwojvxuch7yPspOqsactIGEk72gtQjbz7Dk+XYtsDe3CMW\n" \ 63 | "1hMwt6CaDixVBgBwAc/qOR2A24j3pSC4W/0xJmmPLQphgzpHphNULB7j7UTKvGof\n" \ 64 | "KA5R2d4On3XNDgOVyvnFqSot/kGkoUeuDcL5OWYzSlvhhChZbH2UF3bkRYKtcCD9\n" \ 65 | "0m9jqNf6oDP6N8v3smWe2lBvP+Sn845dWDKXcCMu5/3EFZucJ48y7RetWIExKREa\n" \ 66 | "m9T8bJUox04FB6b9HbwZ4ui3uRGKLXASUoWNjDNKD/yZkuBjcNqllEdjB+dYxzFf\n" \ 67 | "BT02Vf6Dsuimrdfp5gJ0iHRc2jTbkNJtUQoj1iM=\n" \ 68 | "-----END CERTIFICATE-----\n"; 69 | 70 | // Not sure if WiFiClientSecure checks the validity date of the certificate. 71 | // Setting clock just to be sure... 72 | void setClock() 73 | { 74 | configTime(0, 0, "pool.ntp.org"); 75 | 76 | Serial.print(F("Waiting for NTP time sync: ")); 77 | time_t nowSecs = time(nullptr); 78 | 79 | while (nowSecs < 8 * 3600 * 2) 80 | { 81 | delay(500); 82 | Serial.print(F(".")); 83 | yield(); 84 | nowSecs = time(nullptr); 85 | } 86 | 87 | Serial.println(); 88 | struct tm timeinfo; 89 | gmtime_r(&nowSecs, &timeinfo); 90 | Serial.print(F("Current time: ")); 91 | Serial.print(asctime(&timeinfo)); 92 | } 93 | 94 | void setup() 95 | { 96 | Serial.begin(115200); 97 | 98 | while (!Serial); 99 | 100 | // Using this if Serial debugging is not necessary or not using Serial port 101 | //while (!Serial && (millis() < 3000)); 102 | 103 | Serial.print("\nStarting BasicHttpsClient on " + String(ARDUINO_BOARD)); 104 | Serial.println(" with " + String(SHIELD_TYPE)); 105 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 106 | 107 | // To be called before ETH.begin() 108 | WT32_ETH01_onEvent(); 109 | 110 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 111 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 112 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 113 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 114 | 115 | // Static IP, leave without this line to get IP via DHCP 116 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 117 | ETH.config(myIP, myGW, mySN, myDNS); 118 | 119 | WT32_ETH01_waitForConnect(); 120 | 121 | setClock(); 122 | } 123 | 124 | void loop() 125 | { 126 | if (WT32_ETH01_isConnected()) 127 | { 128 | WiFiClientSecure *client = new WiFiClientSecure; 129 | 130 | if (client) 131 | { 132 | client -> setCACert(rootCACertificate); 133 | 134 | { 135 | // Add a scoping block for HTTPClient https to make sure it is destroyed before WiFiClientSecure *client is 136 | HTTPClient https; 137 | 138 | Serial.print("[HTTPS] begin...\n"); 139 | 140 | if (https.begin(*client, "https://jigsaw.w3.org/HTTP/connection.html")) 141 | { 142 | // HTTPS 143 | Serial.print("[HTTPS] GET...\n"); 144 | // start connection and send HTTP header 145 | int httpCode = https.GET(); 146 | 147 | // httpCode will be negative on error 148 | if (httpCode > 0) 149 | { 150 | // HTTP header has been send and Server response header has been handled 151 | Serial.printf("[HTTPS] GET... code: %d\n", httpCode); 152 | 153 | // file found at server 154 | if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) 155 | { 156 | String payload = https.getString(); 157 | Serial.println(payload); 158 | } 159 | } 160 | else 161 | { 162 | Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str()); 163 | } 164 | 165 | https.end(); 166 | } 167 | else 168 | { 169 | Serial.printf("[HTTPS] Unable to connect\n"); 170 | } 171 | 172 | // End extra scoping block 173 | } 174 | 175 | delete client; 176 | } 177 | else 178 | { 179 | Serial.println("Unable to create client"); 180 | } 181 | 182 | Serial.println(); 183 | Serial.println("Waiting 10s before the next round..."); 184 | delay(10000); 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /examples/HTTPClient/StreamHttpClient/StreamHttpClient.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | StreamHttpClient.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 17 | 18 | #include 19 | #include 20 | 21 | // Select the IP address according to your local network 22 | IPAddress myIP(192, 168, 2, 232); 23 | IPAddress myGW(192, 168, 2, 1); 24 | IPAddress mySN(255, 255, 255, 0); 25 | 26 | // Google DNS Server IP 27 | IPAddress myDNS(8, 8, 8, 8); 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | 33 | while (!Serial); 34 | 35 | // Using this if Serial debugging is not necessary or not using Serial port 36 | //while (!Serial && (millis() < 3000)); 37 | 38 | Serial.print("\nStarting StreamHttpClient on " + String(ARDUINO_BOARD)); 39 | Serial.println(" with " + String(SHIELD_TYPE)); 40 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 41 | 42 | // To be called before ETH.begin() 43 | WT32_ETH01_onEvent(); 44 | 45 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 46 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 47 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 48 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 49 | 50 | // Static IP, leave without this line to get IP via DHCP 51 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 52 | ETH.config(myIP, myGW, mySN, myDNS); 53 | 54 | WT32_ETH01_waitForConnect(); 55 | } 56 | 57 | void loop() 58 | { 59 | if (WT32_ETH01_isConnected()) 60 | { 61 | HTTPClient http; 62 | 63 | Serial.print("[HTTP] begin...\n"); 64 | 65 | // configure server and url 66 | http.begin("http://192.168.2.112/test.html"); 67 | //http.begin("192.168.2.112", 80, "/test.html"); 68 | 69 | Serial.print("[HTTP] GET...\n"); 70 | // start connection and send HTTP header 71 | int httpCode = http.GET(); 72 | 73 | if (httpCode > 0) 74 | { 75 | // HTTP header has been send and Server response header has been handled 76 | Serial.printf("[HTTP] GET... code: %d\n", httpCode); 77 | 78 | // file found at server 79 | if (httpCode == HTTP_CODE_OK) 80 | { 81 | // get length of document (is -1 when Server sends no Content-Length header) 82 | int len = http.getSize(); 83 | 84 | // create buffer for read 85 | uint8_t buff[128] = { 0 }; 86 | 87 | // get tcp stream 88 | WiFiClient * stream = http.getStreamPtr(); 89 | 90 | // read all data from server 91 | while (http.connected() && (len > 0 || len == -1)) 92 | { 93 | // get available data size 94 | size_t size = stream->available(); 95 | 96 | if (size) 97 | { 98 | // read up to 128 byte 99 | int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size)); 100 | 101 | // write it to Serial 102 | Serial.write(buff, c); 103 | 104 | if (len > 0) 105 | { 106 | len -= c; 107 | } 108 | } 109 | 110 | delay(1); 111 | } 112 | 113 | Serial.println(); 114 | Serial.print("[HTTP] connection closed or file end.\n"); 115 | } 116 | } 117 | else 118 | { 119 | Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); 120 | } 121 | 122 | http.end(); 123 | } 124 | 125 | delay(10000); 126 | } 127 | -------------------------------------------------------------------------------- /examples/HTTPClient/node_test_server/getPostPutDelete.js: -------------------------------------------------------------------------------- 1 | /* 2 | Express.js GET/POST example 3 | Shows how handle GET, POST, PUT, DELETE 4 | in Express.js 4.0 5 | 6 | created 14 Feb 2016 7 | by Tom Igoe 8 | */ 9 | 10 | var express = require('express'); // include express.js 11 | var app = express(); // a local instance of it 12 | var bodyParser = require('body-parser'); // include body-parser 13 | var WebSocketServer = require('ws').Server // include Web Socket server 14 | 15 | // you need a body parser: 16 | app.use(bodyParser.urlencoded({extended: false})); // for application/x-www-form-urlencoded 17 | 18 | // this runs after the server successfully starts: 19 | function serverStart() { 20 | var port = server.address().port; 21 | console.log('Server listening on port '+ port); 22 | } 23 | 24 | app.get('/chunked', function(request, response) { 25 | response.write('\n'); 26 | response.write(' `:;;;,` .:;;:. \n'); 27 | response.write(' .;;;;;;;;;;;` :;;;;;;;;;;: TM \n'); 28 | response.write(' `;;;;;;;;;;;;;;;` :;;;;;;;;;;;;;;; \n'); 29 | response.write(' :;;;;;;;;;;;;;;;;;; `;;;;;;;;;;;;;;;;;; \n'); 30 | response.write(' ;;;;;;;;;;;;;;;;;;;;; .;;;;;;;;;;;;;;;;;;;; \n'); 31 | response.write(' ;;;;;;;;:` `;;;;;;;;; ,;;;;;;;;.` .;;;;;;;; \n'); 32 | response.write(' .;;;;;;, :;;;;;;; .;;;;;;; ;;;;;;; \n'); 33 | response.write(' ;;;;;; ;;;;;;; ;;;;;;, ;;;;;;. \n'); 34 | response.write(' ,;;;;; ;;;;;;.;;;;;;` ;;;;;; \n'); 35 | response.write(' ;;;;;. ;;;;;;;;;;;` ``` ;;;;;`\n'); 36 | response.write(' ;;;;; ;;;;;;;;;, ;;; .;;;;;\n'); 37 | response.write('`;;;;: `;;;;;;;; ;;; ;;;;;\n'); 38 | response.write(',;;;;` `,,,,,,,, ;;;;;;; .,,;;;,,, ;;;;;\n'); 39 | response.write(':;;;;` .;;;;;;;; ;;;;;, :;;;;;;;; ;;;;;\n'); 40 | response.write(':;;;;` .;;;;;;;; `;;;;;; :;;;;;;;; ;;;;;\n'); 41 | response.write('.;;;;. ;;;;;;;. ;;; ;;;;;\n'); 42 | response.write(' ;;;;; ;;;;;;;;; ;;; ;;;;;\n'); 43 | response.write(' ;;;;; .;;;;;;;;;; ;;; ;;;;;,\n'); 44 | response.write(' ;;;;;; `;;;;;;;;;;;; ;;;;; \n'); 45 | response.write(' `;;;;;, .;;;;;; ;;;;;;; ;;;;;; \n'); 46 | response.write(' ;;;;;;: :;;;;;;. ;;;;;;; ;;;;;; \n'); 47 | response.write(' ;;;;;;;` .;;;;;;;, ;;;;;;;; ;;;;;;;: \n'); 48 | response.write(' ;;;;;;;;;:,:;;;;;;;;;: ;;;;;;;;;;:,;;;;;;;;;; \n'); 49 | response.write(' `;;;;;;;;;;;;;;;;;;;. ;;;;;;;;;;;;;;;;;;;; \n'); 50 | response.write(' ;;;;;;;;;;;;;;;;; :;;;;;;;;;;;;;;;;: \n'); 51 | response.write(' ,;;;;;;;;;;;;;, ;;;;;;;;;;;;;; \n'); 52 | response.write(' .;;;;;;;;;` ,;;;;;;;;: \n'); 53 | response.write(' \n'); 54 | response.write(' \n'); 55 | response.write(' \n'); 56 | response.write(' \n'); 57 | response.write(' ;;; ;;;;;` ;;;;: .;; ;; ,;;;;;, ;;. `;, ;;;; \n'); 58 | response.write(' ;;; ;;:;;; ;;;;;; .;; ;; ,;;;;;: ;;; `;, ;;;:;; \n'); 59 | response.write(' ,;:; ;; ;; ;; ;; .;; ;; ,;, ;;;,`;, ;; ;; \n'); 60 | response.write(' ;; ;: ;; ;; ;; ;; .;; ;; ,;, ;;;;`;, ;; ;;. \n'); 61 | response.write(' ;: ;; ;;;;;: ;; ;; .;; ;; ,;, ;;`;;;, ;; ;;` \n'); 62 | response.write(' ,;;;;; ;;`;; ;; ;; .;; ;; ,;, ;; ;;;, ;; ;; \n'); 63 | response.write(' ;; ,;, ;; .;; ;;;;;: ;;;;;: ,;;;;;: ;; ;;, ;;;;;; \n'); 64 | response.write(' ;; ;; ;; ;;` ;;;;. `;;;: ,;;;;;, ;; ;;, ;;;; \n'); 65 | response.write('\n'); 66 | response.end(); 67 | }); 68 | 69 | // this is the POST handler: 70 | app.all('/*', function (request, response) { 71 | console.log('Got a ' + request.method + ' request'); 72 | // the parameters of a GET request are passed in 73 | // request.body. Pass that to formatResponse() 74 | // for formatting: 75 | console.log(request.headers); 76 | if (request.method == 'GET') { 77 | console.log(request.query); 78 | } else { 79 | console.log(request.body); 80 | } 81 | 82 | // send the response: 83 | response.send('OK'); 84 | response.end(); 85 | }); 86 | 87 | // start the server: 88 | var server = app.listen(8080, serverStart); 89 | 90 | // create a WebSocket server and attach it to the server 91 | var wss = new WebSocketServer({server: server}); 92 | 93 | wss.on('connection', function connection(ws) { 94 | // new connection, add message listener 95 | ws.on('message', function incoming(message) { 96 | // received a message 97 | console.log('received: %s', message); 98 | 99 | // echo it back 100 | ws.send(message); 101 | }); 102 | }); 103 | -------------------------------------------------------------------------------- /examples/HTTPClient/node_test_server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node_test_server", 3 | "version": "0.0.1", 4 | "author": { 5 | "name": "Tom Igoe" 6 | }, 7 | "dependencies": { 8 | "body-parser": ">=1.11.0", 9 | "express": ">=4.0.0", 10 | "multer": "*", 11 | "ws": ">=5.2.3" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /examples/HelloServer/HelloServer.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | HelloServer.ino - Dead simple web-server for Ethernet shields 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 17 | 18 | #include 19 | 20 | WebServer server(80); 21 | 22 | // Select the IP address according to your local network 23 | IPAddress myIP(192, 168, 2, 232); 24 | IPAddress myGW(192, 168, 2, 1); 25 | IPAddress mySN(255, 255, 255, 0); 26 | 27 | // Google DNS Server IP 28 | IPAddress myDNS(8, 8, 8, 8); 29 | 30 | void handleRoot() 31 | { 32 | String html = F("Hello from HelloServer running on "); 33 | 34 | html += String(BOARD_NAME); 35 | 36 | server.send(200, F("text/plain"), html); 37 | } 38 | 39 | void handleNotFound() 40 | { 41 | String message = F("File Not Found\n\n"); 42 | 43 | message += F("URI: "); 44 | message += server.uri(); 45 | message += F("\nMethod: "); 46 | message += (server.method() == HTTP_GET) ? F("GET") : F("POST"); 47 | message += F("\nArguments: "); 48 | message += server.args(); 49 | message += F("\n"); 50 | 51 | for (uint8_t i = 0; i < server.args(); i++) 52 | { 53 | message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; 54 | } 55 | 56 | server.send(404, F("text/plain"), message); 57 | } 58 | 59 | void setup() 60 | { 61 | // Open serial communications and wait for port to open: 62 | Serial.begin(115200); 63 | 64 | while (!Serial); 65 | 66 | // Using this if Serial debugging is not necessary or not using Serial port 67 | //while (!Serial && (millis() < 3000)); 68 | 69 | Serial.print("\nStarting HelloServer on " + String(ARDUINO_BOARD)); 70 | Serial.println(" with " + String(SHIELD_TYPE)); 71 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 72 | 73 | // To be called before ETH.begin() 74 | WT32_ETH01_onEvent(); 75 | 76 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 77 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 78 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 79 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 80 | 81 | // Static IP, leave without this line to get IP via DHCP 82 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 83 | ETH.config(myIP, myGW, mySN, myDNS); 84 | 85 | WT32_ETH01_waitForConnect(); 86 | 87 | server.on(F("/"), handleRoot); 88 | 89 | server.on(F("/inline"), []() 90 | { 91 | server.send(200, F("text/plain"), F("This works as well")); 92 | }); 93 | 94 | server.onNotFound(handleNotFound); 95 | 96 | server.begin(); 97 | 98 | Serial.print(F("HTTP EthernetWebServer is @ IP : ")); 99 | Serial.println(ETH.localIP()); 100 | } 101 | 102 | void loop() 103 | { 104 | server.handleClient(); 105 | } 106 | -------------------------------------------------------------------------------- /examples/HelloServer2/HelloServer2.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | HelloServer2.h - Dead simple web-server for Ethernet shields 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 17 | 18 | #include 19 | 20 | WebServer server(80); 21 | 22 | // Select the IP address according to your local network 23 | IPAddress myIP(192, 168, 2, 232); 24 | IPAddress myGW(192, 168, 2, 1); 25 | IPAddress mySN(255, 255, 255, 0); 26 | 27 | // Google DNS Server IP 28 | IPAddress myDNS(8, 8, 8, 8); 29 | 30 | void handleRoot() 31 | { 32 | String html = F("Hello from HelloServer2 running on "); 33 | 34 | html += String(BOARD_NAME); 35 | 36 | server.send(200, F("text/plain"), html); 37 | } 38 | 39 | void handleNotFound() 40 | { 41 | String message = F("File Not Found\n\n"); 42 | 43 | message += F("URI: "); 44 | message += server.uri(); 45 | message += F("\nMethod: "); 46 | message += (server.method() == HTTP_GET) ? F("GET") : F("POST"); 47 | message += F("\nArguments: "); 48 | message += server.args(); 49 | message += F("\n"); 50 | 51 | for (uint8_t i = 0; i < server.args(); i++) 52 | { 53 | message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; 54 | } 55 | 56 | server.send(404, F("text/plain"), message); 57 | } 58 | 59 | void setup() 60 | { 61 | Serial.begin(115200); 62 | 63 | while (!Serial); 64 | 65 | // Using this if Serial debugging is not necessary or not using Serial port 66 | //while (!Serial && (millis() < 3000)); 67 | 68 | Serial.print("\nStarting HelloServer2 on " + String(ARDUINO_BOARD)); 69 | Serial.println(" with " + String(SHIELD_TYPE)); 70 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 71 | 72 | // To be called before ETH.begin() 73 | WT32_ETH01_onEvent(); 74 | 75 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 76 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 77 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 78 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 79 | 80 | // Static IP, leave without this line to get IP via DHCP 81 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 82 | ETH.config(myIP, myGW, mySN, myDNS); 83 | 84 | WT32_ETH01_waitForConnect(); 85 | 86 | server.on(F("/"), handleRoot); 87 | 88 | server.on(F("/inline"), []() 89 | { 90 | server.send(200, F("text/plain"), F("This works as well")); 91 | }); 92 | 93 | server.on(F("/gif"), []() 94 | { 95 | static const uint8_t gif[] PROGMEM = 96 | { 97 | 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x10, 0x00, 0x10, 0x00, 0x80, 0x01, 98 | 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x00, 99 | 0x10, 0x00, 0x10, 0x00, 0x00, 0x02, 0x19, 0x8c, 0x8f, 0xa9, 0xcb, 0x9d, 100 | 0x00, 0x5f, 0x74, 0xb4, 0x56, 0xb0, 0xb0, 0xd2, 0xf2, 0x35, 0x1e, 0x4c, 101 | 0x0c, 0x24, 0x5a, 0xe6, 0x89, 0xa6, 0x4d, 0x01, 0x00, 0x3b 102 | }; 103 | 104 | char gif_colored[sizeof(gif)]; 105 | 106 | memcpy_P(gif_colored, gif, sizeof(gif)); 107 | 108 | // Set the background to a random set of colors 109 | gif_colored[16] = millis() % 256; 110 | gif_colored[17] = millis() % 256; 111 | gif_colored[18] = millis() % 256; 112 | 113 | server.send_P(200, "image/gif", gif_colored, sizeof(gif_colored)); 114 | }); 115 | 116 | server.onNotFound(handleNotFound); 117 | 118 | server.begin(); 119 | 120 | Serial.print(F("HTTP HelloServer2 started @ IP : ")); 121 | Serial.println(ETH.localIP()); 122 | } 123 | 124 | void loop() 125 | { 126 | server.handleClient(); 127 | } 128 | -------------------------------------------------------------------------------- /examples/HttpBasicAuth/HttpBasicAuth.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | HTTPBasicAuth.h - Dead simple web-server for Ethernet shields 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 17 | 18 | #include 19 | 20 | WebServer server(80); 21 | 22 | // Select the IP address according to your local network 23 | IPAddress myIP(192, 168, 2, 232); 24 | IPAddress myGW(192, 168, 2, 1); 25 | IPAddress mySN(255, 255, 255, 0); 26 | 27 | // Google DNS Server IP 28 | IPAddress myDNS(8, 8, 8, 8); 29 | 30 | const char* www_username = "admin"; 31 | const char* www_password = "wt32_eth01"; 32 | 33 | void setup() 34 | { 35 | Serial.begin(115200); 36 | 37 | while (!Serial); 38 | 39 | // Using this if Serial debugging is not necessary or not using Serial port 40 | //while (!Serial && (millis() < 3000)); 41 | 42 | Serial.print("\nStarting HTTPBasicAuth on " + String(ARDUINO_BOARD)); 43 | Serial.println(" with " + String(SHIELD_TYPE)); 44 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 45 | 46 | // To be called before ETH.begin() 47 | WT32_ETH01_onEvent(); 48 | 49 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 50 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 51 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 52 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 53 | 54 | // Static IP, leave without this line to get IP via DHCP 55 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 56 | ETH.config(myIP, myGW, mySN, myDNS); 57 | 58 | WT32_ETH01_waitForConnect(); 59 | 60 | server.on(F("/"), []() 61 | { 62 | if (!server.authenticate(www_username, www_password)) 63 | { 64 | return server.requestAuthentication(); 65 | } 66 | 67 | server.send(200, F("text/plain"), F("Login OK")); 68 | }); 69 | 70 | server.begin(); 71 | 72 | Serial.print(F("HTTP HTTPBasicAuth started @ IP : ")); 73 | Serial.println(ETH.localIP()); 74 | 75 | Serial.print(F("Open http://")); 76 | Serial.print(ETH.localIP()); 77 | Serial.println(F("/ in your browser to see it working")); 78 | Serial.print(F("Using username : ")); 79 | Serial.print(www_username); 80 | Serial.print(F(" and password : ")); 81 | Serial.println(www_password); 82 | } 83 | 84 | void loop() 85 | { 86 | server.handleClient(); 87 | } 88 | -------------------------------------------------------------------------------- /examples/MQTTClient_Auth/MQTTClient_Auth.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | MQTTClient_Auth.ino - Dead simple MQTT Client for Ethernet shields 3 | 4 | MQTTClient_Auth 5 | *****************************************************************************************************************************/ 6 | 7 | /* 8 | Basic MQTT example (without SSL!) with Authentication 9 | This sketch demonstrates the basic capabilities of the library. 10 | It connects to an MQTT server then: 11 | - providing username and password 12 | - publishes "hello world" to the topic "outTopic" 13 | - subscribes to the topic "inTopic", printing out any messages 14 | it receives. NB - it assumes the received payloads are strings not binary 15 | It will reconnect to the server if the connection is lost using a blocking 16 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 17 | achieve the same result without blocking the main loop. 18 | */ 19 | 20 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 21 | 22 | // Debug Level from 0 to 4 23 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 24 | 25 | #include 26 | 27 | WebServer server(80); 28 | 29 | // Select the IP address according to your local network 30 | IPAddress myIP(192, 168, 2, 232); 31 | IPAddress myGW(192, 168, 2, 1); 32 | IPAddress mySN(255, 255, 255, 0); 33 | 34 | // Google DNS Server IP 35 | IPAddress myDNS(8, 8, 8, 8); 36 | 37 | #include 38 | 39 | // Update these with values suitable for your network. 40 | //const char* mqttServer = "broker.example"; // Broker address 41 | const char* mqttServer = "broker.emqx.io"; // Broker address 42 | //const char* mqttServer = "broker.shiftr.io"; // Broker address 43 | 44 | const char *ID = "MQTTClient_SSL-Client"; // Name of our device, must be unique 45 | const char *TOPIC = "MQTT_Pub"; // Topic to subcribe to 46 | const char *subTopic = "MQTT_Sub"; // Topic to subcribe to 47 | 48 | //IPAddress mqttServer(172, 16, 0, 2); 49 | 50 | void callback(char* topic, byte* payload, unsigned int length) 51 | { 52 | Serial.print("Message arrived ["); 53 | Serial.print(topic); 54 | Serial.print("] "); 55 | 56 | for (unsigned int i = 0; i < length; i++) 57 | { 58 | Serial.print((char)payload[i]); 59 | } 60 | 61 | Serial.println(); 62 | } 63 | 64 | WiFiClient ethClient; 65 | PubSubClient client(mqttServer, 1883, callback, ethClient); 66 | 67 | void reconnect() 68 | { 69 | // Loop until we're reconnected 70 | while (!client.connected()) 71 | { 72 | Serial.print("Attempting MQTT connection to "); 73 | Serial.print(mqttServer); 74 | 75 | // Attempt to connect 76 | if (client.connect("arduino", "try", "try")) 77 | { 78 | Serial.println("...connected"); 79 | 80 | // Once connected, publish an announcement... 81 | String data = "Hello from MQTTClient_SSL on " + String(BOARD_NAME); 82 | 83 | client.publish(TOPIC, data.c_str()); 84 | 85 | //Serial.println("Published connection message successfully!"); 86 | //Serial.print("Subcribed to: "); 87 | //Serial.println(subTopic); 88 | 89 | // This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9 90 | //ethClientSSL.flush(); 91 | // ... and resubscribe 92 | client.subscribe(subTopic); 93 | // for loopback testing 94 | client.subscribe(TOPIC); 95 | // This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9 96 | //ethClientSSL.flush(); 97 | } 98 | else 99 | { 100 | Serial.print("...failed, rc="); 101 | Serial.print(client.state()); 102 | Serial.println(" try again in 5 seconds"); 103 | 104 | // Wait 5 seconds before retrying 105 | delay(5000); 106 | } 107 | } 108 | } 109 | 110 | void setup() 111 | { 112 | // Open serial communications and wait for port to open: 113 | Serial.begin(115200); 114 | 115 | while (!Serial); 116 | 117 | // Using this if Serial debugging is not necessary or not using Serial port 118 | //while (!Serial && (millis() < 3000)); 119 | 120 | Serial.print("\nStarting MQTTClient_Auth on " + String(ARDUINO_BOARD)); 121 | Serial.println(" with " + String(SHIELD_TYPE)); 122 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 123 | 124 | // To be called before ETH.begin() 125 | WT32_ETH01_onEvent(); 126 | 127 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 128 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 129 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 130 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 131 | 132 | // Static IP, leave without this line to get IP via DHCP 133 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 134 | ETH.config(myIP, myGW, mySN, myDNS); 135 | 136 | WT32_ETH01_waitForConnect(); 137 | 138 | // Note - the default maximum packet size is 128 bytes. If the 139 | // combined length of clientId, username and password exceed this use the 140 | // following to increase the buffer size: 141 | // client.setBufferSize(255); 142 | } 143 | 144 | #define MQTT_PUBLISH_INTERVAL_MS 5000L 145 | 146 | String data = "Hello from MQTTClient_Auth on " + String(BOARD_NAME) + " with " + String(SHIELD_TYPE); 147 | const char *pubData = data.c_str(); 148 | 149 | unsigned long lastMsg = 0; 150 | 151 | void loop() 152 | { 153 | static unsigned long now; 154 | 155 | if (!client.connected()) 156 | { 157 | reconnect(); 158 | } 159 | 160 | // Sending Data 161 | now = millis(); 162 | 163 | if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS) 164 | { 165 | lastMsg = now; 166 | 167 | if (!client.publish(TOPIC, pubData)) 168 | { 169 | Serial.println("Message failed to send."); 170 | } 171 | 172 | Serial.print("Message Send : " + String(TOPIC) + " => "); 173 | Serial.println(data); 174 | } 175 | 176 | client.loop(); 177 | } 178 | -------------------------------------------------------------------------------- /examples/MQTTClient_Basic/MQTTClient_Basic.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | MQTTClient_Basic.ino - Dead simple MQTT Client for Ethernet shields 3 | 4 | MQTTClient_Auth 5 | *****************************************************************************************************************************/ 6 | 7 | /* 8 | Basic MQTT example (without SSL!) with Authentication 9 | This sketch demonstrates the basic capabilities of the library. 10 | It connects to an MQTT server then: 11 | - providing username and password 12 | - publishes "hello world" to the topic "outTopic" 13 | - subscribes to the topic "inTopic", printing out any messages 14 | it receives. NB - it assumes the received payloads are strings not binary 15 | 16 | It will reconnect to the server if the connection is lost using a blocking 17 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 18 | achieve the same result without blocking the main loop. 19 | */ 20 | 21 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 22 | 23 | // Debug Level from 0 to 4 24 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 25 | 26 | #include 27 | 28 | WebServer server(80); 29 | 30 | // Select the IP address according to your local network 31 | IPAddress myIP(192, 168, 2, 232); 32 | IPAddress myGW(192, 168, 2, 1); 33 | IPAddress mySN(255, 255, 255, 0); 34 | 35 | // Google DNS Server IP 36 | IPAddress myDNS(8, 8, 8, 8); 37 | 38 | #include 39 | 40 | // Update these with values suitable for your network. 41 | //const char* mqttServer = "broker.example"; // Broker address 42 | const char* mqttServer = "broker.emqx.io"; // Broker address 43 | //const char* mqttServer = "broker.shiftr.io"; // Broker address 44 | 45 | const char *ID = "MQTTClient_SSL-Client"; // Name of our device, must be unique 46 | const char *TOPIC = "MQTT_Pub"; // Topic to subcribe to 47 | const char *subTopic = "MQTT_Sub"; // Topic to subcribe to 48 | 49 | //IPAddress mqttServer(172, 16, 0, 2); 50 | 51 | void callback(char* topic, byte* payload, unsigned int length) 52 | { 53 | Serial.print("Message arrived ["); 54 | Serial.print(topic); 55 | Serial.print("] "); 56 | 57 | for (unsigned int i = 0; i < length; i++) 58 | { 59 | Serial.print((char)payload[i]); 60 | } 61 | 62 | Serial.println(); 63 | } 64 | 65 | WiFiClient ethClient; 66 | PubSubClient client(mqttServer, 1883, callback, ethClient); 67 | 68 | void reconnect() 69 | { 70 | // Loop until we're reconnected 71 | while (!client.connected()) 72 | { 73 | Serial.print("Attempting MQTT connection to "); 74 | Serial.print(mqttServer); 75 | 76 | // Attempt to connect 77 | if (client.connect(ID, "try", "try")) 78 | { 79 | Serial.println("...connected"); 80 | 81 | // Once connected, publish an announcement... 82 | String data = "Hello from MQTTClient_SSL on " + String(BOARD_NAME); 83 | 84 | client.publish(TOPIC, data.c_str()); 85 | 86 | //Serial.println("Published connection message successfully!"); 87 | //Serial.print("Subcribed to: "); 88 | //Serial.println(subTopic); 89 | 90 | // This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9 91 | //ethClientSSL.flush(); 92 | // ... and resubscribe 93 | client.subscribe(subTopic); 94 | // for loopback testing 95 | client.subscribe(TOPIC); 96 | // This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9 97 | //ethClientSSL.flush(); 98 | } 99 | else 100 | { 101 | Serial.print("...failed, rc="); 102 | Serial.print(client.state()); 103 | Serial.println(" try again in 5 seconds"); 104 | 105 | // Wait 5 seconds before retrying 106 | delay(5000); 107 | } 108 | } 109 | } 110 | 111 | void setup() 112 | { 113 | // Open serial communications and wait for port to open: 114 | Serial.begin(115200); 115 | 116 | while (!Serial); 117 | 118 | // Using this if Serial debugging is not necessary or not using Serial port 119 | //while (!Serial && (millis() < 3000)); 120 | 121 | Serial.print("\nStarting MQTTClient_Basic on " + String(ARDUINO_BOARD)); 122 | Serial.println(" with " + String(SHIELD_TYPE)); 123 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 124 | 125 | // To be called before ETH.begin() 126 | WT32_ETH01_onEvent(); 127 | 128 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 129 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 130 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 131 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 132 | 133 | // Static IP, leave without this line to get IP via DHCP 134 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 135 | ETH.config(myIP, myGW, mySN, myDNS); 136 | 137 | WT32_ETH01_waitForConnect(); 138 | 139 | client.setServer(mqttServer, 1883); 140 | client.setCallback(callback); 141 | 142 | // Allow the hardware to sort itself out 143 | delay(1500); 144 | } 145 | 146 | #define MQTT_PUBLISH_INTERVAL_MS 5000L 147 | 148 | String data = "Hello from MQTTClient_Basic on " + String(BOARD_NAME) + " with " + String(SHIELD_TYPE); 149 | const char *pubData = data.c_str(); 150 | 151 | unsigned long lastMsg = 0; 152 | 153 | void loop() 154 | { 155 | static unsigned long now; 156 | 157 | if (!client.connected()) 158 | { 159 | reconnect(); 160 | } 161 | 162 | // Sending Data 163 | now = millis(); 164 | 165 | if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS) 166 | { 167 | lastMsg = now; 168 | 169 | if (!client.publish(TOPIC, pubData)) 170 | { 171 | Serial.println("Message failed to send."); 172 | } 173 | 174 | Serial.print("Message Send : " + String(TOPIC) + " => "); 175 | Serial.println(data); 176 | } 177 | 178 | client.loop(); 179 | } 180 | -------------------------------------------------------------------------------- /examples/MQTT_And_OTA_Ethernet/MQTT_And_OTA_Ethernet.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | MQTT_And_OTA_Ethernet.ino 3 | - Dead simple MQTT Client for Ethernet shields 4 | - Allows for new sketch compiled bin to be uploaded over HTTP using AsyncElegantOTA 5 | 6 | Based on MQTTClient_Auth 7 | *****************************************************************************************************************************/ 8 | 9 | /* 10 | Basic MQTT example (without SSL!) with Authentication 11 | This sketch demonstrates the basic capabilities of the library. 12 | It connects to an MQTT server then: 13 | - providing username and password 14 | - publishes "hello world" to the topic "outTopic" 15 | - subscribes to the topic "inTopic", printing out any messages 16 | it receives. NB - it assumes the received payloads are strings not binary 17 | It will reconnect to the server if the connection is lost using a blocking 18 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 19 | achieve the same result without blocking the main loop. 20 | 21 | To use OTA: 22 | - Take note of what IP the board is on, you should be able to see this both in the serial monitor and in the MQTT messages when the board first starts. 23 | - In the Arduino IDE, go to Sketch > Export compiled binary 24 | - You should now see a build folder next to the MQTT_And_OTA_Ethernet.ino file 25 | - Go into build\esp32.esp32.esp32 folder 26 | - The file you will be uploading to do an OTA update is MQTT_And_OTA_Ethernet.ino.bin in that folder 27 | - Go to http://192.168.X.X/update with a browser (whatever your board IP is that you noted earlier.) 28 | - Click "Choose file" and browse to the MQTT_And_OTA_Ethernet.ino.bin that you made earlier when you clicked Export compiled binary 29 | */ 30 | 31 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 32 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 // Debug Level from 0 to 4 33 | 34 | #include // https://github.com/khoih-prog/WebServer_WT32_ETH01/ 35 | #include // https://github.com/me-no-dev/AsyncTCP 36 | #include // https://github.com/me-no-dev/ESPAsyncWebServer 37 | #include // https://github.com/ayushsharma82/AsyncElegantOTA 38 | 39 | // Libraries also needed: https://github.com/knolleary/pubsubclient 40 | 41 | AsyncWebServer server(80); 42 | 43 | // Set according to your local network if you need static IP 44 | // IPAddress myIP(192, 168, 1, 232); 45 | // IPAddress myGW(192, 168, 1, 1); 46 | // IPAddress mySN(255, 255, 255, 0); 47 | // IPAddress myDNS(8, 8, 8, 8); 48 | 49 | #include 50 | 51 | // MQTT Settings 52 | const char *mqttServer = "192.168.1.25"; // Broker address 53 | const char *mqttBrokerUser = "YOUR_MQTT_USERNAME"; // Username to connect to your MQTT broker 54 | const char *mqttBrokerPass = "YOUR_MQTT_PASSWORD"; // Password to connect to your MQTT broker 55 | const char *ID = "MQTTClient_SSL-Client"; // Name of our device, must be unique 56 | const char *TOPIC = "topics/test/esp32"; // Topic to publish to 57 | const char *subTopic = "topics/MQTT_Sub"; // Topic to subcribe to 58 | 59 | WiFiClient ethClient; 60 | 61 | void setup() 62 | { 63 | Serial.begin(115200); 64 | 65 | while (!Serial); 66 | 67 | // Using this if Serial debugging is not necessary or not using Serial port 68 | //while (!Serial && (millis() < 3000)); 69 | 70 | Serial.print("\nStarting MQTT_And_OTA_Ethernet on " + String(ARDUINO_BOARD)); 71 | Serial.println(" with " + String(SHIELD_TYPE)); 72 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 73 | 74 | // To be called before ETH.begin() 75 | WT32_ETH01_onEvent(); 76 | 77 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 78 | 79 | // Static IP, leave without this line to get IP via DHCP 80 | // ETH.config(myIP, myGW, mySN, myDNS); 81 | 82 | WT32_ETH01_waitForConnect(); 83 | 84 | // Note - the default maximum packet size is 128 bytes. If the 85 | // combined length of clientId, username and password exceed this use the 86 | // following to increase the buffer size: 87 | // client.setBufferSize(255); 88 | 89 | server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) 90 | { 91 | request->send(200, "text/plain", "Hi! I am ESP32."); 92 | }); 93 | 94 | AsyncElegantOTA.begin(&server); // Start ElegantOTA 95 | server.begin(); 96 | 97 | Serial.println(); 98 | Serial.println("HTTP server started with MAC: " + ETH.macAddress() + ", at IPv4: " + ETH.localIP().toString()); 99 | Serial.println(); 100 | } 101 | 102 | void callback(char* topic, byte* payload, unsigned int length) 103 | { 104 | Serial.print("Message arrived ["); 105 | Serial.print(topic); 106 | Serial.print("] "); 107 | 108 | for (unsigned int i = 0; i < length; i++) 109 | { 110 | Serial.print((char)payload[i]); 111 | } 112 | 113 | Serial.println(); 114 | } 115 | 116 | PubSubClient client(mqttServer, 1883, callback, ethClient); 117 | 118 | void reconnect() 119 | { 120 | // Loop until we're reconnected 121 | while (!client.connected()) 122 | { 123 | Serial.print("Attempting MQTT connection to "); 124 | Serial.print(mqttServer); 125 | 126 | // Attempt to connect 127 | if (client.connect("arduino", mqttBrokerUser, mqttBrokerPass)) 128 | { 129 | Serial.println("...connected"); 130 | 131 | // Once connected, publish an announcement... 132 | String data = "Hello from MQTTClient_SSL on " + String(BOARD_NAME) + ", at IPv4: " + ETH.localIP().toString(); 133 | 134 | client.publish(TOPIC, data.c_str()); 135 | 136 | //Serial.println("Published connection message successfully!"); 137 | //Serial.print("Subcribed to: "); 138 | //Serial.println(subTopic); 139 | 140 | // ... and resubscribe 141 | client.subscribe(subTopic); 142 | // for loopback testing 143 | client.subscribe(TOPIC); 144 | } 145 | else 146 | { 147 | Serial.print("...failed, rc="); 148 | Serial.print(client.state()); 149 | Serial.println(" try again in 5 seconds"); 150 | 151 | // Wait 5 seconds before retrying 152 | delay(5000); 153 | } 154 | } 155 | } 156 | 157 | #define MQTT_PUBLISH_INTERVAL_MS 5000L 158 | 159 | unsigned long lastMsg = 0; 160 | 161 | void loop() 162 | { 163 | String data = "Hello from v00 MQTT_And_OTA_Ethernet on: " + String(BOARD_NAME) + " with " + String(SHIELD_TYPE); 164 | const char *pubData = data.c_str(); 165 | 166 | static unsigned long now; 167 | 168 | if (!client.connected()) 169 | { 170 | reconnect(); 171 | } 172 | 173 | // Sending Data 174 | now = millis(); 175 | 176 | if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS) 177 | { 178 | lastMsg = now; 179 | 180 | if (!client.publish(TOPIC, pubData)) 181 | { 182 | Serial.println("Message failed to send."); 183 | } 184 | 185 | Serial.print("Message Send : " + String(TOPIC) + " => "); 186 | Serial.println(data); 187 | } 188 | 189 | client.loop(); 190 | } 191 | -------------------------------------------------------------------------------- /examples/MQTT_ThingStream/MQTT_ThingStream.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | MQTT_ThingStream.ino - Dead simple MQTT Client for Ethernet shields 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | /* 13 | Basic MQTT example (without SSL!) 14 | This sketch demonstrates the basic capabilities of the library. 15 | It connects to an MQTT server then: 16 | - publishes {Hello from MQTTClient_SSL on NUCLEO_F767ZI} to the topic [STM32_Pub] 17 | - subscribes to the topic [STM32_Sub], printing out any messages 18 | it receives. NB - it assumes the received payloads are strings not binary 19 | It will reconnect to the server if the connection is lost using a blocking 20 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 21 | achieve the same result without blocking the main loop. 22 | 23 | You will need to populate "certificates.h" with your trust anchors 24 | (see https://github.com/OPEnSLab-OSU/SSLClient/blob/master/TrustAnchors.md) 25 | and my_cert/my_key with your certificate/private key pair 26 | (see https://github.com/OPEnSLab-OSU/SSLClient#mtls). 27 | */ 28 | 29 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 30 | 31 | // Debug Level from 0 to 4 32 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 33 | 34 | #include 35 | 36 | WebServer server(80); 37 | 38 | // Select the IP address according to your local network 39 | IPAddress myIP(192, 168, 2, 232); 40 | IPAddress myGW(192, 168, 2, 1); 41 | IPAddress mySN(255, 255, 255, 0); 42 | 43 | // Google DNS Server IP 44 | IPAddress myDNS(8, 8, 8, 8); 45 | 46 | #include 47 | 48 | const char my_cert[] = "FIXME"; 49 | const char my_key[] = "FIXME"; 50 | 51 | #define USING_THINGSTREAM_IO true 52 | 53 | #if USING_THINGSTREAM_IO 54 | 55 | const char *MQTT_PREFIX_TOPIC = "esp32-sniffer/"; 56 | const char *MQTT_ANNOUNCE_TOPIC = "/status"; 57 | const char *MQTT_CONTROL_TOPIC = "/control"; 58 | const char *MQTT_BLE_TOPIC = "/ble"; 59 | 60 | 61 | // GOT FROM ThingsStream! 62 | const char *MQTT_SERVER = "mqtt.thingstream.io"; 63 | const char *MQTT_USER = "MQTT_USER"; 64 | const char *MQTT_PASS = "MQTT_PASS"; 65 | const char *MQTT_CLIENT_ID = "MQTT_CLIENT_ID"; 66 | 67 | String topic = MQTT_PREFIX_TOPIC + String("12345678") + MQTT_BLE_TOPIC; 68 | String subTopic = MQTT_PREFIX_TOPIC + String("12345678") + MQTT_BLE_TOPIC; 69 | 70 | #else 71 | 72 | const char* MQTT_SERVER = "broker.emqx.io"; // Broker address 73 | 74 | const char* ID = "MQTTClient_SSL-Client"; // Name of our device, must be unique 75 | String topic = "STM32_Pub"; // Topic to subcribe to 76 | String subTopic = "STM32_Sub"; // Topic to subcribe to 77 | 78 | #endif 79 | 80 | void mqtt_receive_callback(char* topic, byte* payload, unsigned int length); 81 | 82 | const int MQTT_PORT = 1883; //if you use SSL //1883 no SSL 83 | 84 | unsigned long lastMsg = 0; 85 | 86 | // Initialize the SSL client library 87 | // Arguments: EthernetClient, our trust anchors 88 | 89 | 90 | WiFiClient ethClient; 91 | 92 | PubSubClient client(MQTT_SERVER, MQTT_PORT, mqtt_receive_callback, ethClient); 93 | 94 | /* 95 | Called whenever a payload is received from a subscribed MQTT topic 96 | */ 97 | void mqtt_receive_callback(char* topic, byte* payload, unsigned int length) 98 | { 99 | Serial.print("MQTT Message receive ["); 100 | Serial.print(topic); 101 | Serial.print("] "); 102 | 103 | for (unsigned int i = 0; i < length; i++) 104 | { 105 | Serial.print((char)payload[i]); 106 | } 107 | 108 | Serial.println(); 109 | } 110 | 111 | void reconnect() 112 | { 113 | // Loop until we're reconnected 114 | while (!client.connected()) 115 | { 116 | Serial.print("Attempting MQTT connection to "); 117 | Serial.println(MQTT_SERVER); 118 | 119 | // Attempt to connect 120 | 121 | #if USING_THINGSTREAM_IO 122 | int connect_status = client.connect(MQTT_CLIENT_ID, MQTT_USER, MQTT_PASS, topic.c_str(), 2, false, ""); 123 | #else 124 | int connect_status = client.connect(ID); 125 | #endif 126 | 127 | if (connect_status) 128 | { 129 | Serial.println("...connected"); 130 | 131 | // Once connected, publish an announcement... 132 | String data = "Hello from MQTTClient_SSL on " + String(BOARD_NAME); 133 | 134 | client.publish(topic.c_str(), data.c_str()); 135 | 136 | Serial.println("Published connection message successfully!"); 137 | 138 | Serial.print("Subcribed to: "); 139 | Serial.println(subTopic); 140 | 141 | // This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9 142 | //ethClientSSL.flush(); 143 | // ... and resubscribe 144 | client.subscribe(subTopic.c_str()); 145 | // for loopback testing 146 | client.subscribe(topic.c_str()); 147 | // This is a workaround to address https://github.com/OPEnSLab-OSU/SSLClient/issues/9 148 | //ethClientSSL.flush(); 149 | } 150 | else 151 | { 152 | Serial.print("failed, rc="); 153 | Serial.print(client.state()); 154 | Serial.println(" try again in 5 seconds"); 155 | 156 | // Wait 5 seconds before retrying 157 | delay(5000); 158 | } 159 | } 160 | } 161 | 162 | void setup() 163 | { 164 | // Open serial communications and wait for port to open: 165 | Serial.begin(115200); 166 | 167 | while (!Serial); 168 | 169 | // Using this if Serial debugging is not necessary or not using Serial port 170 | //while (!Serial && (millis() < 3000)); 171 | 172 | Serial.print("\nStarting MQTT_ThingStream on " + String(ARDUINO_BOARD)); 173 | Serial.println(" with " + String(SHIELD_TYPE)); 174 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 175 | 176 | // To be called before ETH.begin() 177 | WT32_ETH01_onEvent(); 178 | 179 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 180 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 181 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 182 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 183 | 184 | // Static IP, leave without this line to get IP via DHCP 185 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 186 | ETH.config(myIP, myGW, mySN, myDNS); 187 | 188 | WT32_ETH01_waitForConnect(); 189 | 190 | // Note - the default maximum packet size is 256 bytes. If the 191 | // combined length of clientId, username and password exceed this use the 192 | // following to increase the buffer size: 193 | //client.setBufferSize(256); 194 | 195 | Serial.println("***************************************"); 196 | Serial.println(topic); 197 | Serial.println("***************************************"); 198 | } 199 | 200 | #define MQTT_PUBLISH_INTERVAL_MS 5000L 201 | 202 | String data = "Hello from MQTT_ThingStream on " + String(BOARD_NAME) + " with " + String(SHIELD_TYPE); 203 | const char *pubData = data.c_str(); 204 | 205 | void loop() 206 | { 207 | static unsigned long now; 208 | 209 | if (!client.connected()) 210 | { 211 | reconnect(); 212 | } 213 | 214 | // Sending Data 215 | now = millis(); 216 | 217 | if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS) 218 | { 219 | lastMsg = now; 220 | 221 | if (!client.publish(topic.c_str(), pubData)) 222 | { 223 | Serial.println("Message failed to send."); 224 | } 225 | 226 | Serial.print("MQTT Message Send : " + topic + " => "); 227 | Serial.println(data); 228 | } 229 | 230 | client.loop(); 231 | } 232 | -------------------------------------------------------------------------------- /examples/PostServer/PostServer.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | PostServer.h - Dead simple web-server for Ethernet shields 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 17 | 18 | #include 19 | 20 | WebServer server(80); 21 | 22 | // Select the IP address according to your local network 23 | IPAddress myIP(192, 168, 2, 232); 24 | IPAddress myGW(192, 168, 2, 1); 25 | IPAddress mySN(255, 255, 255, 0); 26 | 27 | // Google DNS Server IP 28 | IPAddress myDNS(8, 8, 8, 8); 29 | 30 | const String postForms = 31 | F("\ 32 | \ 33 | WebServer_WT32_ETH01 POST handling\ 34 | \ 37 | \ 38 | \ 39 |

POST plain text to /postplain/


\ 40 |
\ 41 |
\ 42 | \ 43 |
\ 44 |

POST form data to /postform/


\ 45 |
\ 46 |
\ 47 | \ 48 |
\ 49 | \ 50 | "); 51 | 52 | void handleRoot() 53 | { 54 | server.send(200, F("text/html"), postForms); 55 | } 56 | 57 | void handlePlain() 58 | { 59 | if (server.method() != HTTP_POST) 60 | { 61 | server.send(405, F("text/plain"), F("Method Not Allowed")); 62 | } 63 | else 64 | { 65 | server.send(200, F("text/plain"), "POST body was:\n" + server.arg("plain")); 66 | } 67 | } 68 | 69 | void handleForm() 70 | { 71 | if (server.method() != HTTP_POST) 72 | { 73 | server.send(405, F("text/plain"), F("Method Not Allowed")); 74 | } 75 | else 76 | { 77 | String message = F("POST form was:\n"); 78 | 79 | for (uint8_t i = 0; i < server.args(); i++) 80 | { 81 | message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; 82 | } 83 | 84 | server.send(200, F("text/plain"), message); 85 | } 86 | } 87 | 88 | void handleNotFound() 89 | { 90 | String message = F("File Not Found\n\n"); 91 | 92 | message += F("URI: "); 93 | message += server.uri(); 94 | message += F("\nMethod: "); 95 | message += (server.method() == HTTP_GET) ? F("GET") : F("POST"); 96 | message += F("\nArguments: "); 97 | message += server.args(); 98 | message += F("\n"); 99 | 100 | for (uint8_t i = 0; i < server.args(); i++) 101 | { 102 | message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; 103 | } 104 | 105 | server.send(404, F("text/plain"), message); 106 | } 107 | 108 | void setup() 109 | { 110 | Serial.begin(115200); 111 | 112 | while (!Serial); 113 | 114 | // Using this if Serial debugging is not necessary or not using Serial port 115 | //while (!Serial && (millis() < 3000)); 116 | 117 | Serial.print("\nStarting POSTServer on " + String(ARDUINO_BOARD)); 118 | Serial.println(" with " + String(SHIELD_TYPE)); 119 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 120 | 121 | // To be called before ETH.begin() 122 | WT32_ETH01_onEvent(); 123 | 124 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 125 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 126 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 127 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 128 | 129 | // Static IP, leave without this line to get IP via DHCP 130 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 131 | ETH.config(myIP, myGW, mySN, myDNS); 132 | 133 | WT32_ETH01_waitForConnect(); 134 | 135 | server.on(F("/"), handleRoot); 136 | 137 | server.on(F("/postplain/"), handlePlain); 138 | 139 | server.on(F("/postform/"), handleForm); 140 | 141 | server.onNotFound(handleNotFound); 142 | 143 | server.begin(); 144 | 145 | Serial.print(F("HTTP POSTServer started @ IP : ")); 146 | Serial.println(ETH.localIP()); 147 | } 148 | 149 | void loop() 150 | { 151 | server.handleClient(); 152 | } 153 | -------------------------------------------------------------------------------- /examples/SSL/MQTTClient_SSL/certificates.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | certificates.h 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef _CERTIFICATES_H_ 14 | #define _CERTIFICATES_H_ 15 | 16 | // This is the root Certificate Authority that signed the server certifcate 17 | // for the demo server broker.emqx.io in this example. 18 | // To generate the Root CA Cert, use the following command (in Linux / Ubuntu) 19 | // $ openssl s_client -showcerts -connect broker.emqx.io:8883 20 | 21 | const char* rootCACertificate = 22 | "-----BEGIN CERTIFICATE-----\n" \ 23 | "MIIGEzCCA/ugAwIBAgIQfVtRJrR2uhHbdBYLvFMNpzANBgkqhkiG9w0BAQwFADCB\n" \ 24 | "iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl\n" \ 25 | "cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV\n" \ 26 | "BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTgx\n" \ 27 | "MTAyMDAwMDAwWhcNMzAxMjMxMjM1OTU5WjCBjzELMAkGA1UEBhMCR0IxGzAZBgNV\n" \ 28 | "BAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEYMBYGA1UE\n" \ 29 | "ChMPU2VjdGlnbyBMaW1pdGVkMTcwNQYDVQQDEy5TZWN0aWdvIFJTQSBEb21haW4g\n" \ 30 | "VmFsaWRhdGlvbiBTZWN1cmUgU2VydmVyIENBMIIBIjANBgkqhkiG9w0BAQEFAAOC\n" \ 31 | "AQ8AMIIBCgKCAQEA1nMz1tc8INAA0hdFuNY+B6I/x0HuMjDJsGz99J/LEpgPLT+N\n" \ 32 | "TQEMgg8Xf2Iu6bhIefsWg06t1zIlk7cHv7lQP6lMw0Aq6Tn/2YHKHxYyQdqAJrkj\n" \ 33 | "eocgHuP/IJo8lURvh3UGkEC0MpMWCRAIIz7S3YcPb11RFGoKacVPAXJpz9OTTG0E\n" \ 34 | "oKMbgn6xmrntxZ7FN3ifmgg0+1YuWMQJDgZkW7w33PGfKGioVrCSo1yfu4iYCBsk\n" \ 35 | "Haswha6vsC6eep3BwEIc4gLw6uBK0u+QDrTBQBbwb4VCSmT3pDCg/r8uoydajotY\n" \ 36 | "uK3DGReEY+1vVv2Dy2A0xHS+5p3b4eTlygxfFQIDAQABo4IBbjCCAWowHwYDVR0j\n" \ 37 | "BBgwFoAUU3m/WqorSs9UgOHYm8Cd8rIDZsswHQYDVR0OBBYEFI2MXsRUrYrhd+mb\n" \ 38 | "+ZsF4bgBjWHhMA4GA1UdDwEB/wQEAwIBhjASBgNVHRMBAf8ECDAGAQH/AgEAMB0G\n" \ 39 | "A1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAbBgNVHSAEFDASMAYGBFUdIAAw\n" \ 40 | "CAYGZ4EMAQIBMFAGA1UdHwRJMEcwRaBDoEGGP2h0dHA6Ly9jcmwudXNlcnRydXN0\n" \ 41 | "LmNvbS9VU0VSVHJ1c3RSU0FDZXJ0aWZpY2F0aW9uQXV0aG9yaXR5LmNybDB2Bggr\n" \ 42 | "BgEFBQcBAQRqMGgwPwYIKwYBBQUHMAKGM2h0dHA6Ly9jcnQudXNlcnRydXN0LmNv\n" \ 43 | "bS9VU0VSVHJ1c3RSU0FBZGRUcnVzdENBLmNydDAlBggrBgEFBQcwAYYZaHR0cDov\n" \ 44 | "L29jc3AudXNlcnRydXN0LmNvbTANBgkqhkiG9w0BAQwFAAOCAgEAMr9hvQ5Iw0/H\n" \ 45 | "ukdN+Jx4GQHcEx2Ab/zDcLRSmjEzmldS+zGea6TvVKqJjUAXaPgREHzSyrHxVYbH\n" \ 46 | "7rM2kYb2OVG/Rr8PoLq0935JxCo2F57kaDl6r5ROVm+yezu/Coa9zcV3HAO4OLGi\n" \ 47 | "H19+24rcRki2aArPsrW04jTkZ6k4Zgle0rj8nSg6F0AnwnJOKf0hPHzPE/uWLMUx\n" \ 48 | "RP0T7dWbqWlod3zu4f+k+TY4CFM5ooQ0nBnzvg6s1SQ36yOoeNDT5++SR2RiOSLv\n" \ 49 | "xvcRviKFxmZEJCaOEDKNyJOuB56DPi/Z+fVGjmO+wea03KbNIaiGCpXZLoUmGv38\n" \ 50 | "sbZXQm2V0TP2ORQGgkE49Y9Y3IBbpNV9lXj9p5v//cWoaasm56ekBYdbqbe4oyAL\n" \ 51 | "l6lFhd2zi+WJN44pDfwGF/Y4QA5C5BIG+3vzxhFoYt/jmPQT2BVPi7Fp2RBgvGQq\n" \ 52 | "6jG35LWjOhSbJuMLe/0CjraZwTiXWTb2qHSihrZe68Zk6s+go/lunrotEbaGmAhY\n" \ 53 | "LcmsJWTyXnW0OMGuf1pGg+pRyrbxmRE1a6Vqe8YAsOf4vmSyrcjC8azjUeqkk+B5\n" \ 54 | "yOGBQMkKW+ESPMFgKuOXwIlCypTPRpgSabuY0MLTDXJLR27lk8QyKGOHQ+SwMj4K\n" \ 55 | "00u/I5sUKUErmgQfky3xxzlIPK1aEn8=\n" \ 56 | "-----END CERTIFICATE-----\n"; 57 | 58 | #endif /* ifndef _CERTIFICATES_H_ */ 59 | -------------------------------------------------------------------------------- /examples/SSL/MQTTClient_SSL_Auth/MQTTClient_SSL_Auth.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | MQTTClient_SSL_Auth.ino - Dead simple SSL MQTT Client for Ethernet shields 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | /* 14 | Basic MQTT example (with SSL!) with Authentication 15 | This sketch demonstrates the basic capabilities of the library. 16 | It connects to an MQTT server then: 17 | - providing username and password ("testuser" and "testpass") 18 | - publishes "Hello from MQTTClient_SSL_Auth on WT32-ETH01" to the topic "MQTT_Pub" 19 | - subscribes to the topic "MQTT_Sub", printing out any messages 20 | it receives. NB - it assumes the received payloads are strings not binary 21 | It will reconnect to the server if the connection is lost using a blocking 22 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 23 | achieve the same result without blocking the main loop. 24 | */ 25 | 26 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 27 | 28 | // Debug Level from 0 to 4 29 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 30 | 31 | #include 32 | 33 | #include 34 | 35 | // Select the IP address according to your local network 36 | IPAddress myIP(192, 168, 2, 232); 37 | IPAddress myGW(192, 168, 2, 1); 38 | IPAddress mySN(255, 255, 255, 0); 39 | 40 | // Google DNS Server IP 41 | IPAddress myDNS(8, 8, 8, 8); 42 | 43 | #include "certificates.h" 44 | #include 45 | 46 | // Update these with values suitable for your network. 47 | 48 | const char* mqttServer = "broker.emqx.io"; // Broker address 49 | 50 | const char *TOPIC = "MQTT_Pub"; // Topic to subcribe to 51 | const char *subTopic = "MQTT_Sub"; // Topic to subcribe to 52 | 53 | void callback(char* topic, byte* payload, unsigned int length) 54 | { 55 | Serial.print("Message arrived ["); 56 | Serial.print(topic); 57 | Serial.print("] "); 58 | 59 | for (unsigned int i = 0; i < length; i++) 60 | { 61 | Serial.print((char)payload[i]); 62 | } 63 | 64 | Serial.println(); 65 | } 66 | 67 | WiFiClientSecure ethClientSSL; 68 | 69 | PubSubClient client(mqttServer, 8883, callback, ethClientSSL); 70 | 71 | void reconnect() 72 | { 73 | // Loop until we're reconnected 74 | while (!client.connected()) 75 | { 76 | Serial.print("Attempting MQTTS connection to "); 77 | Serial.print(mqttServer); 78 | 79 | // Attempt to connect 80 | if (client.connect("arduinoClient", "testuser", "testpass")) 81 | { 82 | Serial.println("...connected"); 83 | 84 | // Once connected, publish an announcement... 85 | client.publish(TOPIC, "Hello World from WT32_ETH01"); 86 | // ... and resubscribe 87 | client.subscribe(subTopic); 88 | // for loopback testing 89 | client.subscribe(TOPIC); 90 | } 91 | else 92 | { 93 | Serial.print(" => failed, rc="); 94 | Serial.print(client.state()); 95 | Serial.println(" try again in 5 seconds"); 96 | 97 | // Wait 5 seconds before retrying 98 | delay(5000); 99 | } 100 | } 101 | } 102 | 103 | // Not sure if WiFiClientSecure checks the validity date of the certificate. 104 | // Setting clock just to be sure... 105 | void setClock() 106 | { 107 | configTime(0, 0, "pool.ntp.org"); 108 | 109 | Serial.print(F("Waiting for NTP time sync: ")); 110 | time_t nowSecs = time(nullptr); 111 | 112 | while (nowSecs < 8 * 3600 * 2) 113 | { 114 | delay(500); 115 | Serial.print(F(".")); 116 | yield(); 117 | nowSecs = time(nullptr); 118 | } 119 | 120 | Serial.println(); 121 | struct tm timeinfo; 122 | gmtime_r(&nowSecs, &timeinfo); 123 | Serial.print(F("Current time: ")); 124 | Serial.print(asctime(&timeinfo)); 125 | } 126 | 127 | void setup() 128 | { 129 | // Open serial communications and wait for port to open: 130 | Serial.begin(115200); 131 | 132 | while (!Serial); 133 | 134 | // Using this if Serial debugging is not necessary or not using Serial port 135 | //while (!Serial && (millis() < 3000)); 136 | 137 | Serial.print("\nStarting MQTTClient_SSL_Auth on " + String(ARDUINO_BOARD)); 138 | Serial.println(" with " + String(SHIELD_TYPE)); 139 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 140 | 141 | // To be called before ETH.begin() 142 | WT32_ETH01_onEvent(); 143 | 144 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 145 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 146 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 147 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 148 | 149 | // Static IP, leave without this line to get IP via DHCP 150 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 151 | ETH.config(myIP, myGW, mySN, myDNS); 152 | 153 | WT32_ETH01_waitForConnect(); 154 | 155 | setClock(); 156 | 157 | ethClientSSL.setCACert(rootCACertificate); 158 | 159 | // Note - the default maximum packet size is 128 bytes. If the 160 | // combined length of clientId, username and password exceed this use the 161 | // following to increase the buffer size: 162 | client.setBufferSize(255); 163 | } 164 | 165 | #define MQTT_PUBLISH_INTERVAL_MS 10000L 166 | 167 | String data = "Hello from MQTTClient_SSL_Auth on " + String(BOARD_NAME); 168 | const char *pubData = data.c_str(); 169 | 170 | unsigned long lastMsg = 0; 171 | 172 | void loop() 173 | { 174 | static unsigned long now; 175 | 176 | if (!client.connected()) 177 | { 178 | reconnect(); 179 | } 180 | 181 | // Sending Data 182 | now = millis(); 183 | 184 | if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS) 185 | { 186 | lastMsg = now; 187 | 188 | if (!client.publish(TOPIC, pubData)) 189 | { 190 | Serial.println("Message failed to send."); 191 | } 192 | 193 | Serial.print("Message Send : " + String(TOPIC) + " => "); 194 | Serial.println(data); 195 | } 196 | 197 | client.loop(); 198 | } 199 | -------------------------------------------------------------------------------- /examples/SSL/MQTTClient_SSL_Auth/certificates.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | certificates.h 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef _CERTIFICATES_H_ 14 | #define _CERTIFICATES_H_ 15 | 16 | // This is the root Certificate Authority that signed the server certifcate 17 | // for the demo server broker.emqx.io in this example. 18 | // To generate the Root CA Cert, use the following command (in Linux / Ubuntu) 19 | // $ openssl s_client -showcerts -connect broker.emqx.io:8883 20 | 21 | const char* rootCACertificate = 22 | "-----BEGIN CERTIFICATE-----\n" \ 23 | "MIIGEzCCA/ugAwIBAgIQfVtRJrR2uhHbdBYLvFMNpzANBgkqhkiG9w0BAQwFADCB\n" \ 24 | "iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl\n" \ 25 | "cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV\n" \ 26 | "BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTgx\n" \ 27 | "MTAyMDAwMDAwWhcNMzAxMjMxMjM1OTU5WjCBjzELMAkGA1UEBhMCR0IxGzAZBgNV\n" \ 28 | "BAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEYMBYGA1UE\n" \ 29 | "ChMPU2VjdGlnbyBMaW1pdGVkMTcwNQYDVQQDEy5TZWN0aWdvIFJTQSBEb21haW4g\n" \ 30 | "VmFsaWRhdGlvbiBTZWN1cmUgU2VydmVyIENBMIIBIjANBgkqhkiG9w0BAQEFAAOC\n" \ 31 | "AQ8AMIIBCgKCAQEA1nMz1tc8INAA0hdFuNY+B6I/x0HuMjDJsGz99J/LEpgPLT+N\n" \ 32 | "TQEMgg8Xf2Iu6bhIefsWg06t1zIlk7cHv7lQP6lMw0Aq6Tn/2YHKHxYyQdqAJrkj\n" \ 33 | "eocgHuP/IJo8lURvh3UGkEC0MpMWCRAIIz7S3YcPb11RFGoKacVPAXJpz9OTTG0E\n" \ 34 | "oKMbgn6xmrntxZ7FN3ifmgg0+1YuWMQJDgZkW7w33PGfKGioVrCSo1yfu4iYCBsk\n" \ 35 | "Haswha6vsC6eep3BwEIc4gLw6uBK0u+QDrTBQBbwb4VCSmT3pDCg/r8uoydajotY\n" \ 36 | "uK3DGReEY+1vVv2Dy2A0xHS+5p3b4eTlygxfFQIDAQABo4IBbjCCAWowHwYDVR0j\n" \ 37 | "BBgwFoAUU3m/WqorSs9UgOHYm8Cd8rIDZsswHQYDVR0OBBYEFI2MXsRUrYrhd+mb\n" \ 38 | "+ZsF4bgBjWHhMA4GA1UdDwEB/wQEAwIBhjASBgNVHRMBAf8ECDAGAQH/AgEAMB0G\n" \ 39 | "A1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAbBgNVHSAEFDASMAYGBFUdIAAw\n" \ 40 | "CAYGZ4EMAQIBMFAGA1UdHwRJMEcwRaBDoEGGP2h0dHA6Ly9jcmwudXNlcnRydXN0\n" \ 41 | "LmNvbS9VU0VSVHJ1c3RSU0FDZXJ0aWZpY2F0aW9uQXV0aG9yaXR5LmNybDB2Bggr\n" \ 42 | "BgEFBQcBAQRqMGgwPwYIKwYBBQUHMAKGM2h0dHA6Ly9jcnQudXNlcnRydXN0LmNv\n" \ 43 | "bS9VU0VSVHJ1c3RSU0FBZGRUcnVzdENBLmNydDAlBggrBgEFBQcwAYYZaHR0cDov\n" \ 44 | "L29jc3AudXNlcnRydXN0LmNvbTANBgkqhkiG9w0BAQwFAAOCAgEAMr9hvQ5Iw0/H\n" \ 45 | "ukdN+Jx4GQHcEx2Ab/zDcLRSmjEzmldS+zGea6TvVKqJjUAXaPgREHzSyrHxVYbH\n" \ 46 | "7rM2kYb2OVG/Rr8PoLq0935JxCo2F57kaDl6r5ROVm+yezu/Coa9zcV3HAO4OLGi\n" \ 47 | "H19+24rcRki2aArPsrW04jTkZ6k4Zgle0rj8nSg6F0AnwnJOKf0hPHzPE/uWLMUx\n" \ 48 | "RP0T7dWbqWlod3zu4f+k+TY4CFM5ooQ0nBnzvg6s1SQ36yOoeNDT5++SR2RiOSLv\n" \ 49 | "xvcRviKFxmZEJCaOEDKNyJOuB56DPi/Z+fVGjmO+wea03KbNIaiGCpXZLoUmGv38\n" \ 50 | "sbZXQm2V0TP2ORQGgkE49Y9Y3IBbpNV9lXj9p5v//cWoaasm56ekBYdbqbe4oyAL\n" \ 51 | "l6lFhd2zi+WJN44pDfwGF/Y4QA5C5BIG+3vzxhFoYt/jmPQT2BVPi7Fp2RBgvGQq\n" \ 52 | "6jG35LWjOhSbJuMLe/0CjraZwTiXWTb2qHSihrZe68Zk6s+go/lunrotEbaGmAhY\n" \ 53 | "LcmsJWTyXnW0OMGuf1pGg+pRyrbxmRE1a6Vqe8YAsOf4vmSyrcjC8azjUeqkk+B5\n" \ 54 | "yOGBQMkKW+ESPMFgKuOXwIlCypTPRpgSabuY0MLTDXJLR27lk8QyKGOHQ+SwMj4K\n" \ 55 | "00u/I5sUKUErmgQfky3xxzlIPK1aEn8=\n" \ 56 | "-----END CERTIFICATE-----\n"; 57 | 58 | #endif /* ifndef _CERTIFICATES_H_ */ 59 | -------------------------------------------------------------------------------- /examples/SSL/MQTTClient_SSL_Complex/MQTTClient_SSL_Complex.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | MQTTClient_SSL_Complex.ino - Dead simple SSL MQTT Client for Ethernet shields 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | /* 14 | Basic MQTT example (with SSL!) 15 | This sketch demonstrates the basic capabilities of the library. 16 | It connects to an MQTT server then: 17 | - publishes {Hello from MQTTClient_SSL_Complex on WT32-ETH01, millis = xxxxx} to the topic [MQTT_Pub] 18 | - subscribes to the topic [MQTT_Sub], printing out any messages 19 | it receives. NB - it assumes the received payloads are strings not binary 20 | It will reconnect to the server if the connection is lost using a blocking 21 | reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to 22 | achieve the same result without blocking the main loop. 23 | */ 24 | 25 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 26 | 27 | // Debug Level from 0 to 4 28 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 29 | 30 | #include 31 | 32 | #include 33 | 34 | // Select the IP address according to your local network 35 | IPAddress myIP(192, 168, 2, 232); 36 | IPAddress myGW(192, 168, 2, 1); 37 | IPAddress mySN(255, 255, 255, 0); 38 | 39 | // Google DNS Server IP 40 | IPAddress myDNS(8, 8, 8, 8); 41 | 42 | #include "certificates.h" // This file must be regenerated at https://openslab-osu.github.io/bearssl-certificate-utility/ 43 | #include 44 | 45 | const char* mqttServer = "broker.emqx.io"; // Broker address 46 | 47 | const char *ID = "MQTTClient_SSL-Client"; // Name of our device, must be unique 48 | const char *TOPIC = "MQTT_Pub"; // Topic to subcribe to 49 | const char *subTopic = "MQTT_Sub"; // Topic to subcribe to 50 | 51 | unsigned long lastMsg = 0; 52 | 53 | // Initialize the SSL client library 54 | // Arguments: EthernetClient, our trust anchors 55 | 56 | void callback(char* topic, byte* payload, unsigned int length) 57 | { 58 | Serial.print("Message arrived ["); 59 | Serial.print(topic); 60 | Serial.print("] "); 61 | 62 | for (unsigned int i = 0; i < length; i++) 63 | { 64 | Serial.print((char)payload[i]); 65 | } 66 | 67 | Serial.println(); 68 | } 69 | 70 | WiFiClientSecure ethClientSSL; 71 | 72 | PubSubClient client(mqttServer, 8883, callback, ethClientSSL); 73 | 74 | void reconnect() 75 | { 76 | // Loop until we're reconnected 77 | while (!client.connected()) 78 | { 79 | Serial.print("Attempting MQTT connection to "); 80 | Serial.print(mqttServer); 81 | 82 | // Attempt to connect 83 | if (client.connect(ID)) 84 | { 85 | Serial.println("...connected"); 86 | 87 | // Once connected, publish an announcement... 88 | String data = "Hello from MQTTClient_SSL_Complex on " + String(BOARD_NAME); 89 | 90 | client.publish(TOPIC, data.c_str()); 91 | 92 | //Serial.println("Published connection message successfully!"); 93 | //Serial.print("Subcribed to: "); 94 | //Serial.println(subTopic); 95 | 96 | // ... and resubscribe 97 | client.subscribe(subTopic); 98 | // for loopback testing 99 | client.subscribe(TOPIC); 100 | } 101 | else 102 | { 103 | Serial.print("failed, rc="); 104 | Serial.print(client.state()); 105 | Serial.println(" try again in 5 seconds"); 106 | 107 | // Wait 5 seconds before retrying 108 | delay(5000); 109 | } 110 | } 111 | } 112 | 113 | // Not sure if WiFiClientSecure checks the validity date of the certificate. 114 | // Setting clock just to be sure... 115 | void setClock() 116 | { 117 | configTime(0, 0, "pool.ntp.org"); 118 | 119 | Serial.print(F("Waiting for NTP time sync: ")); 120 | time_t nowSecs = time(nullptr); 121 | 122 | while (nowSecs < 8 * 3600 * 2) 123 | { 124 | delay(500); 125 | Serial.print(F(".")); 126 | yield(); 127 | nowSecs = time(nullptr); 128 | } 129 | 130 | Serial.println(); 131 | struct tm timeinfo; 132 | gmtime_r(&nowSecs, &timeinfo); 133 | Serial.print(F("Current time: ")); 134 | Serial.print(asctime(&timeinfo)); 135 | } 136 | 137 | void setup() 138 | { 139 | // Open serial communications and wait for port to open: 140 | Serial.begin(115200); 141 | 142 | while (!Serial); 143 | 144 | // Using this if Serial debugging is not necessary or not using Serial port 145 | //while (!Serial && (millis() < 3000)); 146 | 147 | Serial.print("\nStarting MQTTClient_SSL_Complex on " + String(ARDUINO_BOARD)); 148 | Serial.println(" with " + String(SHIELD_TYPE)); 149 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 150 | 151 | // To be called before ETH.begin() 152 | WT32_ETH01_onEvent(); 153 | 154 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 155 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 156 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 157 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 158 | 159 | // Static IP, leave without this line to get IP via DHCP 160 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 161 | ETH.config(myIP, myGW, mySN, myDNS); 162 | 163 | WT32_ETH01_waitForConnect(); 164 | 165 | setClock(); 166 | 167 | ethClientSSL.setCACert(rootCACertificate); 168 | 169 | // Note - the default maximum packet size is 128 bytes. If the 170 | // combined length of clientId, username and password exceed this use the 171 | // following to increase the buffer size: 172 | client.setBufferSize(255); 173 | } 174 | 175 | #define MQTT_PUBLISH_INTERVAL_MS 5000L 176 | 177 | void loop() 178 | { 179 | static unsigned long now; 180 | 181 | if (!client.connected()) 182 | { 183 | reconnect(); 184 | } 185 | 186 | // Sending Data 187 | now = millis(); 188 | 189 | if (now - lastMsg > MQTT_PUBLISH_INTERVAL_MS) 190 | { 191 | lastMsg = now; 192 | 193 | String data = "Hello from MQTTClient_SSL_Complex on " + String(BOARD_NAME) + ", millis = " + String(millis()); 194 | 195 | if (!client.publish(TOPIC, data.c_str())) 196 | { 197 | Serial.println("Message failed to send."); 198 | } 199 | 200 | Serial.print("Message Send : " + String(TOPIC) + " => "); 201 | Serial.println(data); 202 | } 203 | 204 | client.loop(); 205 | } 206 | -------------------------------------------------------------------------------- /examples/SSL/MQTTClient_SSL_Complex/certificates.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | certificates.h 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef _CERTIFICATES_H_ 14 | #define _CERTIFICATES_H_ 15 | 16 | // This is the root Certificate Authority that signed the server certifcate 17 | // for the demo server broker.emqx.io in this example. 18 | // To generate the Root CA Cert, use the following command (in Linux / Ubuntu) 19 | // $ openssl s_client -showcerts -connect broker.emqx.io:8883 20 | 21 | const char* rootCACertificate = 22 | "-----BEGIN CERTIFICATE-----\n" \ 23 | "MIIGEzCCA/ugAwIBAgIQfVtRJrR2uhHbdBYLvFMNpzANBgkqhkiG9w0BAQwFADCB\n" \ 24 | "iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl\n" \ 25 | "cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV\n" \ 26 | "BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTgx\n" \ 27 | "MTAyMDAwMDAwWhcNMzAxMjMxMjM1OTU5WjCBjzELMAkGA1UEBhMCR0IxGzAZBgNV\n" \ 28 | "BAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEYMBYGA1UE\n" \ 29 | "ChMPU2VjdGlnbyBMaW1pdGVkMTcwNQYDVQQDEy5TZWN0aWdvIFJTQSBEb21haW4g\n" \ 30 | "VmFsaWRhdGlvbiBTZWN1cmUgU2VydmVyIENBMIIBIjANBgkqhkiG9w0BAQEFAAOC\n" \ 31 | "AQ8AMIIBCgKCAQEA1nMz1tc8INAA0hdFuNY+B6I/x0HuMjDJsGz99J/LEpgPLT+N\n" \ 32 | "TQEMgg8Xf2Iu6bhIefsWg06t1zIlk7cHv7lQP6lMw0Aq6Tn/2YHKHxYyQdqAJrkj\n" \ 33 | "eocgHuP/IJo8lURvh3UGkEC0MpMWCRAIIz7S3YcPb11RFGoKacVPAXJpz9OTTG0E\n" \ 34 | "oKMbgn6xmrntxZ7FN3ifmgg0+1YuWMQJDgZkW7w33PGfKGioVrCSo1yfu4iYCBsk\n" \ 35 | "Haswha6vsC6eep3BwEIc4gLw6uBK0u+QDrTBQBbwb4VCSmT3pDCg/r8uoydajotY\n" \ 36 | "uK3DGReEY+1vVv2Dy2A0xHS+5p3b4eTlygxfFQIDAQABo4IBbjCCAWowHwYDVR0j\n" \ 37 | "BBgwFoAUU3m/WqorSs9UgOHYm8Cd8rIDZsswHQYDVR0OBBYEFI2MXsRUrYrhd+mb\n" \ 38 | "+ZsF4bgBjWHhMA4GA1UdDwEB/wQEAwIBhjASBgNVHRMBAf8ECDAGAQH/AgEAMB0G\n" \ 39 | "A1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAbBgNVHSAEFDASMAYGBFUdIAAw\n" \ 40 | "CAYGZ4EMAQIBMFAGA1UdHwRJMEcwRaBDoEGGP2h0dHA6Ly9jcmwudXNlcnRydXN0\n" \ 41 | "LmNvbS9VU0VSVHJ1c3RSU0FDZXJ0aWZpY2F0aW9uQXV0aG9yaXR5LmNybDB2Bggr\n" \ 42 | "BgEFBQcBAQRqMGgwPwYIKwYBBQUHMAKGM2h0dHA6Ly9jcnQudXNlcnRydXN0LmNv\n" \ 43 | "bS9VU0VSVHJ1c3RSU0FBZGRUcnVzdENBLmNydDAlBggrBgEFBQcwAYYZaHR0cDov\n" \ 44 | "L29jc3AudXNlcnRydXN0LmNvbTANBgkqhkiG9w0BAQwFAAOCAgEAMr9hvQ5Iw0/H\n" \ 45 | "ukdN+Jx4GQHcEx2Ab/zDcLRSmjEzmldS+zGea6TvVKqJjUAXaPgREHzSyrHxVYbH\n" \ 46 | "7rM2kYb2OVG/Rr8PoLq0935JxCo2F57kaDl6r5ROVm+yezu/Coa9zcV3HAO4OLGi\n" \ 47 | "H19+24rcRki2aArPsrW04jTkZ6k4Zgle0rj8nSg6F0AnwnJOKf0hPHzPE/uWLMUx\n" \ 48 | "RP0T7dWbqWlod3zu4f+k+TY4CFM5ooQ0nBnzvg6s1SQ36yOoeNDT5++SR2RiOSLv\n" \ 49 | "xvcRviKFxmZEJCaOEDKNyJOuB56DPi/Z+fVGjmO+wea03KbNIaiGCpXZLoUmGv38\n" \ 50 | "sbZXQm2V0TP2ORQGgkE49Y9Y3IBbpNV9lXj9p5v//cWoaasm56ekBYdbqbe4oyAL\n" \ 51 | "l6lFhd2zi+WJN44pDfwGF/Y4QA5C5BIG+3vzxhFoYt/jmPQT2BVPi7Fp2RBgvGQq\n" \ 52 | "6jG35LWjOhSbJuMLe/0CjraZwTiXWTb2qHSihrZe68Zk6s+go/lunrotEbaGmAhY\n" \ 53 | "LcmsJWTyXnW0OMGuf1pGg+pRyrbxmRE1a6Vqe8YAsOf4vmSyrcjC8azjUeqkk+B5\n" \ 54 | "yOGBQMkKW+ESPMFgKuOXwIlCypTPRpgSabuY0MLTDXJLR27lk8QyKGOHQ+SwMj4K\n" \ 55 | "00u/I5sUKUErmgQfky3xxzlIPK1aEn8=\n" \ 56 | "-----END CERTIFICATE-----\n"; 57 | 58 | #endif /* ifndef _CERTIFICATES_H_ */ 59 | -------------------------------------------------------------------------------- /examples/SSL/MQTTS_ThingStream/certificates.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | certificates.h 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef _CERTIFICATES_H_ 14 | #define _CERTIFICATES_H_ 15 | 16 | #if USING_THINGSTREAM_IO 17 | 18 | // This is the root Certificate Authority that signed the server certifcate 19 | // for the demo server mqtt.thingstream.io in this example. 20 | // To generate the Root CA Cert, use the following command (in Linux / Ubuntu) 21 | // $ openssl s_client -showcerts -connect mqtt.thingstream.io:8883 22 | 23 | const char* rootCACertificate = 24 | "-----BEGIN CERTIFICATE-----\n" \ 25 | "MIIESTCCAzGgAwIBAgITBn+UV4WH6Kx33rJTMlu8mYtWDTANBgkqhkiG9w0BAQsF\n" \ 26 | "ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n" \ 27 | "b24gUm9vdCBDQSAxMB4XDTE1MTAyMjAwMDAwMFoXDTI1MTAxOTAwMDAwMFowRjEL\n" \ 28 | "MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEVMBMGA1UECxMMU2VydmVyIENB\n" \ 29 | "IDFCMQ8wDQYDVQQDEwZBbWF6b24wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK\n" \ 30 | "AoIBAQDCThZn3c68asg3Wuw6MLAd5tES6BIoSMzoKcG5blPVo+sDORrMd4f2AbnZ\n" \ 31 | "cMzPa43j4wNxhplty6aUKk4T1qe9BOwKFjwK6zmxxLVYo7bHViXsPlJ6qOMpFge5\n" \ 32 | "blDP+18x+B26A0piiQOuPkfyDyeR4xQghfj66Yo19V+emU3nazfvpFA+ROz6WoVm\n" \ 33 | "B5x+F2pV8xeKNR7u6azDdU5YVX1TawprmxRC1+WsAYmz6qP+z8ArDITC2FMVy2fw\n" \ 34 | "0IjKOtEXc/VfmtTFch5+AfGYMGMqqvJ6LcXiAhqG5TI+Dr0RtM88k+8XUBCeQ8IG\n" \ 35 | "KuANaL7TiItKZYxK1MMuTJtV9IblAgMBAAGjggE7MIIBNzASBgNVHRMBAf8ECDAG\n" \ 36 | "AQH/AgEAMA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQUWaRmBlKge5WSPKOUByeW\n" \ 37 | "dFv5PdAwHwYDVR0jBBgwFoAUhBjMhTTsvAyUlC4IWZzHshBOCggwewYIKwYBBQUH\n" \ 38 | "AQEEbzBtMC8GCCsGAQUFBzABhiNodHRwOi8vb2NzcC5yb290Y2ExLmFtYXpvbnRy\n" \ 39 | "dXN0LmNvbTA6BggrBgEFBQcwAoYuaHR0cDovL2NydC5yb290Y2ExLmFtYXpvbnRy\n" \ 40 | "dXN0LmNvbS9yb290Y2ExLmNlcjA/BgNVHR8EODA2MDSgMqAwhi5odHRwOi8vY3Js\n" \ 41 | "LnJvb3RjYTEuYW1hem9udHJ1c3QuY29tL3Jvb3RjYTEuY3JsMBMGA1UdIAQMMAow\n" \ 42 | "CAYGZ4EMAQIBMA0GCSqGSIb3DQEBCwUAA4IBAQCFkr41u3nPo4FCHOTjY3NTOVI1\n" \ 43 | "59Gt/a6ZiqyJEi+752+a1U5y6iAwYfmXss2lJwJFqMp2PphKg5625kXg8kP2CN5t\n" \ 44 | "6G7bMQcT8C8xDZNtYTd7WPD8UZiRKAJPBXa30/AbwuZe0GaFEQ8ugcYQgSn+IGBI\n" \ 45 | "8/LwhBNTZTUVEWuCUUBVV18YtbAiPq3yXqMB48Oz+ctBWuZSkbvkNodPLamkB2g1\n" \ 46 | "upRyzQ7qDn1X8nn8N8V7YJ6y68AtkHcNSRAnpTitxBKjtKPISLMVCx7i4hncxHZS\n" \ 47 | "yLyKQXhw2W2Xs0qLeC1etA+jTGDK4UfLeC0SF7FSi8o5LL21L8IzApar2pR/\n" \ 48 | "-----END CERTIFICATE-----\n"; 49 | 50 | #else 51 | 52 | // This is the root Certificate Authority that signed the server certifcate 53 | // for the demo server broker.emqx.io in this example. 54 | // To generate the Root CA Cert, use the following command (in Linux / Ubuntu) 55 | // $ openssl s_client -showcerts -connect broker.emqx.io:8883 56 | 57 | const char* rootCACertificate = 58 | "-----BEGIN CERTIFICATE-----\n" \ 59 | "MIIGEzCCA/ugAwIBAgIQfVtRJrR2uhHbdBYLvFMNpzANBgkqhkiG9w0BAQwFADCB\n" \ 60 | "iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl\n" \ 61 | "cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV\n" \ 62 | "BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTgx\n" \ 63 | "MTAyMDAwMDAwWhcNMzAxMjMxMjM1OTU5WjCBjzELMAkGA1UEBhMCR0IxGzAZBgNV\n" \ 64 | "BAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEYMBYGA1UE\n" \ 65 | "ChMPU2VjdGlnbyBMaW1pdGVkMTcwNQYDVQQDEy5TZWN0aWdvIFJTQSBEb21haW4g\n" \ 66 | "VmFsaWRhdGlvbiBTZWN1cmUgU2VydmVyIENBMIIBIjANBgkqhkiG9w0BAQEFAAOC\n" \ 67 | "AQ8AMIIBCgKCAQEA1nMz1tc8INAA0hdFuNY+B6I/x0HuMjDJsGz99J/LEpgPLT+N\n" \ 68 | "TQEMgg8Xf2Iu6bhIefsWg06t1zIlk7cHv7lQP6lMw0Aq6Tn/2YHKHxYyQdqAJrkj\n" \ 69 | "eocgHuP/IJo8lURvh3UGkEC0MpMWCRAIIz7S3YcPb11RFGoKacVPAXJpz9OTTG0E\n" \ 70 | "oKMbgn6xmrntxZ7FN3ifmgg0+1YuWMQJDgZkW7w33PGfKGioVrCSo1yfu4iYCBsk\n" \ 71 | "Haswha6vsC6eep3BwEIc4gLw6uBK0u+QDrTBQBbwb4VCSmT3pDCg/r8uoydajotY\n" \ 72 | "uK3DGReEY+1vVv2Dy2A0xHS+5p3b4eTlygxfFQIDAQABo4IBbjCCAWowHwYDVR0j\n" \ 73 | "BBgwFoAUU3m/WqorSs9UgOHYm8Cd8rIDZsswHQYDVR0OBBYEFI2MXsRUrYrhd+mb\n" \ 74 | "+ZsF4bgBjWHhMA4GA1UdDwEB/wQEAwIBhjASBgNVHRMBAf8ECDAGAQH/AgEAMB0G\n" \ 75 | "A1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAbBgNVHSAEFDASMAYGBFUdIAAw\n" \ 76 | "CAYGZ4EMAQIBMFAGA1UdHwRJMEcwRaBDoEGGP2h0dHA6Ly9jcmwudXNlcnRydXN0\n" \ 77 | "LmNvbS9VU0VSVHJ1c3RSU0FDZXJ0aWZpY2F0aW9uQXV0aG9yaXR5LmNybDB2Bggr\n" \ 78 | "BgEFBQcBAQRqMGgwPwYIKwYBBQUHMAKGM2h0dHA6Ly9jcnQudXNlcnRydXN0LmNv\n" \ 79 | "bS9VU0VSVHJ1c3RSU0FBZGRUcnVzdENBLmNydDAlBggrBgEFBQcwAYYZaHR0cDov\n" \ 80 | "L29jc3AudXNlcnRydXN0LmNvbTANBgkqhkiG9w0BAQwFAAOCAgEAMr9hvQ5Iw0/H\n" \ 81 | "ukdN+Jx4GQHcEx2Ab/zDcLRSmjEzmldS+zGea6TvVKqJjUAXaPgREHzSyrHxVYbH\n" \ 82 | "7rM2kYb2OVG/Rr8PoLq0935JxCo2F57kaDl6r5ROVm+yezu/Coa9zcV3HAO4OLGi\n" \ 83 | "H19+24rcRki2aArPsrW04jTkZ6k4Zgle0rj8nSg6F0AnwnJOKf0hPHzPE/uWLMUx\n" \ 84 | "RP0T7dWbqWlod3zu4f+k+TY4CFM5ooQ0nBnzvg6s1SQ36yOoeNDT5++SR2RiOSLv\n" \ 85 | "xvcRviKFxmZEJCaOEDKNyJOuB56DPi/Z+fVGjmO+wea03KbNIaiGCpXZLoUmGv38\n" \ 86 | "sbZXQm2V0TP2ORQGgkE49Y9Y3IBbpNV9lXj9p5v//cWoaasm56ekBYdbqbe4oyAL\n" \ 87 | "l6lFhd2zi+WJN44pDfwGF/Y4QA5C5BIG+3vzxhFoYt/jmPQT2BVPi7Fp2RBgvGQq\n" \ 88 | "6jG35LWjOhSbJuMLe/0CjraZwTiXWTb2qHSihrZe68Zk6s+go/lunrotEbaGmAhY\n" \ 89 | "LcmsJWTyXnW0OMGuf1pGg+pRyrbxmRE1a6Vqe8YAsOf4vmSyrcjC8azjUeqkk+B5\n" \ 90 | "yOGBQMkKW+ESPMFgKuOXwIlCypTPRpgSabuY0MLTDXJLR27lk8QyKGOHQ+SwMj4K\n" \ 91 | "00u/I5sUKUErmgQfky3xxzlIPK1aEn8=\n" \ 92 | "-----END CERTIFICATE-----\n"; 93 | 94 | #endif // USING_THINGSTREAM_IO 95 | 96 | #endif /* ifndef _CERTIFICATES_H_ */ 97 | -------------------------------------------------------------------------------- /examples/SSL/WebClientMulti_SSL/WebClientMulti_SSL.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebClientMulti_SSL.ino - Dead simple SSL WebClient for Ethernet shields 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | // This sketch connects to SSL websites (https://www.arduino.cc/asciilogo.txt) and (https://www.cloudflare.com/cdn-cgi/trace) 14 | 15 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 16 | 17 | // Debug Level from 0 to 4 18 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 19 | 20 | #include 21 | 22 | #include 23 | 24 | // Select the IP address according to your local network 25 | IPAddress myIP(192, 168, 2, 232); 26 | IPAddress myGW(192, 168, 2, 1); 27 | IPAddress mySN(255, 255, 255, 0); 28 | 29 | // Google DNS Server IP 30 | IPAddress myDNS(8, 8, 8, 8); 31 | 32 | #include "certificates.h" 33 | 34 | // the two domains we want to query 35 | char server1[] = "www.arduino.cc"; 36 | char server2[] = "www.cloudflare.com"; 37 | // and the queries we want to send to them 38 | char query1[] = "GET /asciilogo.txt HTTP/1.1"; 39 | char query2[] = "GET /cdn-cgi/trace HTTP/1.1"; 40 | 41 | const uint16_t server_port = 443; 42 | 43 | // Initialize the SSL client library 44 | WiFiClientSecure sslClient; 45 | 46 | // Variables to measure 47 | unsigned long beginMillis; 48 | unsigned long byteCount = 0; 49 | unsigned long loopCount = 0; 50 | 51 | bool printWebData = true; // set to false for better speed measurement 52 | 53 | void connectSSL() 54 | { 55 | static bool r = true; 56 | // cycle the server we want to connect to back and forth 57 | char* server; 58 | char* query; 59 | 60 | if (r) 61 | { 62 | server = server1; 63 | query = query1; 64 | sslClient.setCACert(rootCACertificate1); 65 | } 66 | else 67 | { 68 | server = server2; 69 | query = query2; 70 | sslClient.setCACert(rootCACertificate2); 71 | } 72 | 73 | r = !r; 74 | 75 | Serial.print("Connecting to "); 76 | Serial.print(server); 77 | Serial.println("..."); 78 | 79 | // if you get a connection, report back via serial: 80 | auto start = millis(); 81 | 82 | if (sslClient.connect(server, server_port)) 83 | { 84 | auto time = millis() - start; 85 | 86 | Serial.print("Took (ms): "); 87 | Serial.println(time); 88 | 89 | // Make a HTTP request: 90 | sslClient.println(query); 91 | sslClient.println("User-Agent: SSLClientOverEthernet"); 92 | sslClient.print("Host: "); 93 | sslClient.println(server); 94 | sslClient.println("Connection: close"); 95 | sslClient.println(); 96 | sslClient.flush(); 97 | } 98 | else 99 | { 100 | // if you didn't get a connection to the server: 101 | Serial.println("connection failed"); 102 | } 103 | 104 | beginMillis = millis(); 105 | } 106 | 107 | // Not sure if WiFiClientSecure checks the validity date of the certificate. 108 | // Setting clock just to be sure... 109 | void setClock() 110 | { 111 | configTime(0, 0, "pool.ntp.org"); 112 | 113 | Serial.print(F("Waiting for NTP time sync: ")); 114 | time_t nowSecs = time(nullptr); 115 | 116 | while (nowSecs < 8 * 3600 * 2) 117 | { 118 | delay(500); 119 | Serial.print(F(".")); 120 | yield(); 121 | nowSecs = time(nullptr); 122 | } 123 | 124 | Serial.println(); 125 | struct tm timeinfo; 126 | gmtime_r(&nowSecs, &timeinfo); 127 | Serial.print(F("Current time: ")); 128 | Serial.print(asctime(&timeinfo)); 129 | } 130 | 131 | void setup() 132 | { 133 | // Open serial communications and wait for port to open: 134 | Serial.begin(115200); 135 | 136 | while (!Serial); 137 | 138 | // Using this if Serial debugging is not necessary or not using Serial port 139 | //while (!Serial && (millis() < 3000)); 140 | 141 | Serial.print("\nStarting WebClientMulti_SSL on " + String(ARDUINO_BOARD)); 142 | Serial.println(" with " + String(SHIELD_TYPE)); 143 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 144 | 145 | // To be called before ETH.begin() 146 | WT32_ETH01_onEvent(); 147 | 148 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 149 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 150 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 151 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 152 | 153 | // Static IP, leave without this line to get IP via DHCP 154 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 155 | ETH.config(myIP, myGW, mySN, myDNS); 156 | 157 | WT32_ETH01_waitForConnect(); 158 | 159 | setClock(); 160 | 161 | // give the Ethernet shield a second to initialize: 162 | delay(2000); 163 | 164 | // connect! 165 | connectSSL(); 166 | } 167 | 168 | #define BUFFER_SZ 2048 169 | 170 | byte buffer[BUFFER_SZ + 1]; 171 | 172 | void loop() 173 | { 174 | // if there are incoming bytes available 175 | // from the server, read them and print them: 176 | int len = sslClient.available(); 177 | 178 | if (len > 0) 179 | { 180 | if (len > BUFFER_SZ) 181 | len = BUFFER_SZ; 182 | 183 | sslClient.read(buffer, len); 184 | 185 | if (printWebData) 186 | { 187 | Serial.write(buffer, len); // show in the serial monitor (slows some boards) 188 | } 189 | 190 | byteCount = byteCount + len; 191 | } 192 | else 193 | { 194 | if (millis() - beginMillis > 10000) 195 | { 196 | Serial.print("LoopCount "); 197 | Serial.print(++loopCount); 198 | 199 | Serial.print(", Received "); 200 | Serial.print(byteCount); 201 | Serial.println(" bytes"); 202 | 203 | // Reset 204 | byteCount = 0; 205 | 206 | Serial.println("Disconnecting."); 207 | sslClient.stop(); 208 | } 209 | } 210 | 211 | // if the server's disconnected, stop the sslClient: 212 | if (!sslClient.connected()) 213 | { 214 | //quick delay 215 | delay(10000); 216 | 217 | // connect again! 218 | connectSSL(); 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /examples/SSL/WebClientMulti_SSL/certificates.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | certificates.h 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef _CERTIFICATES_H_ 14 | #define _CERTIFICATES_H_ 15 | 16 | // This is the root Certificate Authority that signed the server certifcate 17 | // for the demo server www.arduino.cc:443 in this example. 18 | // To generate the Root CA Cert, use the following command (in Linux / Ubuntu) 19 | // $ openssl s_client -showcerts -connect www.arduino.cc:443 20 | 21 | const char* rootCACertificate1 = 22 | "-----BEGIN CERTIFICATE-----\n" \ 23 | "MIIDzTCCArWgAwIBAgIQCjeHZF5ftIwiTv0b7RQMPDANBgkqhkiG9w0BAQsFADBa\n" \ 24 | "MQswCQYDVQQGEwJJRTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJl\n" \ 25 | "clRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTIw\n" \ 26 | "MDEyNzEyNDgwOFoXDTI0MTIzMTIzNTk1OVowSjELMAkGA1UEBhMCVVMxGTAXBgNV\n" \ 27 | "BAoTEENsb3VkZmxhcmUsIEluYy4xIDAeBgNVBAMTF0Nsb3VkZmxhcmUgSW5jIEVD\n" \ 28 | "QyBDQS0zMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEua1NZpkUC0bsH4HRKlAe\n" \ 29 | "nQMVLzQSfS2WuIg4m4Vfj7+7Te9hRsTJc9QkT+DuHM5ss1FxL2ruTAUJd9NyYqSb\n" \ 30 | "16OCAWgwggFkMB0GA1UdDgQWBBSlzjfq67B1DpRniLRF+tkkEIeWHzAfBgNVHSME\n" \ 31 | "GDAWgBTlnVkwgkdYzKz6CFQ2hns6tQRN8DAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0l\n" \ 32 | "BBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBIGA1UdEwEB/wQIMAYBAf8CAQAwNAYI\n" \ 33 | "KwYBBQUHAQEEKDAmMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2VydC5j\n" \ 34 | "b20wOgYDVR0fBDMwMTAvoC2gK4YpaHR0cDovL2NybDMuZGlnaWNlcnQuY29tL09t\n" \ 35 | "bmlyb290MjAyNS5jcmwwbQYDVR0gBGYwZDA3BglghkgBhv1sAQEwKjAoBggrBgEF\n" \ 36 | "BQcCARYcaHR0cHM6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzALBglghkgBhv1sAQIw\n" \ 37 | "CAYGZ4EMAQIBMAgGBmeBDAECAjAIBgZngQwBAgMwDQYJKoZIhvcNAQELBQADggEB\n" \ 38 | "AAUkHd0bsCrrmNaF4zlNXmtXnYJX/OvoMaJXkGUFvhZEOFp3ArnPEELG4ZKk40Un\n" \ 39 | "+ABHLGioVplTVI+tnkDB0A+21w0LOEhsUCxJkAZbZB2LzEgwLt4I4ptJIsCSDBFe\n" \ 40 | "lpKU1fwg3FZs5ZKTv3ocwDfjhUkV+ivhdDkYD7fa86JXWGBPzI6UAPxGezQxPk1H\n" \ 41 | "goE6y/SJXQ7vTQ1unBuCJN0yJV0ReFEQPaA1IwQvZW+cwdFD19Ae8zFnWSfda9J1\n" \ 42 | "CZMRJCQUzym+5iPDuI9yP+kHyCREU3qzuWFloUwOxkgAyXVjBYdwRVKD05WdRerw\n" \ 43 | "6DEdfgkfCv4+3ao8XnTSrLE=\n" \ 44 | "-----END CERTIFICATE-----\n"; 45 | 46 | // This is the root Certificate Authority that signed the server certifcate 47 | // for the demo server www.cloudflare.com:443 in this example. 48 | // To generate the Root CA Cert, use the following command (in Linux / Ubuntu) 49 | // $ openssl s_client -showcerts -connect www.cloudflare.com:443 50 | 51 | const char* rootCACertificate2 = 52 | "-----BEGIN CERTIFICATE-----\n" \ 53 | "MIIDzTCCArWgAwIBAgIQCjeHZF5ftIwiTv0b7RQMPDANBgkqhkiG9w0BAQsFADBa\n" \ 54 | "MQswCQYDVQQGEwJJRTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJl\n" \ 55 | "clRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTIw\n" \ 56 | "MDEyNzEyNDgwOFoXDTI0MTIzMTIzNTk1OVowSjELMAkGA1UEBhMCVVMxGTAXBgNV\n" \ 57 | "BAoTEENsb3VkZmxhcmUsIEluYy4xIDAeBgNVBAMTF0Nsb3VkZmxhcmUgSW5jIEVD\n" \ 58 | "QyBDQS0zMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEua1NZpkUC0bsH4HRKlAe\n" \ 59 | "nQMVLzQSfS2WuIg4m4Vfj7+7Te9hRsTJc9QkT+DuHM5ss1FxL2ruTAUJd9NyYqSb\n" \ 60 | "16OCAWgwggFkMB0GA1UdDgQWBBSlzjfq67B1DpRniLRF+tkkEIeWHzAfBgNVHSME\n" \ 61 | "GDAWgBTlnVkwgkdYzKz6CFQ2hns6tQRN8DAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0l\n" \ 62 | "BBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBIGA1UdEwEB/wQIMAYBAf8CAQAwNAYI\n" \ 63 | "KwYBBQUHAQEEKDAmMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2VydC5j\n" \ 64 | "b20wOgYDVR0fBDMwMTAvoC2gK4YpaHR0cDovL2NybDMuZGlnaWNlcnQuY29tL09t\n" \ 65 | "bmlyb290MjAyNS5jcmwwbQYDVR0gBGYwZDA3BglghkgBhv1sAQEwKjAoBggrBgEF\n" \ 66 | "BQcCARYcaHR0cHM6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzALBglghkgBhv1sAQIw\n" \ 67 | "CAYGZ4EMAQIBMAgGBmeBDAECAjAIBgZngQwBAgMwDQYJKoZIhvcNAQELBQADggEB\n" \ 68 | "AAUkHd0bsCrrmNaF4zlNXmtXnYJX/OvoMaJXkGUFvhZEOFp3ArnPEELG4ZKk40Un\n" \ 69 | "+ABHLGioVplTVI+tnkDB0A+21w0LOEhsUCxJkAZbZB2LzEgwLt4I4ptJIsCSDBFe\n" \ 70 | "lpKU1fwg3FZs5ZKTv3ocwDfjhUkV+ivhdDkYD7fa86JXWGBPzI6UAPxGezQxPk1H\n" \ 71 | "goE6y/SJXQ7vTQ1unBuCJN0yJV0ReFEQPaA1IwQvZW+cwdFD19Ae8zFnWSfda9J1\n" \ 72 | "CZMRJCQUzym+5iPDuI9yP+kHyCREU3qzuWFloUwOxkgAyXVjBYdwRVKD05WdRerw\n" \ 73 | "6DEdfgkfCv4+3ao8XnTSrLE=\n" \ 74 | "-----END CERTIFICATE-----\n"; 75 | 76 | #endif /* ifndef _CERTIFICATES_H_ */ 77 | -------------------------------------------------------------------------------- /examples/SSL/WebClient_SSL/WebClient_SSL.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebClient_SSL.ino - Dead simple SSL WebClient for Ethernet shields 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | // This sample sketch connects to SSL website (https://www.arduino.cc/asciilogo.txt) 14 | 15 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 16 | 17 | // Debug Level from 0 to 4 18 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 19 | 20 | #include 21 | 22 | #include 23 | 24 | // Select the IP address according to your local network 25 | IPAddress myIP(192, 168, 2, 232); 26 | IPAddress myGW(192, 168, 2, 1); 27 | IPAddress mySN(255, 255, 255, 0); 28 | 29 | // Google DNS Server IP 30 | IPAddress myDNS(8, 8, 8, 8); 31 | 32 | #include "certificates.h" 33 | 34 | const char server_host[] = "www.arduino.cc"; // leave this alone, change only above two 35 | const uint16_t server_port = 443; 36 | 37 | // Initialize the SSL client library 38 | WiFiClientSecure sslClient; 39 | 40 | // Variables to measure 41 | unsigned long beginMillis; 42 | unsigned long byteCount = 0; 43 | 44 | bool printWebData = true; // set to false for better speed measurement 45 | 46 | void connectSSL() 47 | { 48 | Serial.print("Connecting to "); 49 | Serial.print(server_host); 50 | Serial.println("..."); 51 | 52 | // if you get a connection, report back via serial: 53 | auto start = millis(); 54 | 55 | sslClient.setCACert(rootCACertificate1); 56 | 57 | if (sslClient.connect(server_host, server_port)) 58 | { 59 | auto time = millis() - start; 60 | 61 | Serial.print("Took: "); 62 | Serial.println(time); 63 | 64 | // Make a HTTP request: 65 | sslClient.println("GET /asciilogo.txt HTTP/1.1"); 66 | sslClient.println("User-Agent: SSLClientOverEthernet"); 67 | sslClient.print("Host: "); 68 | sslClient.println(server_host); 69 | sslClient.println("Connection: close"); 70 | sslClient.println(); 71 | sslClient.flush(); 72 | } 73 | else 74 | { 75 | // if you didn't get a connection to the server: 76 | Serial.println("connection failed"); 77 | } 78 | 79 | beginMillis = millis(); 80 | } 81 | 82 | // Not sure if WiFiClientSecure checks the validity date of the certificate. 83 | // Setting clock just to be sure... 84 | void setClock() 85 | { 86 | configTime(0, 0, "pool.ntp.org"); 87 | 88 | Serial.print(F("Waiting for NTP time sync: ")); 89 | time_t nowSecs = time(nullptr); 90 | 91 | while (nowSecs < 8 * 3600 * 2) 92 | { 93 | delay(500); 94 | Serial.print(F(".")); 95 | yield(); 96 | nowSecs = time(nullptr); 97 | } 98 | 99 | Serial.println(); 100 | struct tm timeinfo; 101 | gmtime_r(&nowSecs, &timeinfo); 102 | Serial.print(F("Current time: ")); 103 | Serial.print(asctime(&timeinfo)); 104 | } 105 | 106 | void setup() 107 | { 108 | // Open serial communications and wait for port to open: 109 | Serial.begin(115200); 110 | 111 | while (!Serial); 112 | 113 | // Using this if Serial debugging is not necessary or not using Serial port 114 | //while (!Serial && (millis() < 3000)); 115 | 116 | Serial.print("\nStarting WebClient_SSL on " + String(ARDUINO_BOARD)); 117 | Serial.println(" with " + String(SHIELD_TYPE)); 118 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 119 | 120 | // To be called before ETH.begin() 121 | WT32_ETH01_onEvent(); 122 | 123 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 124 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 125 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 126 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 127 | 128 | // Static IP, leave without this line to get IP via DHCP 129 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 130 | ETH.config(myIP, myGW, mySN, myDNS); 131 | 132 | WT32_ETH01_waitForConnect(); 133 | 134 | setClock(); 135 | 136 | // give the Ethernet shield a second to initialize: 137 | delay(2000); 138 | 139 | // connect! 140 | connectSSL(); 141 | } 142 | 143 | #define BUFFER_SZ 2048 144 | 145 | byte buffer[BUFFER_SZ + 1]; 146 | 147 | void loop() 148 | { 149 | // if there are incoming bytes available 150 | // from the server, read them and print them: 151 | int len = sslClient.available(); 152 | 153 | if (len > 0) 154 | { 155 | if (len > BUFFER_SZ) 156 | len = BUFFER_SZ; 157 | 158 | sslClient.read(buffer, len); 159 | 160 | if (printWebData) 161 | { 162 | Serial.write(buffer, len); // show in the serial monitor (slows some boards) 163 | } 164 | 165 | byteCount = byteCount + len; 166 | } 167 | else 168 | { 169 | if (millis() - beginMillis > 10000) 170 | { 171 | Serial.print("Received "); 172 | Serial.print(byteCount); 173 | Serial.println(" bytes"); 174 | 175 | // Reset 176 | byteCount = 0; 177 | 178 | Serial.println("Disconnecting."); 179 | sslClient.stop(); 180 | 181 | // do nothing forever: 182 | while (true) 183 | { 184 | delay(1); 185 | } 186 | } 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /examples/SSL/WebClient_SSL/certificates.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | certificates.h 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #ifndef _CERTIFICATES_H_ 14 | #define _CERTIFICATES_H_ 15 | 16 | // This is the root Certificate Authority that signed the server certifcate 17 | // for the demo server www.arduino.cc:443 in this example. 18 | // To generate the Root CA Cert, use the following command (in Linux / Ubuntu) 19 | // $ openssl s_client -showcerts -connect www.arduino.cc:443 20 | 21 | const char* rootCACertificate1 = 22 | "-----BEGIN CERTIFICATE-----\n" \ 23 | "MIIDzTCCArWgAwIBAgIQCjeHZF5ftIwiTv0b7RQMPDANBgkqhkiG9w0BAQsFADBa\n" \ 24 | "MQswCQYDVQQGEwJJRTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJl\n" \ 25 | "clRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTIw\n" \ 26 | "MDEyNzEyNDgwOFoXDTI0MTIzMTIzNTk1OVowSjELMAkGA1UEBhMCVVMxGTAXBgNV\n" \ 27 | "BAoTEENsb3VkZmxhcmUsIEluYy4xIDAeBgNVBAMTF0Nsb3VkZmxhcmUgSW5jIEVD\n" \ 28 | "QyBDQS0zMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEua1NZpkUC0bsH4HRKlAe\n" \ 29 | "nQMVLzQSfS2WuIg4m4Vfj7+7Te9hRsTJc9QkT+DuHM5ss1FxL2ruTAUJd9NyYqSb\n" \ 30 | "16OCAWgwggFkMB0GA1UdDgQWBBSlzjfq67B1DpRniLRF+tkkEIeWHzAfBgNVHSME\n" \ 31 | "GDAWgBTlnVkwgkdYzKz6CFQ2hns6tQRN8DAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0l\n" \ 32 | "BBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBIGA1UdEwEB/wQIMAYBAf8CAQAwNAYI\n" \ 33 | "KwYBBQUHAQEEKDAmMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2VydC5j\n" \ 34 | "b20wOgYDVR0fBDMwMTAvoC2gK4YpaHR0cDovL2NybDMuZGlnaWNlcnQuY29tL09t\n" \ 35 | "bmlyb290MjAyNS5jcmwwbQYDVR0gBGYwZDA3BglghkgBhv1sAQEwKjAoBggrBgEF\n" \ 36 | "BQcCARYcaHR0cHM6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzALBglghkgBhv1sAQIw\n" \ 37 | "CAYGZ4EMAQIBMAgGBmeBDAECAjAIBgZngQwBAgMwDQYJKoZIhvcNAQELBQADggEB\n" \ 38 | "AAUkHd0bsCrrmNaF4zlNXmtXnYJX/OvoMaJXkGUFvhZEOFp3ArnPEELG4ZKk40Un\n" \ 39 | "+ABHLGioVplTVI+tnkDB0A+21w0LOEhsUCxJkAZbZB2LzEgwLt4I4ptJIsCSDBFe\n" \ 40 | "lpKU1fwg3FZs5ZKTv3ocwDfjhUkV+ivhdDkYD7fa86JXWGBPzI6UAPxGezQxPk1H\n" \ 41 | "goE6y/SJXQ7vTQ1unBuCJN0yJV0ReFEQPaA1IwQvZW+cwdFD19Ae8zFnWSfda9J1\n" \ 42 | "CZMRJCQUzym+5iPDuI9yP+kHyCREU3qzuWFloUwOxkgAyXVjBYdwRVKD05WdRerw\n" \ 43 | "6DEdfgkfCv4+3ao8XnTSrLE=\n" \ 44 | "-----END CERTIFICATE-----\n"; 45 | 46 | #endif /* ifndef _CERTIFICATES_H_ */ 47 | -------------------------------------------------------------------------------- /examples/SimpleAuthentication/SimpleAuthentication.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | SimpleAuthentication.ino - Dead simple web-server for Ethernet shields 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 17 | 18 | #include 19 | 20 | WebServer server(80); 21 | 22 | // Select the IP address according to your local network 23 | IPAddress myIP(192, 168, 2, 232); 24 | IPAddress myGW(192, 168, 2, 1); 25 | IPAddress mySN(255, 255, 255, 0); 26 | 27 | // Google DNS Server IP 28 | IPAddress myDNS(8, 8, 8, 8); 29 | 30 | //Check if header is present and correct 31 | bool is_authenticated() 32 | { 33 | Serial.println(F("Enter is_authenticated")); 34 | 35 | if (server.hasHeader(F("Cookie"))) 36 | { 37 | Serial.print(F("Found cookie: ")); 38 | String cookie = server.header(F("Cookie")); 39 | Serial.println(cookie); 40 | 41 | if (cookie.indexOf(F("ESPSESSIONID=1")) != -1) 42 | { 43 | Serial.println(F("Authentication Successful")); 44 | return true; 45 | } 46 | } 47 | 48 | Serial.println(F("Authentication Failed")); 49 | return false; 50 | } 51 | 52 | //login page, also called for disconnect 53 | void handleLogin() 54 | { 55 | String msg; 56 | 57 | if (server.hasHeader(F("Cookie"))) 58 | { 59 | Serial.print(F("Found cookie: ")); 60 | String cookie = server.header(F("Cookie")); 61 | Serial.println(cookie); 62 | } 63 | 64 | if (server.hasArg(F("DISCONNECT"))) 65 | { 66 | Serial.println(F("Disconnection")); 67 | server.sendHeader(F("Location"), F("/login")); 68 | server.sendHeader(F("Cache-Control"), F("no-cache")); 69 | server.sendHeader(F("Set-Cookie"), F("ESPSESSIONID=0")); 70 | server.send(301); 71 | return; 72 | } 73 | 74 | if (server.hasArg(F("USERNAME")) && server.hasArg(F("PASSWORD"))) 75 | { 76 | if (server.arg(F("USERNAME")) == F("admin") && server.arg(F("PASSWORD")) == F("password")) 77 | { 78 | server.sendHeader(F("Location"), F("/")); 79 | server.sendHeader(F("Cache-Control"), F("no-cache")); 80 | server.sendHeader(F("Set-Cookie"), F("ESPSESSIONID=1")); 81 | server.send(301); 82 | Serial.println(F("Log in Successful")); 83 | return; 84 | } 85 | 86 | msg = F("Wrong username/password! try again."); 87 | Serial.println(F("Log in Failed")); 88 | } 89 | 90 | String content = F("
To log in, please use : admin/password
"); 91 | content += F("User:
"); 92 | content += F("Password:
"); 93 | content += F("
"); 94 | content += msg; 95 | content += F("
"); 96 | content += F("You also can go here"); 97 | server.send(200, F("text/html"), content); 98 | } 99 | 100 | //root page can be accessed only if authentication is ok 101 | void handleRoot() 102 | { 103 | String header; 104 | 105 | Serial.println(F("Enter handleRoot")); 106 | 107 | if (!is_authenticated()) 108 | { 109 | server.sendHeader(F("Location"), F("/login")); 110 | server.sendHeader(F("Cache-Control"), F("no-cache")); 111 | server.send(301); 112 | return; 113 | } 114 | 115 | String content = F("

Hello, you're connected to WebServer_WT32_ETH01 running on "); 116 | 117 | content += String(BOARD_NAME); 118 | content += F("!


"); 119 | 120 | if (server.hasHeader(F("User-Agent"))) 121 | { 122 | content += F("the user agent used is : "); 123 | content += server.header(F("User-Agent")); 124 | content += F("

"); 125 | } 126 | 127 | content += F("You can access this page until you disconnect"); 128 | server.send(200, F("text/html"), content); 129 | } 130 | 131 | //no need authentication 132 | void handleNotFound() 133 | { 134 | String message = F("File Not Found\n\n"); 135 | 136 | message += F("URI: "); 137 | message += server.uri(); 138 | message += F("\nMethod: "); 139 | message += (server.method() == HTTP_GET) ? F("GET") : F("POST"); 140 | message += F("\nArguments: "); 141 | message += server.args(); 142 | message += F("\n"); 143 | 144 | for (uint8_t i = 0; i < server.args(); i++) 145 | { 146 | message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; 147 | } 148 | 149 | server.send(404, F("text/plain"), message); 150 | } 151 | 152 | void setup() 153 | { 154 | Serial.begin(115200); 155 | 156 | while (!Serial); 157 | 158 | // Using this if Serial debugging is not necessary or not using Serial port 159 | //while (!Serial && (millis() < 3000)); 160 | 161 | Serial.print("\nStarting SimpleAuthentication on " + String(ARDUINO_BOARD)); 162 | Serial.println(" with " + String(SHIELD_TYPE)); 163 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 164 | 165 | // To be called before ETH.begin() 166 | WT32_ETH01_onEvent(); 167 | 168 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 169 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 170 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 171 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 172 | 173 | // Static IP, leave without this line to get IP via DHCP 174 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 175 | ETH.config(myIP, myGW, mySN, myDNS); 176 | 177 | WT32_ETH01_waitForConnect(); 178 | 179 | server.on(F("/"), handleRoot); 180 | 181 | server.on(F("/login"), handleLogin); 182 | 183 | server.on(F("/inline"), []() 184 | { 185 | server.send(200, F("text/plain"), F("This works without need of authentication")); 186 | }); 187 | 188 | server.onNotFound(handleNotFound); 189 | 190 | //here the list of headers to be recorded 191 | const char * headerkeys[] = {"User-Agent", "Cookie"} ; 192 | size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*); 193 | 194 | //ask server to track these headers 195 | server.collectHeaders(headerkeys, headerkeyssize); 196 | server.begin(); 197 | 198 | Serial.print(F("HTTP SimpleAuthentication is @ IP : ")); 199 | Serial.println(ETH.localIP()); 200 | } 201 | 202 | void loop() 203 | { 204 | server.handleClient(); 205 | } 206 | -------------------------------------------------------------------------------- /examples/UdpNTPClient/UdpNTPClient.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | UdpNTPClient.ino - Simple Arduino web server sample for ESP8266 AT-command shield 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | /* 13 | The Arduino board communicates with the shield using the SPI bus. This is on digital pins 11, 12, and 13 on the Uno 14 | and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used as SS. On the Mega, the hardware SS pin, 53, 15 | is not used to select the Ethernet controller chip, but it must be kept as an output or the SPI interface won't work. 16 | */ 17 | 18 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 19 | 20 | // Debug Level from 0 to 4 21 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 22 | 23 | #include 24 | 25 | // Select the IP address according to your local network 26 | IPAddress myIP(192, 168, 2, 232); 27 | IPAddress myGW(192, 168, 2, 1); 28 | IPAddress mySN(255, 255, 255, 0); 29 | 30 | // Google DNS Server IP 31 | IPAddress myDNS(8, 8, 8, 8); 32 | 33 | char timeServer[] = "time.nist.gov"; // NTP server 34 | unsigned int localPort = 2390; // local port to listen for UDP packets 35 | 36 | const int NTP_PACKET_SIZE = 48; // NTP timestamp is in the first 48 bytes of the message 37 | const int UDP_TIMEOUT = 2000; // timeout in miliseconds to wait for an UDP packet to arrive 38 | 39 | byte packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming and outgoing packets 40 | 41 | // A UDP instance to let us send and receive packets over UDP 42 | WiFiUDP Udp; 43 | 44 | // send an NTP request to the time server at the given address 45 | void sendNTPpacket(char *ntpSrv) 46 | { 47 | // set all bytes in the buffer to 0 48 | memset(packetBuffer, 0, NTP_PACKET_SIZE); 49 | // Initialize values needed to form NTP request 50 | // (see URL above for details on the packets) 51 | 52 | packetBuffer[0] = 0b11100011; // LI, Version, Mode 53 | packetBuffer[1] = 0; // Stratum, or type of clock 54 | packetBuffer[2] = 6; // Polling Interval 55 | packetBuffer[3] = 0xEC; // Peer Clock Precision 56 | // 8 bytes of zero for Root Delay & Root Dispersion 57 | packetBuffer[12] = 49; 58 | packetBuffer[13] = 0x4E; 59 | packetBuffer[14] = 49; 60 | packetBuffer[15] = 52; 61 | 62 | // all NTP fields have been given values, now 63 | // you can send a packet requesting a timestamp: 64 | Udp.beginPacket(ntpSrv, 123); //NTP requests are to port 123 65 | 66 | Udp.write(packetBuffer, NTP_PACKET_SIZE); 67 | 68 | Udp.endPacket(); 69 | } 70 | 71 | void setup() 72 | { 73 | Serial.begin(115200); 74 | 75 | while (!Serial); 76 | 77 | // Using this if Serial debugging is not necessary or not using Serial port 78 | //while (!Serial && (millis() < 3000)); 79 | 80 | Serial.print("\nStarting UdpNTPClient on " + String(ARDUINO_BOARD)); 81 | Serial.println(" with " + String(SHIELD_TYPE)); 82 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 83 | 84 | // To be called before ETH.begin() 85 | WT32_ETH01_onEvent(); 86 | 87 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 88 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 89 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 90 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 91 | 92 | // Static IP, leave without this line to get IP via DHCP 93 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 94 | ETH.config(myIP, myGW, mySN, myDNS); 95 | 96 | WT32_ETH01_waitForConnect(); 97 | 98 | Udp.begin(localPort); 99 | } 100 | 101 | void loop() 102 | { 103 | sendNTPpacket(timeServer); // send an NTP packet to a time server 104 | 105 | // wait for a reply for UDP_TIMEOUT miliseconds 106 | unsigned long startMs = millis(); 107 | 108 | while (!Udp.available() && (millis() - startMs) < UDP_TIMEOUT) {} 109 | 110 | // if there's data available, read a packet 111 | int packetSize = Udp.parsePacket(); 112 | 113 | if (packetSize) 114 | { 115 | Serial.print(F("UDP Packet received, size ")); 116 | Serial.println(packetSize); 117 | Serial.print(F("From ")); 118 | IPAddress remoteIp = Udp.remoteIP(); 119 | Serial.print(remoteIp); 120 | Serial.print(F(", port ")); 121 | Serial.println(Udp.remotePort()); 122 | 123 | // We've received a packet, read the data from it into the buffer 124 | Udp.read(packetBuffer, NTP_PACKET_SIZE); 125 | 126 | // the timestamp starts at byte 40 of the received packet and is four bytes, 127 | // or two words, long. First, esxtract the two words: 128 | 129 | unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); 130 | unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); 131 | 132 | // combine the four bytes (two words) into a long integer 133 | // this is NTP time (seconds since Jan 1 1900): 134 | unsigned long secsSince1900 = highWord << 16 | lowWord; 135 | 136 | Serial.print(F("Seconds since Jan 1 1900 = ")); 137 | Serial.println(secsSince1900); 138 | 139 | // now convert NTP time into )everyday time: 140 | Serial.print(F("Unix time = ")); 141 | // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: 142 | const unsigned long seventyYears = 2208988800UL; 143 | // subtract seventy years: 144 | unsigned long epoch = secsSince1900 - seventyYears; 145 | // print Unix time: 146 | Serial.println(epoch); 147 | 148 | // print the hour, minute and second: 149 | Serial.print(F("The UTC time is ")); // UTC is the time at Greenwich Meridian (GMT) 150 | Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) 151 | Serial.print(F(":")); 152 | 153 | if (((epoch % 3600) / 60) < 10) 154 | { 155 | // In the first 10 minutes of each hour, we'll want a leading '0' 156 | Serial.print(F("0")); 157 | } 158 | 159 | Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) 160 | Serial.print(F(":")); 161 | 162 | if ((epoch % 60) < 10) 163 | { 164 | // In the first 10 seconds of each minute, we'll want a leading '0' 165 | Serial.print(F("0")); 166 | } 167 | 168 | Serial.println(epoch % 60); // print the second 169 | } 170 | 171 | // wait ten seconds before asking for the time again 172 | delay(10000); 173 | } 174 | -------------------------------------------------------------------------------- /examples/UdpSendReceive/UdpSendReceive.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | UDPSendReceive.ino - Simple Arduino web server sample for ESP8266/ESP32 AT-command shield 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 17 | 18 | #include 19 | 20 | // Select the IP address according to your local network 21 | IPAddress myIP(192, 168, 2, 232); 22 | IPAddress myGW(192, 168, 2, 1); 23 | IPAddress mySN(255, 255, 255, 0); 24 | 25 | // Google DNS Server IP 26 | IPAddress myDNS(8, 8, 8, 8); 27 | 28 | unsigned int localPort = 1883; //10002; // local port to listen on 29 | 30 | char packetBuffer[255]; // buffer to hold incoming packet 31 | byte ReplyBuffer[] = "ACK"; // a string to send back 32 | 33 | // A UDP instance to let us send and receive packets over UDP 34 | WiFiUDP Udp; 35 | 36 | void setup() 37 | { 38 | Serial.begin(115200); 39 | 40 | while (!Serial); 41 | 42 | // Using this if Serial debugging is not necessary or not using Serial port 43 | //while (!Serial && (millis() < 3000)); 44 | 45 | Serial.print("\nStarting UDPSendReceive on " + String(ARDUINO_BOARD)); 46 | Serial.println(" with " + String(SHIELD_TYPE)); 47 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 48 | 49 | // To be called before ETH.begin() 50 | WT32_ETH01_onEvent(); 51 | 52 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 53 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 54 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 55 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 56 | 57 | // Static IP, leave without this line to get IP via DHCP 58 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 59 | ETH.config(myIP, myGW, mySN, myDNS); 60 | 61 | WT32_ETH01_waitForConnect(); 62 | 63 | Serial.println(F("\nStarting connection to server...")); 64 | // if you get a connection, report back via serial: 65 | Udp.begin(localPort); 66 | 67 | Serial.print(F("Listening on port ")); 68 | Serial.println(localPort); 69 | } 70 | 71 | void loop() 72 | { 73 | // if there's data available, read a packet 74 | int packetSize = Udp.parsePacket(); 75 | 76 | if (packetSize) 77 | { 78 | Serial.print(F("Received packet of size ")); 79 | Serial.println(packetSize); 80 | Serial.print(F("From ")); 81 | IPAddress remoteIp = Udp.remoteIP(); 82 | Serial.print(remoteIp); 83 | Serial.print(F(", port ")); 84 | Serial.println(Udp.remotePort()); 85 | 86 | // read the packet into packetBufffer 87 | int len = Udp.read(packetBuffer, 255); 88 | 89 | if (len > 0) 90 | { 91 | packetBuffer[len] = 0; 92 | } 93 | 94 | Serial.println(F("Contents:")); 95 | Serial.println(packetBuffer); 96 | 97 | // send a reply, to the IP address and port that sent us the packet we received 98 | Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); 99 | Udp.write(ReplyBuffer, sizeof(ReplyBuffer)); 100 | Udp.endPacket(); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /examples/WebClient/WebClient.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebClient.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 14 | 15 | // Debug Level from 0 to 4 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 17 | 18 | #include 19 | 20 | // Select the IP address according to your local network 21 | IPAddress myIP(192, 168, 2, 232); 22 | IPAddress myGW(192, 168, 2, 1); 23 | IPAddress mySN(255, 255, 255, 0); 24 | 25 | // Google DNS Server IP 26 | IPAddress myDNS(8, 8, 8, 8); 27 | 28 | char server[] = "arduino.cc"; 29 | 30 | // Initialize the Ethernet client object 31 | WiFiClient client; 32 | 33 | void setup() 34 | { 35 | Serial.begin(115200); 36 | 37 | while (!Serial); 38 | 39 | // Using this if Serial debugging is not necessary or not using Serial port 40 | //while (!Serial && (millis() < 3000)); 41 | 42 | Serial.print("\nStarting WebClient on " + String(ARDUINO_BOARD)); 43 | Serial.println(" with " + String(SHIELD_TYPE)); 44 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 45 | 46 | // To be called before ETH.begin() 47 | WT32_ETH01_onEvent(); 48 | 49 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 50 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 51 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 52 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 53 | 54 | // Static IP, leave without this line to get IP via DHCP 55 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 56 | ETH.config(myIP, myGW, mySN, myDNS); 57 | 58 | WT32_ETH01_waitForConnect(); 59 | 60 | Serial.println(); 61 | Serial.println(F("Starting connection to server...")); 62 | 63 | // if you get a connection, report back via serial 64 | if (client.connect(server, 80)) 65 | { 66 | Serial.println(F("Connected to server")); 67 | // Make a HTTP request 68 | client.println(F("GET /asciilogo.txt HTTP/1.1")); 69 | client.println(F("Host: arduino.cc")); 70 | client.println(F("Connection: close")); 71 | client.println(); 72 | } 73 | } 74 | 75 | void printoutData() 76 | { 77 | // if there are incoming bytes available 78 | // from the server, read them and print them 79 | while (client.available()) 80 | { 81 | char c = client.read(); 82 | Serial.write(c); 83 | Serial.flush(); 84 | } 85 | } 86 | 87 | void loop() 88 | { 89 | printoutData(); 90 | 91 | // if the server's disconnected, stop the client 92 | if (!client.connected()) 93 | { 94 | Serial.println(); 95 | Serial.println(F("Disconnecting from server...")); 96 | client.stop(); 97 | 98 | // do nothing forevermore 99 | while (true) 100 | yield(); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /examples/WebClientRepeating/WebClientRepeating.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebClientRepeating.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | /* 13 | The Arduino board communicates with the shield using the SPI bus. This is on digital pins 11, 12, and 13 on the Uno 14 | and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used as SS. On the Mega, the hardware SS pin, 53, 15 | is not used to select the Ethernet controller chip, but it must be kept as an output or the SPI interface won't work. 16 | */ 17 | 18 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 19 | 20 | // Debug Level from 0 to 4 21 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 22 | 23 | #include 24 | 25 | // Select the IP address according to your local network 26 | IPAddress myIP(192, 168, 2, 232); 27 | IPAddress myGW(192, 168, 2, 1); 28 | IPAddress mySN(255, 255, 255, 0); 29 | 30 | // Google DNS Server IP 31 | IPAddress myDNS(8, 8, 8, 8); 32 | 33 | char server[] = "arduino.cc"; 34 | 35 | unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 36 | const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds 37 | 38 | // Initialize the Web client object 39 | WiFiClient client; 40 | 41 | // this method makes a HTTP connection to the server 42 | void httpRequest() 43 | { 44 | Serial.println(); 45 | 46 | // close any connection before send a new request 47 | // this will free the socket on the WiFi shield 48 | client.stop(); 49 | 50 | // if there's a successful connection 51 | if (client.connect(server, 80)) 52 | { 53 | Serial.println(F("Connecting...")); 54 | 55 | // send the HTTP PUT request 56 | client.println(F("GET /asciilogo.txt HTTP/1.1")); 57 | client.println(F("Host: arduino.cc")); 58 | client.println(F("Connection: close")); 59 | client.println(); 60 | 61 | // note the time that the connection was made 62 | lastConnectionTime = millis(); 63 | } 64 | else 65 | { 66 | // if you couldn't make a connection 67 | Serial.println(F("Connection failed")); 68 | } 69 | } 70 | 71 | void setup() 72 | { 73 | Serial.begin(115200); 74 | 75 | while (!Serial); 76 | 77 | // Using this if Serial debugging is not necessary or not using Serial port 78 | //while (!Serial && (millis() < 3000)); 79 | 80 | Serial.print("\nStarting WebClientRepeating on " + String(ARDUINO_BOARD)); 81 | Serial.println(" with " + String(SHIELD_TYPE)); 82 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 83 | 84 | // To be called before ETH.begin() 85 | WT32_ETH01_onEvent(); 86 | 87 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 88 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 89 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 90 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 91 | 92 | // Static IP, leave without this line to get IP via DHCP 93 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 94 | ETH.config(myIP, myGW, mySN, myDNS); 95 | 96 | WT32_ETH01_waitForConnect(); 97 | } 98 | 99 | void loop() 100 | { 101 | // if there's incoming data from the net connection send it out the serial port 102 | // this is for debugging purposes only 103 | while (client.available()) 104 | { 105 | char c = client.read(); 106 | Serial.write(c); 107 | Serial.flush(); 108 | } 109 | 110 | // if 10 seconds have passed since your last connection, 111 | // then connect again and send data 112 | if (millis() - lastConnectionTime > postingInterval) 113 | { 114 | httpRequest(); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /examples/WebServer/WebServer.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebServer.ino - Simple Arduino web server sample for Ethernet shield 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | *****************************************************************************************************************************/ 12 | 13 | 14 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 15 | 16 | // Debug Level from 0 to 4 17 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 18 | 19 | #include 20 | 21 | WiFiServer server(80); 22 | 23 | // Select the IP address according to your local network 24 | IPAddress myIP(192, 168, 2, 232); 25 | IPAddress myGW(192, 168, 2, 1); 26 | IPAddress mySN(255, 255, 255, 0); 27 | 28 | // Google DNS Server IP 29 | IPAddress myDNS(8, 8, 8, 8); 30 | 31 | int reqCount = 0; // number of requests received 32 | 33 | void setup() 34 | { 35 | Serial.begin(115200); 36 | 37 | while (!Serial); 38 | 39 | // Using this if Serial debugging is not necessary or not using Serial port 40 | //while (!Serial && (millis() < 3000)); 41 | 42 | Serial.print("\nStarting WebServer on " + String(ARDUINO_BOARD)); 43 | Serial.println(" with " + String(SHIELD_TYPE)); 44 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 45 | 46 | // To be called before ETH.begin() 47 | WT32_ETH01_onEvent(); 48 | 49 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 50 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 51 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 52 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 53 | 54 | // Static IP, leave without this line to get IP via DHCP 55 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 56 | ETH.config(myIP, myGW, mySN, myDNS); 57 | 58 | WT32_ETH01_waitForConnect(); 59 | 60 | // start the web server on port 80 61 | server.begin(); 62 | } 63 | 64 | void loop() 65 | { 66 | // listen for incoming clients 67 | WiFiClient client = server.available(); 68 | 69 | if (client) 70 | { 71 | Serial.println(F("New client")); 72 | // an http request ends with a blank line 73 | bool currentLineIsBlank = true; 74 | 75 | while (client.connected()) 76 | { 77 | if (client.available()) 78 | { 79 | char c = client.read(); 80 | Serial.write(c); 81 | 82 | // if you've gotten to the end of the line (received a newline 83 | // character) and the line is blank, the http request has ended, 84 | // so you can send a reply 85 | if (c == '\n' && currentLineIsBlank) 86 | { 87 | Serial.println(F("Sending response")); 88 | 89 | // send a standard http response header 90 | // use \r\n instead of many println statements to speedup data send 91 | client.print( 92 | "HTTP/1.1 200 OK\r\n" 93 | "Content-Type: text/html\r\n" 94 | "Connection: close\r\n" // the connection will be closed after completion of the response 95 | "Refresh: 20\r\n" // refresh the page automatically every 20 sec 96 | "\r\n"); 97 | client.print("\r\n"); 98 | client.print("\r\n"); 99 | client.print(String("

Hello World from ") + BOARD_NAME + "!

\r\n"); 100 | client.print("Requests received: "); 101 | client.print(++reqCount); 102 | client.print("
\r\n"); 103 | client.print("
\r\n"); 104 | client.print("\r\n"); 105 | break; 106 | } 107 | 108 | if (c == '\n') 109 | { 110 | // you're starting a new line 111 | currentLineIsBlank = true; 112 | } 113 | else if (c != '\r') 114 | { 115 | // you've gotten a character on the current line 116 | currentLineIsBlank = false; 117 | } 118 | } 119 | } 120 | 121 | // give the web browser time to receive the data 122 | delay(10); 123 | 124 | // close the connection: 125 | client.stop(); 126 | Serial.println(F("Client disconnected")); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /examples/multiFileProject/multiFileProject.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | multiFileProject.cpp 3 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 4 | 5 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | 12 | // To demo how to include files in multi-file Projects 13 | 14 | #include "multiFileProject.h" 15 | -------------------------------------------------------------------------------- /examples/multiFileProject/multiFileProject.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | multiFileProject.h 3 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 4 | 5 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | 12 | // To demo how to include files in multi-file Projects 13 | 14 | #pragma once 15 | 16 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 1 17 | 18 | // Can be included as many times as necessary, without `Multiple Definitions` Linker Error 19 | #include "WebServer_WT32_ETH01.hpp" 20 | -------------------------------------------------------------------------------- /examples/multiFileProject/multiFileProject.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | multiFileProject.ino 3 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 4 | 5 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 9 | Licensed under MIT license 10 | *****************************************************************************************************************************/ 11 | 12 | // To demo how to include files in multi-file Projects 13 | 14 | #include "multiFileProject.h" 15 | 16 | // Can be included as many times as necessary, without `Multiple Definitions` Linker Error 17 | #include "WebServer_WT32_ETH01.h" 18 | 19 | void setup() 20 | { 21 | Serial.begin(115200); 22 | 23 | while (!Serial); 24 | 25 | delay(500); 26 | 27 | Serial.println("\nStart multiFileProject"); 28 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 29 | 30 | 31 | Serial.print("You're OK now"); 32 | } 33 | 34 | void loop() 35 | { 36 | // put your main code here, to run repeatedly: 37 | } 38 | -------------------------------------------------------------------------------- /examples/serveStatic/data/page1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Hello from Ethernet HTTP Web Server ESP8266/ESP32 - Page1 10 | 11 | 12 | 13 |
14 |

ESP8266/ESP32 Ethernet HTTP Web Server

15 |

Hello from ESP8266/ESP32 Ethernet HTTP Web Server. This is Page1.

16 |

17 | Page1 18 | Page2 19 | Page3 20 |

21 | 22 |

Copyright (C) 2019 Arduino Slovakia.

23 |

Copyright (C) 2021 Sardar Azari.

24 |
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/serveStatic/data/page2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Hello from Ethernet HTTP Web Server ESP8266/ESP32 - Page2 10 | 11 | 12 | 13 |
14 |

ESP8266/ESP32 Ethernet HTTP Web Server

15 |

Hello from ESP8266/ESP32 Ethernet HTTP Web Server. This is Page2.

16 |

17 | Page1 18 | Page2 19 | Page3 20 |

21 | 22 |

Copyright (C) 2019 Arduino Slovakia.

23 |

Copyright (C) 2021 Sardar Azari.

24 |
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/serveStatic/data/page3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Hello from Ethernet HTTP Web Server ESP8266/ESP32 - Page3 10 | 11 | 12 | 13 |
14 |

ESP8266/ESP32 Ethernet HTTP Web Server

15 |

Hello from ESP8266/ESP32 Ethernet HTTP Web Server. This is Page3.

16 |

17 | Page1 18 | Page2 19 | Page3 20 |

21 | 22 |

Copyright (C) 2019 Arduino Slovakia.

23 |

Copyright (C) 2021 Sardar Azari.

24 |
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/serveStatic/serveStatic.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | serveStatic.ino - Dead simple web-server for Ethernet shields 3 | demoing the usage of serveStatic class method 4 | v. 1.0 5 | Copyright (C) 2021 Sardar Azari 6 | https://www.qrz.com/db/ac8l 7 | 8 | Prior to the usage - use ESP8266/ESP32 Sketch data upoad tool to save the content of web-site to the SPIFFS flash memory. 9 | 10 | This example sketch is based on HTML templates from Robert Ulbricht: https://www.arduinoslovakia.eu 11 | https://github.com/RoboUlbricht/arduinoslovakia/tree/master/esp8266/simple_http_server_multiplepages_responsive_spiffs 12 | 13 | This code's core is based on HelloServer.ino example of this library by Khoi Hoang 14 | 15 | Some great examples of commercial use of serveStatic function can be seen and learned at uStepper's WiFiGUI project: 16 | https://github.com/uStepper/uStepperSWiFiGUI 17 | 18 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 19 | 20 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 21 | 22 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 23 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 24 | Licensed under MIT license 25 | *****************************************************************************************************************************/ 26 | 27 | /***************************************************************************************************************************** 28 | How To Use: 29 | 1) Run the serveStaticLoadFile.ino 30 | 2) Upload the contents of a folder if you changedir in that folder and run the following command: 31 | for file in `\ls -A1`; do curl -F "file=@$PWD/$file" localIPAddress/edit; done 32 | 3) access the sample web page at http://localIPAddress/ 33 | *****************************************************************************************************************************/ 34 | 35 | #define DEBUG_ETHERNET_WEBSERVER_PORT Serial 36 | 37 | // Debug Level from 0 to 4 38 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 3 39 | 40 | // LittleFS has higher priority than SPIFFS 41 | #if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) ) 42 | #define USE_LITTLEFS true 43 | #define USE_SPIFFS false 44 | #elif defined(ARDUINO_ESP32C3_DEV) 45 | // For core v1.0.6-, ESP32-C3 only supporting SPIFFS and EEPROM. To use v2.0.0+ for LittleFS 46 | #define USE_LITTLEFS false 47 | #define USE_SPIFFS true 48 | #endif 49 | 50 | #if USE_LITTLEFS 51 | // Use LittleFS 52 | #include "FS.h" 53 | 54 | // Check cores/esp32/esp_arduino_version.h and cores/esp32/core_version.h 55 | //#if ( ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0) ) //(ESP_ARDUINO_VERSION_MAJOR >= 2) 56 | #if ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) ) 57 | #if (_WIFIMGR_LOGLEVEL_ > 3) 58 | #warning Using ESP32 Core 1.0.6 or 2.0.0+ 59 | #endif 60 | 61 | // The library has been merged into esp32 core from release 1.0.6 62 | #include // https://github.com/espressif/arduino-esp32/tree/master/libraries/LittleFS 63 | 64 | FS* filesystem = &LittleFS; 65 | #define FileFS LittleFS 66 | #define FS_Name "LittleFS" 67 | #else 68 | #if (_WIFIMGR_LOGLEVEL_ > 3) 69 | #warning Using ESP32 Core 1.0.5-. You must install LITTLEFS library 70 | #endif 71 | 72 | // The library has been merged into esp32 core from release 1.0.6 73 | #include // https://github.com/lorol/LITTLEFS 74 | 75 | FS* filesystem = &LITTLEFS; 76 | #define FileFS LITTLEFS 77 | #define FS_Name "LittleFS" 78 | #endif 79 | 80 | #elif USE_SPIFFS 81 | #include 82 | FS* filesystem = &SPIFFS; 83 | #define FileFS SPIFFS 84 | #define FS_Name "SPIFFS" 85 | #else 86 | // Use FFat 87 | #include 88 | FS* filesystem = &FFat; 89 | #define FileFS FFat 90 | #define FS_Name "FFat" 91 | #endif 92 | 93 | #include 94 | 95 | WebServer server(80); 96 | 97 | // Select the IP address according to your local network 98 | IPAddress myIP(192, 168, 2, 232); 99 | IPAddress myGW(192, 168, 2, 1); 100 | IPAddress mySN(255, 255, 255, 0); 101 | 102 | // Google DNS Server IP 103 | IPAddress myDNS(8, 8, 8, 8); 104 | 105 | void initFS() 106 | { 107 | // Initialize LittleFS/SPIFFS file-system 108 | #if (ESP32) 109 | // Format SPIFFS if not yet 110 | if (!FileFS.begin(true)) 111 | { 112 | Serial.println(F("SPIFFS/LittleFS failed! Formatting.")); 113 | #else 114 | 115 | if (!FileFS.begin()) 116 | { 117 | FileFS.format(); 118 | #endif 119 | 120 | if (!FileFS.begin()) 121 | { 122 | while (true) 123 | { 124 | #if USE_LITTLEFS 125 | Serial.println(F("LittleFS failed!. Please use SPIFFS.")); 126 | #else 127 | Serial.println(F("SPIFFS failed!. Please use LittleFS.")); 128 | #endif 129 | // Stay forever here as useless to go further 130 | delay(5000); 131 | } 132 | } 133 | } 134 | } 135 | 136 | void initWebserver() 137 | { 138 | 139 | // Web Page handlers 140 | server.serveStatic("/", FileFS, "/page1.html"); 141 | server.serveStatic("/page2", FileFS, "/page2.html"); 142 | server.serveStatic("/page3", FileFS, "/page3.html"); 143 | 144 | // Other usage with various web site assets: 145 | // server.serveStatic("/assets/css/test.css", SPIFFS, "/assets/css/test.css"); // Style sheet 146 | // server.serveStatic("/assets/js/test_script.js", SPIFFS,"/assets/js/test_script.js"); // Javascript 147 | // server.serveStatic("/assets/font/fonticons.ttf", SPIFFS,"/assets/font/fonticons.ttf"); // font 148 | // server.serveStatic("/assets/picture.png", SPIFFS,"/assets/picture.png"); // Picture 149 | 150 | server.begin(); 151 | } 152 | 153 | void setup() 154 | { 155 | Serial.begin(115200); 156 | 157 | while (!Serial); 158 | 159 | // Using this if Serial debugging is not necessary or not using Serial port 160 | //while (!Serial && (millis() < 3000)); 161 | 162 | Serial.print("\nStarting serveStatic demoing 'serveStatic' function on " + String(ARDUINO_BOARD)); 163 | Serial.print(" using "); 164 | Serial.println(FS_Name); 165 | Serial.println("With " + String(SHIELD_TYPE)); 166 | Serial.println(WEBSERVER_WT32_ETH01_VERSION); 167 | 168 | // To be called before ETH.begin() 169 | WT32_ETH01_onEvent(); 170 | 171 | //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, 172 | // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); 173 | //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); 174 | ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); 175 | 176 | // Static IP, leave without this line to get IP via DHCP 177 | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); 178 | ETH.config(myIP, myGW, mySN, myDNS); 179 | 180 | WT32_ETH01_waitForConnect(); 181 | 182 | initFS(); 183 | initWebserver(); 184 | 185 | Serial.println("HTTP server started"); 186 | } 187 | 188 | void loop() 189 | { 190 | server.handleClient(); 191 | } 192 | -------------------------------------------------------------------------------- /examples/serveStaticLoadFile/data/page1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Hello from Ethernet HTTP Web Server ESP8266/ESP32 - Page1 10 | 11 | 12 | 13 |
14 |

ESP8266/ESP32 Ethernet HTTP Web Server

15 |

Hello from ESP8266/ESP32 Ethernet HTTP Web Server. This is Page1.

16 |

17 | Page1 18 | Page2 19 | Page3 20 |

21 | 22 |

Copyright (C) 2019 Arduino Slovakia.

23 |

Copyright (C) 2021 Sardar Azari.

24 |
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/serveStaticLoadFile/data/page2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Hello from Ethernet HTTP Web Server ESP8266/ESP32 - Page2 10 | 11 | 12 | 13 |
14 |

ESP8266/ESP32 Ethernet HTTP Web Server

15 |

Hello from ESP8266/ESP32 Ethernet HTTP Web Server. This is Page2.

16 |

17 | Page1 18 | Page2 19 | Page3 20 |

21 | 22 |

Copyright (C) 2019 Arduino Slovakia.

23 |

Copyright (C) 2021 Sardar Azari.

24 |
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/serveStaticLoadFile/data/page3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Hello from Ethernet HTTP Web Server ESP8266/ESP32 - Page3 10 | 11 | 12 | 13 |
14 |

ESP8266/ESP32 Ethernet HTTP Web Server

15 |

Hello from ESP8266/ESP32 Ethernet HTTP Web Server. This is Page3.

16 |

17 | Page1 18 | Page2 19 | Page3 20 |

21 | 22 |

Copyright (C) 2019 Arduino Slovakia.

23 |

Copyright (C) 2021 Sardar Azari.

24 |
25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "WebServer_WT32_ETH01", 3 | "version": "1.5.1", 4 | "keywords": "WebServer, Ethernet, MQTT, MQTTS, HTTP, HTTPS, SSL, Arduino, ESP32, LAN8720, WT32-ETH01, HTTP-Client, WebSocket-Client, MQTT-Client, server, client, websocket, LittleFS, SPIFFS, ThingStream", 5 | "description": "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.", 6 | "authors": 7 | { 8 | "name": "Khoi Hoang", 9 | "url": "https://github.com/khoih-prog", 10 | "maintainer": true 11 | }, 12 | "repository": 13 | { 14 | "type": "git", 15 | "url": "https://github.com/khoih-prog/WebServer_WT32_ETH01" 16 | }, 17 | "homepage": "https://github.com/khoih-prog/WebServer_WT32_ETH01", 18 | "export": { 19 | "exclude": [ 20 | "linux", 21 | "extras", 22 | "tests" 23 | ] 24 | }, 25 | "license": "GPL-3.0", 26 | "frameworks": "*", 27 | "platforms": "espressif32", 28 | "examples": "examples/*/*/*.ino", 29 | "headers": ["WebServer_WT32_ETH01.h", "WebServer_WT32_ETH01.hpp"] 30 | } 31 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=WebServer_WT32_ETH01 2 | version=1.5.1 3 | author=Khoi Hoang 4 | license=GPLv3 5 | maintainer=Khoi Hoang 6 | sentence=Simple Ethernet WebServer, HTTP/HTTPS Client wrapper library for WT32_ETH01 boards using LAN8720 Ethernet. 7 | paragraph=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. 8 | category=Communication 9 | url=https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | architectures=esp32 11 | includes=WebServer_WT32_ETH01.h, WebServer_WT32_ETH01.hpp 12 | -------------------------------------------------------------------------------- /pics/AdvancedWebServer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/WebServer_WT32_ETH01/593fe6211a30329499952ba0b29f6d37fc7b5144/pics/AdvancedWebServer.png -------------------------------------------------------------------------------- /pics/ESP32_FS_EthernetWebServer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/WebServer_WT32_ETH01/593fe6211a30329499952ba0b29f6d37fc7b5144/pics/ESP32_FS_EthernetWebServer.png -------------------------------------------------------------------------------- /pics/serveStatic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoih-prog/WebServer_WT32_ETH01/593fe6211a30329499952ba0b29f6d37fc7b5144/pics/serveStatic.png -------------------------------------------------------------------------------- /platformio/platformio.ini: -------------------------------------------------------------------------------- 1 | ;PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | ; ============================================================ 13 | ; chose environment: 14 | ; ESP32 15 | ; esp32s2 16 | ; esp32s3 17 | ; esp32c3 18 | 19 | ; ============================================================ 20 | default_envs = ESP32 21 | 22 | [env] 23 | ; ============================================================ 24 | ; Serial configuration 25 | ; choose upload speed, serial-monitor speed 26 | ; ============================================================ 27 | upload_speed = 921600 28 | ;upload_port = COM11 29 | ;monitor_speed = 9600 30 | ;monitor_port = COM11 31 | 32 | ; Checks for the compatibility with frameworks and dev/platforms 33 | lib_compat_mode = strict 34 | lib_ldf_mode = chain+ 35 | ;lib_ldf_mode = deep+ 36 | 37 | lib_deps = 38 | 39 | build_flags = 40 | ; set your debug output (default=Serial) 41 | -D DEBUG_ESP_PORT=Serial 42 | ; comment the following line to enable WiFi debugging 43 | -D NDEBUG 44 | 45 | [env:ESP32] 46 | platform = espressif32 47 | framework = arduino 48 | 49 | ; ============================================================ 50 | ; Board configuration 51 | ; choose your board by uncommenting one of the following lines 52 | ; ============================================================ 53 | ;board = esp32cam 54 | ;board = alksesp32 55 | ;board = featheresp32 56 | ;board = espea32 57 | ;board = bpi-bit 58 | ;board = d-duino-32 59 | board = esp32doit-devkit-v1 60 | ;board = pocket_32 61 | ;board = fm-devkit 62 | ;board = pico32 63 | ;board = esp32-evb 64 | ;board = esp32-gateway 65 | ;board = esp32-pro 66 | ;board = esp32-poe 67 | ;board = oroca_edubot 68 | ;board = onehorse32dev 69 | ;board = lopy 70 | ;board = lopy4 71 | ;board = wesp32 72 | ;board = esp32thing 73 | ;board = sparkfun_lora_gateway_1-channel 74 | ;board = ttgo-lora32-v1 75 | ;board = ttgo-t-beam 76 | ;board = turta_iot_node 77 | ;board = lolin_d32 78 | ;board = lolin_d32_pro 79 | ;board = lolin32 80 | ;board = wemosbat 81 | ;board = widora-air 82 | ;board = xinabox_cw02 83 | ;board = iotbusio 84 | ;board = iotbusproteus 85 | ;board = nina_w10 86 | 87 | [env:esp32s2] 88 | platform = espressif32 89 | framework = arduino 90 | 91 | ; toolchain download links see 92 | ; refer "name": "xtensa-esp32s2-elf-gcc","version": "gcc8_4_0-esp-2021r1" section of 93 | ; https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json 94 | ; e.g. Windows: https://github.com/espressif/crosstool-NG/releases/download/esp-2021r1/xtensa-esp32s2-elf-gcc8_4_0-esp-2021r1-win32.zip 95 | platform_packages = 96 | toolchain-xtensa32s2@file://C:\Users\Max\Downloads\xtensa-esp32s2-elf 97 | framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#a4118ea88987c28aac3a49bcb9cc5d6c0acc6f3f 98 | platformio/tool-esptoolpy @ ~1.30100 99 | framework = arduino 100 | board = esp32dev 101 | board_build.mcu = esp32s2 102 | board_build.partitions = huge_app.csv 103 | board_build.variant = esp32s2 104 | board_build.f_cpu = 240000000L 105 | board_build.f_flash = 80000000L 106 | board_build.flash_mode = qio 107 | board_build.arduino.ldscript = esp32s2_out.ld 108 | build_unflags = 109 | -DARDUINO_ESP32_DEV 110 | -DARDUINO_VARIANT="esp32" 111 | build_flags = 112 | -DARDUINO_ESP32S2_DEV 113 | -DARDUINO_VARIANT="esp32s2" 114 | 115 | 116 | [env:esp32s3] 117 | platform = espressif32 118 | framework = arduino 119 | 120 | board_build.mcu = esp32s3 121 | board_build.partitions = huge_app.csv 122 | board_build.variant = esp32s3 123 | board_build.f_cpu = 240000000L 124 | board_build.f_flash = 80000000L 125 | board_build.flash_mode = qio 126 | board_build.arduino.ldscript = esp32s3_out.ld 127 | build_unflags = 128 | -DARDUINO_ESP32_DEV 129 | -DARDUINO_VARIANT="esp32" 130 | build_flags = 131 | -DARDUINO_ESP32S3_DEV 132 | -DARDUINO_VARIANT="esp32s3" 133 | 134 | 135 | [env:esp32sc3] 136 | platform = espressif32 137 | framework = arduino 138 | 139 | board_build.mcu = esp32c3 140 | board_build.partitions = huge_app.csv 141 | board_build.variant = esp32c3 142 | board_build.f_cpu = 160000000L 143 | board_build.f_flash = 80000000L 144 | board_build.flash_mode = qio 145 | board_build.arduino.ldscript = esp32c3_out.ld 146 | build_unflags = 147 | -DARDUINO_ESP32_DEV 148 | -DARDUINO_VARIANT="esp32" 149 | build_flags = 150 | -DARDUINO_ESP32S3_DEV 151 | -DARDUINO_VARIANT="esp32c3" 152 | -------------------------------------------------------------------------------- /src/WebServer_WT32_ETH01.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebServer_WT32_ETH01.h - Dead simple web-server. 3 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 4 | 5 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 9 | Licensed under MIT license 10 | 11 | Original author: 12 | @file Esp8266WebServer.h 13 | @author Ivan Grokhotkov 14 | 15 | Version: 1.5.1 16 | 17 | Version Modified By Date Comments 18 | ------- ----------- ---------- ----------- 19 | 1.0.0 K Hoang 05/07/2021 Initial coding for WT32_ETH01 (ESP32 + LAN8720) 20 | 1.1.0 K Hoang 06/07/2021 Add SSL support and HTTPS, MQTTS examples 21 | 1.2.0 K Hoang 12/07/2021 Add common code to library. Working only with core v1.0.6- 22 | 1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+ 23 | 1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version 24 | 1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time 25 | 1.5.0 K Hoang 21/06/2022 Fix multiple-definitions linker error 26 | 1.5.1 K Hoang 10/09/2022 Add example MQTT_And_OTA_Ethernet. Fix compile error for examples 27 | *****************************************************************************************************************************/ 28 | 29 | #pragma once 30 | 31 | #ifndef WEBSERVER_WT32_ETH01_H 32 | #define WEBSERVER_WT32_ETH01_H 33 | 34 | ////////////////////////////////////////////////////////////// 35 | 36 | //#if !defined(USING_CORE_ESP32_CORE_V200_PLUS) 37 | #if ( ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) ) && ( ARDUINO_ESP32_GIT_VER != 0x46d5afb1 ) ) 38 | #define USING_CORE_ESP32_CORE_V200_PLUS true 39 | 40 | #if (_ETHERNET_WEBSERVER_LOGLEVEL_ > 2) 41 | #warning Using code for ESP32 core v2.0.0+ in WebServer_WT32_ETH01.h 42 | #endif 43 | 44 | #define WEBSERVER_WT32_ETH01_VERSION "WebServer_WT32_ETH01 v1.5.1 for core v2.0.0+" 45 | #else 46 | #if (_ETHERNET_WEBSERVER_LOGLEVEL_ > 2) 47 | #warning Using code for ESP32 core v1.0.6- in WebServer_WT32_ETH01.h 48 | #endif 49 | 50 | #define WEBSERVER_WT32_ETH01_VERSION "WebServer_WT32_ETH01 v1.5.1 for core v1.0.6-" 51 | #endif 52 | 53 | #define WEBSERVER_WT32_ETH01_VERSION_MAJOR 1 54 | #define WEBSERVER_WT32_ETH01_VERSION_MINOR 5 55 | #define WEBSERVER_WT32_ETH01_VERSION_PATCH 1 56 | 57 | #define WEBSERVER_WT32_ETH01_VERSION_INT 1005001 58 | 59 | #if ESP32 60 | #warning Using ESP32 architecture for WebServer_WT32_ETH01 61 | #define BOARD_NAME "WT32-ETH01" 62 | #else 63 | #error This code is designed to run on ESP32 platform! Please check your Tools->Board setting. 64 | #endif 65 | 66 | #include 67 | 68 | #include "WebServer_WT32_ETH01_Debug.h" 69 | 70 | ////////////////////////////////////////////////////////////// 71 | 72 | #include "WebServer_WT32_ETH01.hpp" 73 | #include "WebServer_WT32_ETH01_Impl.h" 74 | 75 | #endif // WEBSERVER_WT32_ETH01_H 76 | -------------------------------------------------------------------------------- /src/WebServer_WT32_ETH01.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebServer_WT32_ETH01.h - Dead simple web-server. 3 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 4 | 5 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 9 | Licensed under MIT license 10 | 11 | Original author: 12 | @file Esp8266WebServer.h 13 | @author Ivan Grokhotkov 14 | 15 | Version: 1.5.1 16 | 17 | Version Modified By Date Comments 18 | ------- ----------- ---------- ----------- 19 | 1.0.0 K Hoang 05/07/2021 Initial coding for WT32_ETH01 (ESP32 + LAN8720) 20 | 1.1.0 K Hoang 06/07/2021 Add SSL support and HTTPS, MQTTS examples 21 | 1.2.0 K Hoang 12/07/2021 Add common code to library. Working only with core v1.0.6- 22 | 1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+ 23 | 1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version 24 | 1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time 25 | 1.5.0 K Hoang 21/06/2022 Fix multiple-definitions linker error 26 | 1.5.1 K Hoang 10/09/2022 Add example MQTT_And_OTA_Ethernet. Fix compile error for examples 27 | *****************************************************************************************************************************/ 28 | 29 | #pragma once 30 | 31 | #ifndef WEBSERVER_WT32_ETH01_HPP 32 | #define WEBSERVER_WT32_ETH01_HPP 33 | 34 | ////////////////////////////////////////////////////////////// 35 | 36 | // defined here before #include to override 37 | 38 | // I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110) 39 | #ifndef ETH_PHY_ADDR 40 | #define ETH_PHY_ADDR 1 41 | #endif 42 | 43 | // Type of the Ethernet PHY (LAN8720 or TLK110) 44 | //typedef enum { ETH_PHY_LAN8720, ETH_PHY_TLK110, ETH_PHY_RTL8201, ETH_PHY_DP83848, ETH_PHY_DM9051, ETH_PHY_KSZ8081, ETH_PHY_MAX } eth_phy_type_t; 45 | 46 | #ifndef ETH_PHY_TYPE 47 | #define ETH_PHY_TYPE ETH_PHY_LAN8720 48 | #endif 49 | 50 | // Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source) 51 | #ifndef ETH_PHY_POWER 52 | #define ETH_PHY_POWER 16 53 | #endif 54 | 55 | // Pin# of the I²C clock signal for the Ethernet PHY 56 | #ifndef ETH_PHY_MDC 57 | #define ETH_PHY_MDC 23 58 | #endif 59 | 60 | // Pin# of the I²C IO signal for the Ethernet PHY 61 | #ifndef ETH_PHY_MDIO 62 | #define ETH_PHY_MDIO 18 63 | #endif 64 | 65 | /* 66 | //typedef enum { ETH_CLOCK_GPIO0_IN, ETH_CLOCK_GPIO0_OUT, ETH_CLOCK_GPIO16_OUT, ETH_CLOCK_GPIO17_OUT } eth_clock_mode_t; 67 | ETH_CLOCK_GPIO0_IN - default: external clock from crystal oscillator 68 | ETH_CLOCK_GPIO0_OUT - 50MHz clock from internal APLL output on GPIO0 - possibly an inverter is needed for LAN8720 69 | ETH_CLOCK_GPIO16_OUT - 50MHz clock from internal APLL output on GPIO16 - possibly an inverter is needed for LAN8720 70 | ETH_CLOCK_GPIO17_OUT - 50MHz clock from internal APLL inverted output on GPIO17 - tested with LAN8720 71 | */ 72 | #ifndef ETH_CLK_MODE 73 | #define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN // ETH_CLOCK_GPIO17_OUT 74 | #endif 75 | 76 | #include 77 | 78 | #include 79 | #include // Introduce corresponding libraries 80 | 81 | #ifndef SHIELD_TYPE 82 | #define SHIELD_TYPE "ETH_PHY_LAN8720" 83 | #endif 84 | 85 | extern bool WT32_ETH01_eth_connected; 86 | 87 | extern void WT32_ETH01_onEvent(); 88 | 89 | extern void WT32_ETH01_waitForConnect(); 90 | 91 | extern bool WT32_ETH01_isConnected(); 92 | 93 | extern void WT32_ETH01_event(WiFiEvent_t event); 94 | 95 | ////////////////////////////////////////////////////////////// 96 | 97 | #endif // WEBSERVER_WT32_ETH01_HPP 98 | -------------------------------------------------------------------------------- /src/WebServer_WT32_ETH01_Debug.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebServer_WT32_ETH01_Debug.h - Dead simple Ethernet web-server. 3 | 4 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 5 | 6 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 7 | 8 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 9 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 10 | Licensed under MIT license 11 | 12 | Original author: 13 | @file Esp8266WebServer.h 14 | @author Ivan Grokhotkov 15 | 16 | Version: 1.5.1 17 | 18 | Version Modified By Date Comments 19 | ------- ----------- ---------- ----------- 20 | 1.0.0 K Hoang 05/07/2021 Initial coding for WT32_ETH01 (ESP32 + LAN8720) 21 | 1.1.0 K Hoang 06/07/2021 Add SSL support and HTTPS, MQTTS examples 22 | 1.2.0 K Hoang 12/07/2021 Add common code to library. Working only with core v1.0.6- 23 | 1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+ 24 | 1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version 25 | 1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time 26 | 1.5.0 K Hoang 21/06/2022 Fix multiple-definitions linker error 27 | 1.5.1 K Hoang 10/09/2022 Add example MQTT_And_OTA_Ethernet. Fix compile error for examples 28 | *****************************************************************************************************************************/ 29 | 30 | #pragma once 31 | 32 | #ifndef WEBSERVER_WT32_ETH01_DEBUG_H 33 | #define WEBSERVER_WT32_ETH01_DEBUG_H 34 | 35 | #include 36 | 37 | #ifdef DEBUG_ETHERNET_WEBSERVER_PORT 38 | #define ET_DEBUG_OUTPUT DEBUG_ETHERNET_WEBSERVER_PORT 39 | #else 40 | #define ET_DEBUG_OUTPUT Serial 41 | #endif 42 | 43 | // Change _ETHERNET_WEBSERVER_LOGLEVEL_ to set tracing and logging verbosity 44 | // 0: DISABLED: no logging 45 | // 1: ERROR: errors 46 | // 2: WARN: errors and warnings 47 | // 3: INFO: errors, warnings and informational (default) 48 | // 4: DEBUG: errors, warnings, informational and debug 49 | 50 | #ifndef _ETHERNET_WEBSERVER_LOGLEVEL_ 51 | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 0 52 | #endif 53 | 54 | const char EWS_MARK[] = "[EWS] "; 55 | const char EWS_SPACE[] = " "; 56 | const char EWS_LINE[] = "========================================\n"; 57 | 58 | #define EWS_PRINT_MARK EWS_PRINT(EWS_MARK) 59 | #define EWS_PRINT_SP EWS_PRINT(EWS_SPACE) 60 | #define EWS_PRINT_LINE EWS_PRINT(EWS_LINE) 61 | 62 | #define EWS_PRINT ET_DEBUG_OUTPUT.print 63 | #define EWS_PRINTLN ET_DEBUG_OUTPUT.println 64 | 65 | /////////////////////////////////////// 66 | 67 | #define ET_LOG(x) { EWS_PRINTLN(x); } 68 | #define ET_LOG0(x) { EWS_PRINT(x); } 69 | #define ET_LOG1(x,y) { EWS_PRINT(x); EWS_PRINTLN(y); } 70 | #define ET_LOG2(x,y,z) { EWS_PRINT(x); EWS_PRINT(y); EWS_PRINTLN(z); } 71 | #define ET_LOG3(x,y,z,w) { EWS_PRINT(x); EWS_PRINT(y); EWS_PRINT(z); EWS_PRINTLN(w); } 72 | 73 | /////////////////////////////////////// 74 | 75 | #define ET_LOGERROR(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>0) { EWS_PRINT_MARK; EWS_PRINTLN(x); } 76 | #define ET_LOGERROR_LINE(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>0) { EWS_PRINT_MARK; EWS_PRINTLN(x); EWS_PRINT_LINE; } 77 | #define ET_LOGERROR0(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>0) { EWS_PRINT(x); } 78 | #define ET_LOGERROR1(x,y) if(_ETHERNET_WEBSERVER_LOGLEVEL_>0) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINTLN(y); } 79 | #define ET_LOGERROR2(x,y,z) if(_ETHERNET_WEBSERVER_LOGLEVEL_>0) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINTLN(z); } 80 | #define ET_LOGERROR3(x,y,z,w) if(_ETHERNET_WEBSERVER_LOGLEVEL_>0) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINT(z); EWS_PRINT_SP; EWS_PRINTLN(w); } 81 | 82 | /////////////////////////////////////// 83 | 84 | #define ET_LOGWARN(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>1) { EWS_PRINT_MARK; EWS_PRINTLN(x); } 85 | #define ET_LOGWARN_LINE(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>1) { EWS_PRINT_MARK; EWS_PRINTLN(x); EWS_PRINT_LINE; } 86 | #define ET_LOGWARN0(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>1) { EWS_PRINT(x); } 87 | #define ET_LOGWARN1(x,y) if(_ETHERNET_WEBSERVER_LOGLEVEL_>1) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINTLN(y); } 88 | #define ET_LOGWARN2(x,y,z) if(_ETHERNET_WEBSERVER_LOGLEVEL_>1) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINTLN(z); } 89 | #define ET_LOGWARN3(x,y,z,w) if(_ETHERNET_WEBSERVER_LOGLEVEL_>1) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINT(z); EWS_PRINT_SP; EWS_PRINTLN(w); } 90 | 91 | /////////////////////////////////////// 92 | 93 | #define ET_LOGINFO(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>2) { EWS_PRINT_MARK; EWS_PRINTLN(x); } 94 | #define ET_LOGINFO_LINE(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>2) { EWS_PRINT_MARK; EWS_PRINTLN(x); EWS_PRINT_LINE; } 95 | #define ET_LOGINFO0(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>2) { EWS_PRINT(x); } 96 | #define ET_LOGINFO1(x,y) if(_ETHERNET_WEBSERVER_LOGLEVEL_>2) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINTLN(y); } 97 | #define ET_LOGINFO2(x,y,z) if(_ETHERNET_WEBSERVER_LOGLEVEL_>2) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINTLN(z); } 98 | #define ET_LOGINFO3(x,y,z,w) if(_ETHERNET_WEBSERVER_LOGLEVEL_>2) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINT(z); EWS_PRINT_SP; EWS_PRINTLN(w); } 99 | 100 | /////////////////////////////////////// 101 | 102 | #define ET_LOGDEBUG(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>3) { EWS_PRINT_MARK; EWS_PRINTLN(x); } 103 | #define ET_LOGDEBUG_LINE(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>3) { EWS_PRINT_MARK; EWS_PRINTLN(x); EWS_PRINT_LINE; } 104 | #define ET_LOGDEBUG0(x) if(_ETHERNET_WEBSERVER_LOGLEVEL_>3) { EWS_PRINT(x); } 105 | #define ET_LOGDEBUG1(x,y) if(_ETHERNET_WEBSERVER_LOGLEVEL_>3) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINTLN(y); } 106 | #define ET_LOGDEBUG2(x,y,z) if(_ETHERNET_WEBSERVER_LOGLEVEL_>3) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINTLN(z); } 107 | #define ET_LOGDEBUG3(x,y,z,w) if(_ETHERNET_WEBSERVER_LOGLEVEL_>3) { EWS_PRINT_MARK; EWS_PRINT(x); EWS_PRINT_SP; EWS_PRINT(y); EWS_PRINT_SP; EWS_PRINT(z); EWS_PRINT_SP; EWS_PRINTLN(w); } 108 | 109 | #endif // WEBSERVER_WT32_ETH01_DEBUG_H 110 | 111 | 112 | -------------------------------------------------------------------------------- /src/WebServer_WT32_ETH01_Impl.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************************************************************** 2 | WebServer_WT32_ETH01_Impl.h - Dead simple web-server. 3 | For Ethernet shields using WT32_ETH01 (ESP32 + LAN8720) 4 | 5 | WebServer_WT32_ETH01 is a library for the Ethernet LAN8720 in WT32_ETH01 to run WebServer 6 | 7 | Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases 8 | Built by Khoi Hoang https://github.com/khoih-prog/WebServer_WT32_ETH01 9 | Licensed under MIT license 10 | 11 | Original author: 12 | @file Esp8266WebServer.h 13 | @author Ivan Grokhotkov 14 | 15 | Version: 1.5.1 16 | 17 | Version Modified By Date Comments 18 | ------- ----------- ---------- ----------- 19 | 1.0.0 K Hoang 05/07/2021 Initial coding for WT32_ETH01 (ESP32 + LAN8720) 20 | 1.1.0 K Hoang 06/07/2021 Add SSL support and HTTPS, MQTTS examples 21 | 1.2.0 K Hoang 12/07/2021 Add common code to library. Working only with core v1.0.6- 22 | 1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+ 23 | 1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version 24 | 1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time 25 | 1.5.0 K Hoang 21/06/2022 Fix multiple-definitions linker error 26 | 1.5.1 K Hoang 10/09/2022 Add example MQTT_And_OTA_Ethernet. Fix compile error for examples 27 | *****************************************************************************************************************************/ 28 | 29 | #pragma once 30 | 31 | #ifndef WEBSERVER_WT32_ETH01_IMPL_H 32 | #define WEBSERVER_WT32_ETH01_IMPL_H 33 | 34 | ////////////////////////////////////////////////////////////// 35 | 36 | bool WT32_ETH01_eth_connected = false; 37 | 38 | void WT32_ETH01_onEvent() 39 | { 40 | WiFi.onEvent(WT32_ETH01_event); 41 | } 42 | 43 | void WT32_ETH01_waitForConnect() 44 | { 45 | while (!WT32_ETH01_eth_connected) 46 | delay(100); 47 | } 48 | 49 | bool WT32_ETH01_isConnected() 50 | { 51 | return WT32_ETH01_eth_connected; 52 | } 53 | 54 | void WT32_ETH01_event(WiFiEvent_t event) 55 | { 56 | switch (event) 57 | { 58 | //#if USING_CORE_ESP32_CORE_V200_PLUS 59 | #if ( ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) ) && ( ARDUINO_ESP32_GIT_VER != 0x46d5afb1 ) ) 60 | // For breaking core v2.0.0 61 | // Why so strange to define a breaking enum arduino_event_id_t in WiFiGeneric.h 62 | // compared to the old system_event_id_t, now in tools/sdk/esp32/include/esp_event/include/esp_event_legacy.h 63 | // You can preserve the old enum order and just adding new items to do no harm 64 | case ARDUINO_EVENT_ETH_START: 65 | ET_LOG(F("\nETH Started")); 66 | //set eth hostname here 67 | ETH.setHostname("WT32-ETH01"); 68 | break; 69 | 70 | case ARDUINO_EVENT_ETH_CONNECTED: 71 | ET_LOG(F("ETH Connected")); 72 | break; 73 | 74 | case ARDUINO_EVENT_ETH_GOT_IP: 75 | if (!WT32_ETH01_eth_connected) 76 | { 77 | ET_LOG3(F("ETH MAC: "), ETH.macAddress(), F(", IPv4: "), ETH.localIP()); 78 | 79 | if (ETH.fullDuplex()) 80 | { 81 | ET_LOG0(F("FULL_DUPLEX, ")); 82 | } 83 | else 84 | { 85 | ET_LOG0(F("HALF_DUPLEX, ")); 86 | } 87 | 88 | ET_LOG1(ETH.linkSpeed(), F("Mbps")); 89 | 90 | WT32_ETH01_eth_connected = true; 91 | } 92 | 93 | break; 94 | 95 | case ARDUINO_EVENT_ETH_DISCONNECTED: 96 | ET_LOG("ETH Disconnected"); 97 | WT32_ETH01_eth_connected = false; 98 | break; 99 | 100 | case ARDUINO_EVENT_ETH_STOP: 101 | ET_LOG("\nETH Stopped"); 102 | WT32_ETH01_eth_connected = false; 103 | break; 104 | 105 | #else 106 | 107 | // For old core v1.0.6- 108 | // Core v2.0.0 defines a stupid enum arduino_event_id_t, breaking any code for WT32_ETH01 written for previous core 109 | // Why so strange to define a breaking enum arduino_event_id_t in WiFiGeneric.h 110 | // compared to the old system_event_id_t, now in tools/sdk/esp32/include/esp_event/include/esp_event_legacy.h 111 | // You can preserve the old enum order and just adding new items to do no harm 112 | case SYSTEM_EVENT_ETH_START: 113 | ET_LOG(F("\nETH Started")); 114 | //set eth hostname here 115 | ETH.setHostname("WT32-ETH01"); 116 | break; 117 | 118 | case SYSTEM_EVENT_ETH_CONNECTED: 119 | ET_LOG(F("ETH Connected")); 120 | break; 121 | 122 | case SYSTEM_EVENT_ETH_GOT_IP: 123 | if (!WT32_ETH01_eth_connected) 124 | { 125 | ET_LOG3(F("ETH MAC: "), ETH.macAddress(), F(", IPv4: "), ETH.localIP()); 126 | 127 | if (ETH.fullDuplex()) 128 | { 129 | ET_LOG0(F("FULL_DUPLEX, ")); 130 | } 131 | else 132 | { 133 | ET_LOG0(F("HALF_DUPLEX, ")); 134 | } 135 | 136 | ET_LOG1(ETH.linkSpeed(), F("Mbps")); 137 | 138 | WT32_ETH01_eth_connected = true; 139 | } 140 | 141 | break; 142 | 143 | case SYSTEM_EVENT_ETH_DISCONNECTED: 144 | ET_LOG("ETH Disconnected"); 145 | WT32_ETH01_eth_connected = false; 146 | break; 147 | 148 | case SYSTEM_EVENT_ETH_STOP: 149 | ET_LOG("\nETH Stopped"); 150 | WT32_ETH01_eth_connected = false; 151 | break; 152 | #endif 153 | 154 | default: 155 | break; 156 | } 157 | } 158 | 159 | #endif // WEBSERVER_WT32_ETH01_IMPL_H 160 | -------------------------------------------------------------------------------- /utils/astyle_library.conf: -------------------------------------------------------------------------------- 1 | # Code formatting rules for Arduino libraries, modified from for KH libraries: 2 | # 3 | # https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf 4 | # 5 | 6 | # astyle --style=allman -s2 -t2 -C -S -xW -Y -M120 -f -p -xg -H -xb -c --xC120 -xL *.h *.cpp *.ino 7 | 8 | --mode=c 9 | --lineend=linux 10 | --style=allman 11 | 12 | # -r or -R 13 | #--recursive 14 | 15 | # -c => Converts tabs into spaces 16 | convert-tabs 17 | 18 | # -s2 => 2 spaces indentation 19 | --indent=spaces=2 20 | 21 | # -t2 => tab =2 spaces 22 | #--indent=tab=2 23 | 24 | # -C 25 | --indent-classes 26 | 27 | # -S 28 | --indent-switches 29 | 30 | # -xW 31 | --indent-preproc-block 32 | 33 | # -Y => indent classes, switches (and cases), comments starting at column 1 34 | --indent-col1-comments 35 | 36 | # -M120 => maximum of 120 spaces to indent a continuation line 37 | --max-continuation-indent=120 38 | 39 | # -xC120 => max‑code‑length will break a line if the code exceeds # characters 40 | --max-code-length=120 41 | 42 | # -f => 43 | --break-blocks 44 | 45 | # -p => put a space around operators 46 | --pad-oper 47 | 48 | # -xg => Insert space padding after commas 49 | --pad-comma 50 | 51 | # -H => put a space after if/for/while 52 | pad-header 53 | 54 | # -xb => Break one line headers (e.g. if/for/while) 55 | --break-one-line-headers 56 | 57 | # -c => Converts tabs into spaces 58 | #--convert-tabs 59 | 60 | # if you like one-liners, keep them 61 | #keep-one-line-statements 62 | 63 | # -xV 64 | --attach-closing-while 65 | 66 | #unpad-paren 67 | 68 | # -xp 69 | remove-comment-prefix 70 | 71 | -------------------------------------------------------------------------------- /utils/restyle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for dir in . ; do 4 | find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.ino" \) -exec astyle --suffix=none --options=./utils/astyle_library.conf \{\} \; 5 | done 6 | 7 | --------------------------------------------------------------------------------