From 307792f250686ff98162d4cea7d8a9b421dd6ff5 Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Wed, 7 Jul 2021 02:07:54 -0400 Subject: [PATCH] v1.5.0 to add support to ESP32-based WT32-ETH01 ### Major Releases v1.5.0 1. Add support to ESP32-based WT32-ETH01 (ESP32 + LAN8720) boards, using EEPROM, SPIFFS or LittleFS --- CONTRIBUTING.md | 12 +- README.md | 206 +- examples/AM2315_Ethernet/AM2315_Ethernet.ino | 7 +- examples/AM2315_Ethernet/Credentials.h | 4 +- examples/AM2315_Ethernet/defines.h | 4 +- examples/AM2315_Ethernet/dynamicParams.h | 4 +- examples/Ethernet_Generic/Credentials.h | 4 +- .../Ethernet_Generic/Ethernet_Generic.ino | 7 +- examples/Ethernet_Generic/defines.h | 4 +- examples/Ethernet_Generic/dynamicParams.h | 4 +- examples/Ethernet_RP2040/Credentials.h | 4 +- examples/Ethernet_RP2040/Ethernet_RP2040.ino | 7 +- examples/Ethernet_RP2040/defines.h | 4 +- examples/Ethernet_RP2040/dynamicParams.h | 4 +- examples/Ethernet_SAMD/Credentials.h | 4 +- examples/Ethernet_SAMD/Ethernet_SAMD.ino | 7 +- examples/Ethernet_SAMD/defines.h | 4 +- examples/Ethernet_SAMD/dynamicParams.h | 4 +- examples/Ethernet_SAM_DUE/Credentials.h | 4 +- .../Ethernet_SAM_DUE/Ethernet_SAM_DUE.ino | 7 +- examples/Ethernet_SAM_DUE/defines.h | 4 +- examples/Ethernet_SAM_DUE/dynamicParams.h | 4 +- examples/Ethernet_Teensy/Credentials.h | 4 +- examples/Ethernet_Teensy/Ethernet_Teensy.ino | 7 +- examples/Ethernet_Teensy/defines.h | 4 +- examples/Ethernet_Teensy/dynamicParams.h | 4 +- examples/Ethernet_WT32_ETH01/Credentials.h | 67 + .../Ethernet_WT32_ETH01.ino | 215 ++ examples/Ethernet_WT32_ETH01/defines.h | 70 + examples/Ethernet_WT32_ETH01/dynamicParams.h | 76 + examples/Ethernet_nRF52/Credentials.h | 4 +- examples/Ethernet_nRF52/Ethernet_nRF52.ino | 7 +- examples/Ethernet_nRF52/defines.h | 4 +- examples/Ethernet_nRF52/dynamicParams.h | 4 +- .../Credentials.h | 4 +- .../MQTT_ThingStream_Ethernet_Generic.ino | 7 +- .../defines.h | 4 +- .../dynamicParams.h | 4 +- .../Credentials.h | 4 +- .../MQTT_ThingStream_Ethernet_RP2040.ino | 7 +- .../defines.h | 4 +- .../dynamicParams.h | 4 +- .../Credentials.h | 4 +- .../MQTT_ThingStream_Ethernet_SAMD.ino | 7 +- .../MQTT_ThingStream_Ethernet_SAMD/defines.h | 4 +- .../dynamicParams.h | 4 +- .../Credentials.h | 4 +- .../MQTT_ThingStream_Ethernet_SAM_DUE.ino | 7 +- .../defines.h | 4 +- .../dynamicParams.h | 4 +- .../Credentials.h | 4 +- .../MQTT_ThingStream_Ethernet_Teensy.ino | 7 +- .../defines.h | 4 +- .../dynamicParams.h | 4 +- .../Credentials.h | 67 + .../MQTT_ThingStream_Ethernet_WT32_ETH01.ino | 363 +++ .../defines.h | 71 + .../dynamicParams.h | 72 + .../Credentials.h | 4 +- .../MQTT_ThingStream_Ethernet_nRF52.ino | 7 +- .../MQTT_ThingStream_Ethernet_nRF52/defines.h | 4 +- .../dynamicParams.h | 4 +- library.json | 12 +- library.properties | 6 +- platformio/platformio.ini | 6 +- src/Adapters/Ethernet_DUE_Manager.h | 8 +- src/Adapters/Ethernet_ESP32_Manager.h | 8 +- src/Adapters/Ethernet_ESP8266_Manager.h | 8 +- src/Adapters/Ethernet_MBED_RP2040_Manager.h | 10 +- src/Adapters/Ethernet_NRF52_Manager.h | 8 +- src/Adapters/Ethernet_RP2040_Manager.h | 10 +- src/Adapters/Ethernet_SAMD_Manager.h | 8 +- src/Adapters/Ethernet_Teensy_Manager.h | 8 +- src/Adapters/Ethernet_WT32_ETH01_Manager.h | 1959 +++++++++++++++++ src/Ethernet_Manager.h | 22 +- src/Ethernet_Manager_Debug.h | 8 +- 76 files changed, 3334 insertions(+), 213 deletions(-) create mode 100644 examples/Ethernet_WT32_ETH01/Credentials.h create mode 100644 examples/Ethernet_WT32_ETH01/Ethernet_WT32_ETH01.ino create mode 100644 examples/Ethernet_WT32_ETH01/defines.h create mode 100644 examples/Ethernet_WT32_ETH01/dynamicParams.h create mode 100644 examples/MQTT_ThingStream_Ethernet_WT32_ETH01/Credentials.h create mode 100644 examples/MQTT_ThingStream_Ethernet_WT32_ETH01/MQTT_ThingStream_Ethernet_WT32_ETH01.ino create mode 100644 examples/MQTT_ThingStream_Ethernet_WT32_ETH01/defines.h create mode 100644 examples/MQTT_ThingStream_Ethernet_WT32_ETH01/dynamicParams.h create mode 100644 src/Adapters/Ethernet_WT32_ETH01_Manager.h diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6639a763..8b667a0d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,8 +14,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p Please ensure to specify the following: -* Arduino IDE version (e.g. 1.8.13) or Platform.io version -* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP8266 core v3.0.0, etc.) +* Arduino IDE version (e.g. 1.8.15) or Platform.io version +* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP8266 core v3.0.1, etc.) * Contextual information (e.g. what you were trying to achieve) * Simplest possible steps to reproduce * Anything that might be relevant in your opinion, such as: @@ -26,10 +26,11 @@ Please ensure to specify the following: ### Example ``` -Arduino IDE version: 1.8.13 -Arduino SAM DUE Core Version 1.6.12 +Arduino IDE version: 1.8.15 +WT32_ETH01 board +ESP32 core v1.0.6 OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux +Linux xy-Inspiron-3593 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux Context: The board couldn't autoreconnect to Local Blynk Server after router power recycling. @@ -40,6 +41,7 @@ Steps to reproduce: 3. ... 4. ... ``` + ### Sending Feature Requests Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. diff --git a/README.md b/README.md index 53719054..7669a94c 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ * [Currently supported Boards](#currently-supported-boards) * [Currently supported Ethernet shields/modules](#currently-supported-ethernet-shieldsmodules) * [Changelog](#changelog) + * [Major Releases v1.5.0](#major-releases-v150) * [Major Releases v1.4.0](#major-releases-v140) * [Major Releases v1.3.0](#major-releases-v130) * [Major Releases v1.2.0](#major-releases-v120) @@ -105,12 +106,14 @@ * [ 5. Ethernet_SAMD](examples/Ethernet_SAMD) * [ 6. Ethernet_SAM_DUE](examples/Ethernet_SAM_DUE) * [ 7. Ethernet_Teensy](examples/Ethernet_Teensy) - * [ 8. **MQTT_ThingStream_Ethernet_Generic**](examples/MQTT_ThingStream_Ethernet_Generic) - * [ 9. **MQTT_ThingStream_Ethernet_nRF52**](examples/MQTT_ThingStream_Ethernet_nRF52) - * [10. **MQTT_ThingStream_Ethernet_RP2040**](examples/MQTT_ThingStream_Ethernet_RP2040). **New** - * [11. **MQTT_ThingStream_Ethernet_SAMD**](examples/MQTT_ThingStream_Ethernet_SAMD) - * [12. **MQTT_ThingStream_Ethernet_SAM_DUE**](examples/MQTT_ThingStream_Ethernet_SAM_DUE) - * [13. **MQTT_ThingStream_Ethernet_Teensy**](examples/MQTT_ThingStream_Ethernet_Teensy) + * [ 8. Ethernet_WT32_ETH01](examples/Ethernet_WT32_ETH01). **New** + * [ 9. **MQTT_ThingStream_Ethernet_Generic**](examples/MQTT_ThingStream_Ethernet_Generic) + * [10. **MQTT_ThingStream_Ethernet_nRF52**](examples/MQTT_ThingStream_Ethernet_nRF52) + * [11. **MQTT_ThingStream_Ethernet_RP2040**](examples/MQTT_ThingStream_Ethernet_RP2040). **New** + * [12. **MQTT_ThingStream_Ethernet_SAMD**](examples/MQTT_ThingStream_Ethernet_SAMD) + * [13. **MQTT_ThingStream_Ethernet_SAM_DUE**](examples/MQTT_ThingStream_Ethernet_SAM_DUE) + * [14. **MQTT_ThingStream_Ethernet_Teensy**](examples/MQTT_ThingStream_Ethernet_Teensy) + * [15. **MQTT_ThingStream_Ethernet_WT32_ETH01**](examples/MQTT_ThingStream_Ethernet_WT32_ETH01). **New** * [So, how it works?](#so-how-it-works) * [Example Ethernet_Generic](#example-ethernet_generic) * [1. File Ethernet_Generic.ino](#1-file-ethernet_genericino) @@ -137,6 +140,10 @@ * [7. Ethernet_RP2040 on MBED RASPBERRY_PI_PICO with W5500 using EthernetLarge Library](#7-ethernet_rp2040-on-mbed-raspberry_pi_pico-with-w5500-using-ethernetlarge-library) * [7.1. DRD => Config Portal](#71-drd--config-portal) * [7.2. Data Saved => Exit Config Portal](#72-data-saved--exit-config-portal) + * [8. MQTT_ThingStream_Ethernet_WT32_ETH01 on WT32-ETH01](#8-mqtt_thingstream_ethernet_wt32_eth01-on-wt32-eth01) + * [8.1. Normal run with correct ThingStream MQTT Credentials](#81-normal-run-with-correct-thingstream-mqtt-credentials) + + * [Debug](#debug) * [Troubleshooting](#troubleshooting) * [Releases](#releases) @@ -203,20 +210,27 @@ This [**Ethernet_Manager** library](https://github.com/khoih-prog/Ethernet_Manag 9. RP2040-based boards, such as **Nano RP2040 Connect**, using [**Arduino mbed OS for Nano boards**](https://github.com/arduino/ArduinoCore-mbed). 10. RP2040-based boards, such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, using [**Arduino-mbed RP2040** v2.1.0+ core](https://github.com/arduino/ArduinoCore-mbed) + +11. **WT32_ETH01 boards** using ESP32-based boards and LAN8720 Ethernet + +--- - --- - -#### Currently Supported Ethernet shields/modules: +#### Supported Ethernet shields/modules: 1. W5x00 using [`Ethernet`](https://www.arduino.cc/en/Reference/Ethernet), [`EthernetLarge`](https://github.com/OPEnSLab-OSU/EthernetLarge), [`Ethernet2`](https://github.com/adafruit/Ethernet2) or [`Ethernet3`](https://github.com/sstaub/Ethernet3) library 2. ENC28J60 using [`EthernetENC`](https://github.com/jandrassy/EthernetENC) or [`UIPEthernet`](https://github.com/UIPEthernet/UIPEthernet) library 3. Teensy 4.1 NativeEthernet using [`NativeEthernet Library version stable111+`](https://github.com/vjmuzik/NativeEthernet). +4. LAN8720 Ethernet used in WT32_ETH01 boards --- --- ## Changelog +### Major Releases v1.5.0 + +1. Add support to ESP32-based WT32-ETH01 (ESP32 + LAN8720) boards, using EEPROM, SPIFFS or LittleFS + ### Major Releases v1.4.0 1. Add support to RP2040-based boards, such as **Nano RP2040 Connect**, using [**Arduino mbed OS for Nano boards**](https://github.com/arduino/ArduinoCore-mbed) and LittleFS. @@ -260,18 +274,18 @@ This [**Ethernet_Manager** library](https://github.com/khoih-prog/Ethernet_Manag ## Prerequisites - 1. [`Arduino IDE 1.8.13+` for Arduino](https://www.arduino.cc/en/Main/Software) + 1. [`Arduino IDE 1.8.15+` for Arduino](https://www.arduino.cc/en/Main/Software) 2. [`Teensy core v1.51`](https://www.pjrc.com/teensy/td_download.html) for Teensy (4.0, 3.6, 3.5, 3,2, 3.1, 3.0) boards and [`Teensy core v1.53+`](https://www.pjrc.com/teensy/td_download.html) for Teensy 4.1 boards using NativeEthernet. 3. [`Arduino SAM DUE core v1.6.12+`](https://www.arduino.cc/en/Guide/ArduinoDue) for SAM DUE ARM Cortex-M3 boards. 4. [`Arduino SAMD core 1.8.11+`](https://www.arduino.cc/en/Guide/ArduinoM0) for SAMD ARM Cortex-M0+ boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-samd.svg)](https://github.com/arduino/ArduinoCore-samd/releases/latest) - 5. [`Adafruit SAMD core 1.7.2+`](https://www.adafruit.com/) for SAMD ARM Cortex-M0+ and M4 boards (Nano 33 IoT, etc.). [![GitHub release](https://img.shields.io/github/release/adafruit/ArduinoCore-samd.svg)](https://github.com/adafruit/ArduinoCore-samd/releases/latest) + 5. [`Adafruit SAMD core 1.7.3+`](https://www.adafruit.com/) for SAMD ARM Cortex-M0+ and M4 boards (Nano 33 IoT, etc.). [![GitHub release](https://img.shields.io/github/release/adafruit/ArduinoCore-samd.svg)](https://github.com/adafruit/ArduinoCore-samd/releases/latest) 6. [`Seeeduino SAMD core 1.8.1+`](https://github.com/Seeed-Studio/ArduinoCore-samd) for SAMD21/SAMD51 boards (XIAO M0, Wio Terminal, etc.). [![Latest release](https://img.shields.io/github/release/Seeed-Studio/ArduinoCore-samd.svg)](https://github.com/Seeed-Studio/ArduinoCore-samd/releases/latest/) - 7. [`Adafruit nRF52 v0.22.1+`](https://www.adafruit.com) for nRF52 boards such as Adafruit NRF52840_FEATHER, NRF52832_FEATHER, NRF52840_FEATHER_SENSE, NRF52840_ITSYBITSY, NRF52840_CIRCUITPLAY, NRF52840_CLUE, NRF52840_METRO, NRF52840_PCA10056, PARTICLE_XENON, **NINA_B302_ublox**, etc. [![GitHub release](https://img.shields.io/github/release/adafruit/Adafruit_nRF52_Arduino.svg)](https://github.com/adafruit/Adafruit_nRF52_Arduino/releases/latest) - 8. [`ESP8266 Core 3.0.0+`](https://github.com/esp8266/Arduino) for ESP8266-based boards. [![Latest release](https://img.shields.io/github/release/esp8266/Arduino.svg)](https://github.com/esp8266/Arduino/releases/latest/). To use ESP8266 core 2.7.1+ for LittleFS. + 7. [`Adafruit nRF52 v0.24.0+`](https://www.adafruit.com) for nRF52 boards such as Adafruit NRF52840_FEATHER, NRF52832_FEATHER, NRF52840_FEATHER_SENSE, NRF52840_ITSYBITSY, NRF52840_CIRCUITPLAY, NRF52840_CLUE, NRF52840_METRO, NRF52840_PCA10056, PARTICLE_XENON, **NINA_B302_ublox**, etc. [![GitHub release](https://img.shields.io/github/release/adafruit/Adafruit_nRF52_Arduino.svg)](https://github.com/adafruit/Adafruit_nRF52_Arduino/releases/latest) + 8. [`ESP8266 Core 3.0.1+`](https://github.com/esp8266/Arduino) for ESP8266-based boards. [![Latest release](https://img.shields.io/github/release/esp8266/Arduino.svg)](https://github.com/esp8266/Arduino/releases/latest/). To use ESP8266 core 2.7.1+ for LittleFS. 9. [`ESP32 Core 1.0.6+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [![Latest release](https://img.shields.io/github/release/espressif/arduino-esp32.svg)](https://github.com/espressif/arduino-esp32/releases/latest/) 10. [`ESP32S2 Core 1.0.6+`](https://github.com/espressif/arduino-esp32/tree/esp32s2) for ESP32S2-based boards. -11. [`Earle Philhower's arduino-pico core v1.6.2+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest) -12. [`Arduino mbed_rp2040 core 2.1.0+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) RP2040-based boards, such as **Arduino Nano RP2040 Connect, RASPBERRY_PI_PICO, etc.**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest) +11. [`Earle Philhower's arduino-pico core v1.9.1+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest) +12. [`Arduino mbed_rp2040 core 2.2.0+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) RP2040-based boards, such as **Arduino Nano RP2040 Connect, RASPBERRY_PI_PICO, etc.**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest) 13. Depending on which Ethernet card you're using: - [`Ethernet library v2.0.0+`](https://github.com/arduino-libraries/Ethernet) for W5100, W5200 and W5500. [![GitHub release](https://img.shields.io/github/release/arduino-libraries/Ethernet.svg)](https://github.com/arduino-libraries/Ethernet/releases/latest) - [`EthernetLarge library v2.0.0+`](https://github.com/OPEnSLab-OSU/EthernetLarge) for W5100, W5200 and W5500. @@ -285,10 +299,11 @@ This [**Ethernet_Manager** library](https://github.com/khoih-prog/Ethernet_Manag - [`FlashStorage_SAMD library v1.1.0+`](https://github.com/khoih-prog/FlashStorage_SAMD) for SAMD21 and SAMD51 boards (ZERO, MKR, NANO_33_IOT, M0, M0 Pro, AdaFruit Itsy-Bitsy M4, etc.). [![GitHub release](https://img.shields.io/github/release/khoih-prog/FlashStorage_SAMD.svg)](https://github.com/khoih-prog/FlashStorage_SAMD/releases/latest) - [`Adafruit's LittleFS/InternalFS`](www.adafruit.com) for nRF52 15. [`EthernetWebServer library v1.5.0+`](https://github.com/khoih-prog/EthernetWebServer). To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/EthernetWebServer.svg?)](https://www.ardu-badge.com/EthernetWebServer). -16. [`ESP_DoubleResetDetector library v1.1.1+`](https://github.com/khoih-prog/ESP_DoubleResetDetector) for ESP32 and ESP8266. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_DoubleResetDetector.svg?)](https://www.ardu-badge.com/ESP_DoubleResetDetector). -17. [`DoubleResetDetector_Generic library v1.3.0+`](https://github.com/khoih-prog/DoubleResetDetector_Generic) for other boards (not ESP32 or ESP8266). To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/DoubleResetDetector_Generic.svg?)](https://www.ardu-badge.com/DoubleResetDetector_Generic). -18. [`Functional-VLPP library v1.0.2+`](https://github.com/khoih-prog/functional-vlpp) to use server's lambda function. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/Functional-Vlpp.svg?)](https://www.ardu-badge.com/Functional-Vlpp) -19. [`LittleFS_esp32 v1.0.6+`](https://github.com/lorol/LITTLEFS) for ESP32-based boards using LittleFS. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/LittleFS_esp32.svg?)](https://www.ardu-badge.com/LittleFS_esp32). **Notice**: This [`LittleFS_esp32 library`](https://github.com/lorol/LITTLEFS) has been integrated to Arduino [esp32 core v1.0.6](https://github.com/espressif/arduino-esp32/tree/master/libraries/LITTLEFS). +16. [`WebServer_WT32_ETH01 library v1.1.0+`](https://github.com/khoih-prog/WebServer_WT32_ETH01) for WT32_ETH01 boards. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/WebServer_WT32_ETH01.svg?)](https://www.ardu-badge.com/WebServer_WT32_ETH01). +17. [`ESP_DoubleResetDetector library v1.1.1+`](https://github.com/khoih-prog/ESP_DoubleResetDetector) for ESP32 and ESP8266. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/ESP_DoubleResetDetector.svg?)](https://www.ardu-badge.com/ESP_DoubleResetDetector). +18. [`DoubleResetDetector_Generic library v1.4.0+`](https://github.com/khoih-prog/DoubleResetDetector_Generic) for other boards (not ESP32 or ESP8266). To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/DoubleResetDetector_Generic.svg?)](https://www.ardu-badge.com/DoubleResetDetector_Generic). +19. [`Functional-VLPP library v1.0.2+`](https://github.com/khoih-prog/functional-vlpp) to use server's lambda function. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/Functional-Vlpp.svg?)](https://www.ardu-badge.com/Functional-Vlpp) +20. [`LittleFS_esp32 v1.0.6+`](https://github.com/lorol/LITTLEFS) for ESP32-based boards using LittleFS. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/LittleFS_esp32.svg?)](https://www.ardu-badge.com/LittleFS_esp32). **Notice**: This [`LittleFS_esp32 library`](https://github.com/lorol/LITTLEFS) has been integrated to Arduino [esp32 core v1.0.6](https://github.com/espressif/arduino-esp32/tree/master/libraries/LITTLEFS). --- @@ -1325,12 +1340,14 @@ Please be noted that the following **reserved names are already used in library* 5. [Ethernet_SAMD](examples/Ethernet_SAMD) 6. [Ethernet_SAM_DUE](examples/Ethernet_SAM_DUE) 7. [Ethernet_Teensy](examples/Ethernet_Teensy) - 8. [**MQTT_ThingStream_Ethernet_Generic**](examples/MQTT_ThingStream_Ethernet_Generic). - 9. [**MQTT_ThingStream_Ethernet_nRF52**](examples/MQTT_ThingStream_Ethernet_nRF52). -10. [**MQTT_ThingStream_Ethernet_RP2040**](examples/MQTT_ThingStream_Ethernet_RP2040). **New** -11. [**MQTT_ThingStream_Ethernet_SAMD**](examples/MQTT_ThingStream_Ethernet_SAMD). -12. [**MQTT_ThingStream_Ethernet_SAM_DUE**](examples/MQTT_ThingStream_Ethernet_SAM_DUE). -13. [**MQTT_ThingStream_Ethernet_Teensy**](examples/MQTT_ThingStream_Ethernet_Teensy). + 8. [Ethernet_WT32_ETH01](examples/Ethernet_WT32_ETH01). **New** + 9. [**MQTT_ThingStream_Ethernet_Generic**](examples/MQTT_ThingStream_Ethernet_Generic). +10. [**MQTT_ThingStream_Ethernet_nRF52**](examples/MQTT_ThingStream_Ethernet_nRF52). +11. [**MQTT_ThingStream_Ethernet_RP2040**](examples/MQTT_ThingStream_Ethernet_RP2040). **New** +12. [**MQTT_ThingStream_Ethernet_SAMD**](examples/MQTT_ThingStream_Ethernet_SAMD). +13. [**MQTT_ThingStream_Ethernet_SAM_DUE**](examples/MQTT_ThingStream_Ethernet_SAM_DUE). +14. [**MQTT_ThingStream_Ethernet_Teensy**](examples/MQTT_ThingStream_Ethernet_Teensy). +15. [**MQTT_ThingStream_Ethernet_WT32_ETH01**](examples/MQTT_ThingStream_Ethernet_WT32_ETH01). **New** --- --- @@ -2413,8 +2430,8 @@ This is the terminal output of an Adafruit NRF52840_FEATHER board with W5500 Eth ``` Start Ethernet_nRF52 on NRF52840_FEATHER Ethernet Shield type W5x00 using Ethernet2 Library -Ethernet_Manager v1.4.0 -DoubleResetDetector_Generic v1.3.0 +Ethernet_Manager v1.5.0 +DoubleResetDetector_Generic v1.4.0 [ETHERNET_WEBSERVER] =========== USE_ETHERNET2 =========== [ETHERNET_WEBSERVER] Default SPI pinout: [ETHERNET_WEBSERVER] MOSI: 25 @@ -2505,8 +2522,8 @@ Pubs Topics = old-mqtt-PubTopic ```cpp Start Ethernet_nRF52 on NRF52840_FEATHER Ethernet Shield type : W5x00 using Ethernet2 Library -Ethernet_Manager v1.4.0 -DoubleResetDetector_Generic v1.3.0 +Ethernet_Manager v1.5.0 +DoubleResetDetector_Generic v1.4.0 [ETHERNET_WEBSERVER] =========== USE_ETHERNET2 =========== [ETHERNET_WEBSERVER] Default SPI pinout: [ETHERNET_WEBSERVER] MOSI: 25 @@ -2688,8 +2705,8 @@ This is the terminal output of an SeeedStudio SAMD21 SEEED_XIAO_M0 board with W5 ``` Start Ethernet_SAMD on SEEED_XIAO_M0 Ethernet Shield type : W5x00 using Ethernet Library -Ethernet_Manager v1.4.0 -DoubleResetDetector_Generic v1.3.0 +Ethernet_Manager v1.5.0 +DoubleResetDetector_Generic v1.4.0 Flag read = 0xffffffff No doubleResetDetected SetFlag write = 0xd0d01234 @@ -2765,8 +2782,8 @@ This is the terminal output of an Arduino SAM DUE board with W5100 Ethernet shie ``` Start Ethernet_SAM_DUE on SAM DUE Ethernet Shield type : W5x00 using EthernetLarge Library -Ethernet_Manager v1.4.0 -DoubleResetDetector_Generic v1.3.0 +Ethernet_Manager v1.5.0 +DoubleResetDetector_Generic v1.4.0 Flag read = 0xd0d01234 doubleResetDetected ClearFlag write = 0xd0d04321 @@ -2851,7 +2868,7 @@ If no valid config data are stored in EEPROM, it will switch to `Configuration M ``` Start MQTT_ThingStream_Ethernet_Generic using LittleFS on ESP8266_NODEMCU Ethernet Shield type : W5x00 using Ethernet2 Library -Ethernet_Manager v1.4.0 +Ethernet_Manager v1.5.0 ESP_DoubleResetDetector Version v1.1.1 ========================= Currently Used SPI pinout: @@ -2899,7 +2916,7 @@ Enter your credentials (Blynk Servers/Tokens and Port). If you prefer static IP, ``` Start MQTT_ThingStream_Ethernet_Generic using LittleFS on ESP8266_NODEMCU Ethernet Shield type : W5x00 using Ethernet2 Library -Ethernet_Manager v1.4.0 +Ethernet_Manager v1.5.0 ESP_DoubleResetDetector Version v1.1.1 ========================= Currently Used SPI pinout: @@ -2959,8 +2976,8 @@ This is the terminal output of NRF52840_FEATHER board with ENC28J60 using Ethern ``` Start MQTT_ThingStream_Ethernet_Generic on NRF52840_FEATHER Ethernet Shield type : ENC28J60 using EthernetENC Library -Ethernet_Manager v1.4.0 -DoubleResetDetector_Generic v1.3.0 +Ethernet_Manager v1.5.0 +DoubleResetDetector_Generic v1.4.0 LittleFS Flag read = 0xd0d01234 Flag read = 0xd0d01234 doubleResetDetected @@ -2997,8 +3014,8 @@ esp32-sniffer/12345678/ble ``` Start MQTT_ThingStream_Ethernet_Generic on NRF52840_FEATHER Ethernet Shield type : ENC28J60 using EthernetENC Library -Ethernet_Manager v1.4.0 -DoubleResetDetector_Generic v1.3.0 +Ethernet_Manager v1.5.0 +DoubleResetDetector_Generic v1.4.0 LittleFS Flag read = 0xd0d04321 Flag read = 0xd0d04321 No doubleResetDetected @@ -3054,8 +3071,8 @@ This is the terminal output of RASPBERRY_PI_PICO board with W5x00 using Ethernet ``` Start MQTT_ThingStream_Ethernet_RP2040 on RASPBERRY_PI_PICO Ethernet Shield type : W5x00 using Ethernet Library -Ethernet_Manager v1.4.0 -DoubleResetDetector_Generic v1.3.0 +Ethernet_Manager v1.5.0 +DoubleResetDetector_Generic v1.4.0 [EWS] =========== USE_ETHERNET =========== [EWS] Default SPI pinout: [EWS] MOSI: 19 @@ -3111,8 +3128,8 @@ esp32-sniffer/12345678/ble ``` Start MQTT_ThingStream_Ethernet_RP2040 on RASPBERRY_PI_PICO Ethernet Shield type : W5x00 using Ethernet Library -Ethernet_Manager v1.4.0 -DoubleResetDetector_Generic v1.3.0 +Ethernet_Manager v1.5.0 +DoubleResetDetector_Generic v1.4.0 [EWS] =========== USE_ETHERNET =========== [EWS] Default SPI pinout: [EWS] MOSI: 19 @@ -3184,8 +3201,8 @@ This is the terminal output of an MBED RASPBERRY_PI_PICO board with W5500 Ethern ``` Start Ethernet_RP2040 on MBED RASPBERRY_PI_PICO Ethernet Shield type : W5x00 using EthernetLarge Library -Ethernet_Manager v1.4.0 -DoubleResetDetector_Generic v1.3.0 +Ethernet_Manager v1.5.0 +DoubleResetDetector_Generic v1.4.0 [EWS] =========== USE_ETHERNET_LARGE =========== [EWS] Default SPI pinout: [EWS] MOSI: 3 @@ -3257,8 +3274,8 @@ HHHH[ETM] h:Updating LittleFS: /fs/etm_config.dat ``` Start Ethernet_RP2040 on MBED RASPBERRY_PI_PICO Ethernet Shield type : W5x00 using EthernetLarge Library -Ethernet_Manager v1.4.0 -DoubleResetDetector_Generic v1.3.0 +Ethernet_Manager v1.5.0 +DoubleResetDetector_Generic v1.4.0 [EWS] =========== USE_ETHERNET_LARGE =========== [EWS] Default SPI pinout: [EWS] MOSI: 3 @@ -3314,6 +3331,92 @@ ClearFlag write = 0xd0d04321 HHHHHH ``` +--- + + +#### 8. MQTT_ThingStream_Ethernet_WT32_ETH01 on WT32-ETH01 + +This is the terminal output of WT32-ETH01 board with LAN8720 Ethernet, running complex [MQTT_ThingStream_Ethernet_WT32_ETH01](examples/MQTT_ThingStream_Ethernet_WT32_ETH01) example to demonstrate how to use dynamic parameters, entered via Config Portal, to connect to [**ThingStream MQTT Server**](mqtt.thingstream.io). + +#### 8.1. Normal run with correct ThingStream MQTT Credentials + +``` +Start MQTT_ThingStream_Ethernet_WT32_ETH01 on WT32-ETH01 +Ethernet Shield type : ETH_PHY_LAN8720 +WebServer_WT32_ETH01 v1.1.0 +Ethernet_Manager v1.5.0 +ESP_DoubleResetDetector v1.1.1 +[ETM] Set CustomsStyle to : +[ETM] Set CustomsHeadElement to : +[ETM] Set CORS Header to : Your Access-Control-Allow-Origin +LittleFS Flag read = 0xD0D04321 +No doubleResetDetected +Saving config file... +Saving config file OK +[ETM] LoadCfgFile +[ETM] OK +[ETM] ======= Start Stored Config Data ======= +[ETM] Header= WT32_ETH01 , BoardName= WT32_ETH01 +[ETM] StaticIP= 192.168.2.232 +[ETM] i= 0 ,id= mqtt +[ETM] data= default-mqtt-server +[ETM] i= 1 ,id= mqpt +[ETM] data= 1883 +[ETM] i= 2 ,id= user +[ETM] data= default-mqtt-username +[ETM] i= 3 ,id= mqpw +[ETM] data= default-mqtt-password +[ETM] i= 4 ,id= clid +[ETM] data= default-mqtt-clientID +[ETM] CCSum=0x 7f0 ,RCSum=0x 7f0 +[ETM] LoadCredFile +[ETM] CrR:pdata= mqtt.thingstream.io ,len= 48 +[ETM] CrR:pdata= 1883 ,len= 6 +[ETM] CrR:pdata= mqtt_user ,len= 34 +[ETM] CrR:pdata= mqtt_pass ,len= 48 +[ETM] CrR:pdata= client_ID ,len= 48 +[ETM] OK +[ETM] CrCCsum=0x 2785 ,CrRCsum=0x 2785 +[ETM] Valid Stored Dynamic Data +[ETM] Start connectEthernet using Static IP = 192.168.2.232 +[ETM] myGW IP = 192.168.2.1 +[ETM] ETH Started +[ETM] ETH MAC: A8:03:2A:A1:61:73 , IPv4: 192.168.2.232 +[ETM] FULL_DUPLEX, Link Speed (Mbps) 100 +[ETM] IP: 192.168.2.232 +[ETM] Check if isForcedCP +[ETM] LoadCPFile +[ETM] OK +[ETM] begin:Ethernet Connected. +Connected! IP address: 192.168.2.232 +*************************************** +esp32-sniffer/12345678/ble +*************************************** +Connecting to MQTT_SERVER = mqtt.thingstream.io, MQTT_PORT= 1883 +Attempting MQTT connection to mqtt.thingstream.io +MQTT_CLIENT_ID = client_ID +MQTT_USER = mqtt_user +MQTT_PASS = mqtt_pass +...connected +Published connection message successfully! +Subcribed to: esp32-sniffer/12345678/ble + +Your stored Credentials : +MQTT Server = mqtt.thingstream.io +Port = 1883 +MQTT UserName = mqtt_user +MQTT PWD = mqtt_pass +Client ID = client_ID +HStop doubleResetDetecting +Saving config file... +Saving config file OK + +MQTT Message Send : esp32-sniffer/12345678/ble => Hello from MQTT_ThingStream on WT32-ETH01 with ETH_PHY_LAN8720 +H +MQTT Message receive [esp32-sniffer/12345678/ble] Hello from MQTT_ThingStream on WT32-ETH01 with ETH_PHY_LAN8720 +H +``` + --- --- @@ -3345,6 +3448,10 @@ Sometimes, the library will only work if you update the board core to the latest ## Releases +### Major Releases v1.5.0 + +1. Add support to ESP32-based WT32-ETH01 (ESP32 + LAN8720) boards, using EEPROM, SPIFFS or LittleFS + ### Major Releases v1.4.0 1. Add support to RP2040-based boards, such as **Nano RP2040 Connect**, using [**Arduino mbed OS for Nano boards**](https://github.com/arduino/ArduinoCore-mbed) and LittleFS. @@ -3405,12 +3512,15 @@ This [**Ethernet_Manager** library](https://github.com/khoih-prog/Ethernet_Manag 8. RP2040-based boards, such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, using [Earle Philhower's arduino-pico core](https://github.com/earlephilhower/arduino-pico). 9. RP2040-based boards, such as **Nano RP2040 Connect**, using [**Arduino mbed OS for Nano boards**](https://github.com/arduino/ArduinoCore-mbed). 10. RP2040-based boards, such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, using [**Arduino-mbed RP2040** v2.1.0+ core](https://github.com/arduino/ArduinoCore-mbed) + +11. **WT32_ETH01 boards** using ESP32-based boards and LAN8720 Ethernet #### Supported Ethernet shields/modules: 1. W5x00 using [`Ethernet`](https://www.arduino.cc/en/Reference/Ethernet), [`EthernetLarge`](https://github.com/OPEnSLab-OSU/EthernetLarge), [`Ethernet2`](https://github.com/adafruit/Ethernet2) or [`Ethernet3`](https://github.com/sstaub/Ethernet3) library 2. ENC28J60 using [`EthernetENC`](https://github.com/jandrassy/EthernetENC) or [`UIPEthernet`](https://github.com/UIPEthernet/UIPEthernet) library 3. Teensy 4.1 NativeEthernet using [`NativeEthernet Library version stable111+`](https://github.com/vjmuzik/NativeEthernet). +4. LAN8720 Ethernet used in WT32_ETH01 boards --- --- @@ -3457,6 +3567,8 @@ Default Credentials and dynamic parameters 23. Add support to RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, using [Earle Philhower's arduino-pico core](https://github.com/earlephilhower/arduino-pico) and LittleFS. 24. Add support to RP2040-based boards, such as **Nano RP2040 Connect**, using [**Arduino mbed OS for Nano boards**](https://github.com/arduino/ArduinoCore-mbed) and LittleFS. 25. Add support to RP2040-based boards, such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, using [**Arduino-mbed RP2040** v2.1.0+ core](https://github.com/arduino/ArduinoCore-mbed) and LittleFS. +26. Add support to **WT32_ETH01 boards** using ESP32-based boards and LAN8720 Ethernet + --- --- diff --git a/examples/AM2315_Ethernet/AM2315_Ethernet.ino b/examples/AM2315_Ethernet/AM2315_Ethernet.ino index f94bc24f..b22606af 100644 --- a/examples/AM2315_Ethernet/AM2315_Ethernet.ino +++ b/examples/AM2315_Ethernet/AM2315_Ethernet.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** AM2315_Ethernet.ino - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/AM2315_Ethernet/Credentials.h b/examples/AM2315_Ethernet/Credentials.h index 1c82d900..e899daf7 100644 --- a/examples/AM2315_Ethernet/Credentials.h +++ b/examples/AM2315_Ethernet/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/AM2315_Ethernet/defines.h b/examples/AM2315_Ethernet/defines.h index 4014702d..0498bb80 100644 --- a/examples/AM2315_Ethernet/defines.h +++ b/examples/AM2315_Ethernet/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/AM2315_Ethernet/dynamicParams.h b/examples/AM2315_Ethernet/dynamicParams.h index ba75afdc..c1486b08 100644 --- a/examples/AM2315_Ethernet/dynamicParams.h +++ b/examples/AM2315_Ethernet/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_Generic/Credentials.h b/examples/Ethernet_Generic/Credentials.h index 4654c7b9..84826cf4 100644 --- a/examples/Ethernet_Generic/Credentials.h +++ b/examples/Ethernet_Generic/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_Generic/Ethernet_Generic.ino b/examples/Ethernet_Generic/Ethernet_Generic.ino index 3d63cff2..039e1ba9 100644 --- a/examples/Ethernet_Generic/Ethernet_Generic.ino +++ b/examples/Ethernet_Generic/Ethernet_Generic.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** Ethernet_Generic.ino - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/Ethernet_Generic/defines.h b/examples/Ethernet_Generic/defines.h index 4014702d..0498bb80 100644 --- a/examples/Ethernet_Generic/defines.h +++ b/examples/Ethernet_Generic/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_Generic/dynamicParams.h b/examples/Ethernet_Generic/dynamicParams.h index ba75afdc..c1486b08 100644 --- a/examples/Ethernet_Generic/dynamicParams.h +++ b/examples/Ethernet_Generic/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_RP2040/Credentials.h b/examples/Ethernet_RP2040/Credentials.h index 6b14fa72..d7b1ee21 100644 --- a/examples/Ethernet_RP2040/Credentials.h +++ b/examples/Ethernet_RP2040/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_RP2040/Ethernet_RP2040.ino b/examples/Ethernet_RP2040/Ethernet_RP2040.ino index f3d7c094..bbb512cf 100644 --- a/examples/Ethernet_RP2040/Ethernet_RP2040.ino +++ b/examples/Ethernet_RP2040/Ethernet_RP2040.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** Ethernet_RP2040.ino - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/Ethernet_RP2040/defines.h b/examples/Ethernet_RP2040/defines.h index c563df59..cdb37018 100644 --- a/examples/Ethernet_RP2040/defines.h +++ b/examples/Ethernet_RP2040/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_RP2040/dynamicParams.h b/examples/Ethernet_RP2040/dynamicParams.h index ba75afdc..c1486b08 100644 --- a/examples/Ethernet_RP2040/dynamicParams.h +++ b/examples/Ethernet_RP2040/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_SAMD/Credentials.h b/examples/Ethernet_SAMD/Credentials.h index 252abc7a..10fca1dc 100644 --- a/examples/Ethernet_SAMD/Credentials.h +++ b/examples/Ethernet_SAMD/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_SAMD/Ethernet_SAMD.ino b/examples/Ethernet_SAMD/Ethernet_SAMD.ino index cb50d273..6e9fef68 100644 --- a/examples/Ethernet_SAMD/Ethernet_SAMD.ino +++ b/examples/Ethernet_SAMD/Ethernet_SAMD.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** Ethernet_SAMD.ino - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/Ethernet_SAMD/defines.h b/examples/Ethernet_SAMD/defines.h index 4d6319a0..0b3e70c0 100644 --- a/examples/Ethernet_SAMD/defines.h +++ b/examples/Ethernet_SAMD/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_SAMD/dynamicParams.h b/examples/Ethernet_SAMD/dynamicParams.h index ba75afdc..c1486b08 100644 --- a/examples/Ethernet_SAMD/dynamicParams.h +++ b/examples/Ethernet_SAMD/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_SAM_DUE/Credentials.h b/examples/Ethernet_SAM_DUE/Credentials.h index ba49a58e..24d17885 100644 --- a/examples/Ethernet_SAM_DUE/Credentials.h +++ b/examples/Ethernet_SAM_DUE/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_SAM_DUE/Ethernet_SAM_DUE.ino b/examples/Ethernet_SAM_DUE/Ethernet_SAM_DUE.ino index 615384d2..b3991233 100644 --- a/examples/Ethernet_SAM_DUE/Ethernet_SAM_DUE.ino +++ b/examples/Ethernet_SAM_DUE/Ethernet_SAM_DUE.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** Ethernet_SAM_DUE.ino - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/Ethernet_SAM_DUE/defines.h b/examples/Ethernet_SAM_DUE/defines.h index f9ddfe5e..5e5cbf1c 100644 --- a/examples/Ethernet_SAM_DUE/defines.h +++ b/examples/Ethernet_SAM_DUE/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_SAM_DUE/dynamicParams.h b/examples/Ethernet_SAM_DUE/dynamicParams.h index ba75afdc..c1486b08 100644 --- a/examples/Ethernet_SAM_DUE/dynamicParams.h +++ b/examples/Ethernet_SAM_DUE/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_Teensy/Credentials.h b/examples/Ethernet_Teensy/Credentials.h index 277f524d..b6ecdeaf 100644 --- a/examples/Ethernet_Teensy/Credentials.h +++ b/examples/Ethernet_Teensy/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_Teensy/Ethernet_Teensy.ino b/examples/Ethernet_Teensy/Ethernet_Teensy.ino index 0c61f255..e79dc8d6 100644 --- a/examples/Ethernet_Teensy/Ethernet_Teensy.ino +++ b/examples/Ethernet_Teensy/Ethernet_Teensy.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** Ethernet_Teensy.ino - For W5x00, ENC28J60 and Teensy 4.1 NativeEthernet. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/Ethernet_Teensy/defines.h b/examples/Ethernet_Teensy/defines.h index 2d588127..d2ba9487 100644 --- a/examples/Ethernet_Teensy/defines.h +++ b/examples/Ethernet_Teensy/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_Teensy/dynamicParams.h b/examples/Ethernet_Teensy/dynamicParams.h index ba75afdc..c1486b08 100644 --- a/examples/Ethernet_Teensy/dynamicParams.h +++ b/examples/Ethernet_Teensy/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_WT32_ETH01/Credentials.h b/examples/Ethernet_WT32_ETH01/Credentials.h new file mode 100644 index 00000000..80e3627a --- /dev/null +++ b/examples/Ethernet_WT32_ETH01/Credentials.h @@ -0,0 +1,67 @@ +/**************************************************************************************************************************** + Credentials.h + For W5x00, LAN8720 and ENC28J60 Ethernet shields. + + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + AVR Mega is not supported. + + Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager + Licensed under MIT license + *****************************************************************************************************************************/ + +#ifndef Credentials_h +#define Credentials_h + +#include "defines.h" + +/// Start Default Config Data ////////////////// + +/* +typedef struct Configuration +{ + char header [16]; + char static_IP [16]; + char board_name [24]; + int checkSum; +} Ethernet_Configuration; +*/ + +#define TO_LOAD_DEFAULT_CONFIG_DATA false + +#if TO_LOAD_DEFAULT_CONFIG_DATA + +bool LOAD_DEFAULT_CONFIG_DATA = false; + +Ethernet_Configuration defaultConfig = +{ + //char header[16], dummy, not used +#if USE_SSL + "Eth_SSL", +#else + "Eth_NonSSL", +#endif + + // char static_IP [16]; + //"192.168.2.232", + // Use dynamic DHCP IP + "", + //char board_name [24]; + "WT32-ETH01", + // terminate the list + //int checkSum, dummy, not used + 0 + /////////// End Default Config Data ///////////// +}; + +#else + +bool LOAD_DEFAULT_CONFIG_DATA = false; + +Ethernet_Configuration defaultConfig; + +#endif // TO_LOAD_DEFAULT_CONFIG_DATA + +/////////// End Default Config Data ///////////// + +#endif //Credentials_h diff --git a/examples/Ethernet_WT32_ETH01/Ethernet_WT32_ETH01.ino b/examples/Ethernet_WT32_ETH01/Ethernet_WT32_ETH01.ino new file mode 100644 index 00000000..a52abaa5 --- /dev/null +++ b/examples/Ethernet_WT32_ETH01/Ethernet_WT32_ETH01.ino @@ -0,0 +1,215 @@ +/**************************************************************************************************************************** + Ethernet_RP2040.ino + For W5x00, LAN8720 and ENC28J60 Ethernet shields. + + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + AVR Mega is not supported. + + Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager + Licensed under MIT license + + Version: 1.5.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 14/12/2020 Initial coding. + 1.1.0 K Hoang 17/12/2020 Add support to ESP32/ESP8266. Add MQTT related examples to demo dynamic parameter usage + 1.1.1 K Hoang 28/12/2020 Suppress all possible compiler warnings + 1.2.0 K Hoang 22/02/2021 Optimize code and use better FlashStorage_SAMD and FlashStorage_STM32. + Add customs HTML header feature. Fix bug. + 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO + 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards + *****************************************************************************************************************************/ + +#include "defines.h" +#include "Credentials.h" +#include "dynamicParams.h" + +Ethernet_Manager ethernet_manager; + +IPAddress localEthernetIP; + +void heartBeatPrint() +{ + static int num = 1; + + localEthernetIP = ETH.localIP(); + + if ( ( (uint32_t) localEthernetIP != 0 ) ) + { + Serial.print(F("H")); + } + else + Serial.print(F("F")); + + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } +} + +void check_status() +{ + #define STATUS_CHECK_INTERVAL 10000L + + static unsigned long checkstatus_timeout = STATUS_CHECK_INTERVAL; + + // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. + if ((millis() > checkstatus_timeout)) + { + heartBeatPrint(); + checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; + } +} + +#if USING_CUSTOMS_STYLE +const char NewCustomsStyle[] /*PROGMEM*/ = ""; +#endif + +void WiFiEvent(WiFiEvent_t event) +{ + switch (event) + { + case SYSTEM_EVENT_ETH_START: + ETM_LOGERROR(F("ETH Started")); + //set eth hostname here + ETH.setHostname("WT32-ETH01"); + break; + case SYSTEM_EVENT_ETH_CONNECTED: + ETM_LOGERROR(F("ETH Connected")); + break; + + case SYSTEM_EVENT_ETH_GOT_IP: + if (!ethernet_manager.ethernetConnected) + { + ETM_LOGERROR3(F("ETH MAC:"), ETH.macAddress(), F(", IPv4:"), ETH.localIP()); + + if (ETH.fullDuplex()) + { + ETM_LOGERROR1(F("FULL_DUPLEX, Link Speed (Mbps)"), ETH.linkSpeed()); + } + else + { + ETM_LOGERROR1(F("HALF_DUPLEX, Link Speed (Mbps)"), ETH.linkSpeed()); + } + + ethernet_manager.ethernetConnected = true; + } + + break; + + case SYSTEM_EVENT_ETH_DISCONNECTED: + ETM_LOGERROR(F("ETH Disconnected")); + ethernet_manager.ethernetConnected = false; + break; + + case SYSTEM_EVENT_ETH_STOP: + ETM_LOGERROR(F("\nETH Stopped")); + ethernet_manager.ethernetConnected = false; + break; + + default: + break; + } +} + +void setup() +{ + // Debug console + Serial.begin(115200); + while (!Serial); + + // Using this if Serial debugging is not necessary or not using Serial port + //while (!Serial && (millis() < 3000)); + + Serial.print("\nStart Ethernet_WT32_ETH01 on "); Serial.println(BOARD_NAME); + Serial.print("Ethernet Shield type : "); Serial.println(SHIELD_TYPE); + Serial.println(WEBSERVER_WT32_ETH01_VERSION); + Serial.println(ETHERNET_MANAGER_VERSION); + Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION); + + WiFi.onEvent(WiFiEvent); + + ////////////////////////////////////////////// + +#if USING_CUSTOMS_STYLE + ethernet_manager.setCustomsStyle(NewCustomsStyle); +#endif + +#if USING_CUSTOMS_HEAD_ELEMENT + ethernet_manager.setCustomsHeadElement(""); +#endif + +#if USING_CORS_FEATURE + ethernet_manager.setCORSHeader("Your Access-Control-Allow-Origin"); +#endif + + ethernet_manager.begin(); + + ////////////////////////////////////////////// + + localEthernetIP = ETH.localIP(); + + if ( (uint32_t) localEthernetIP != 0 ) + { + Serial.print(F("Connected! IP address: ")); + Serial.println(localEthernetIP); + } + else + { + Serial.println(F("Ethernet not Connected! Please check.")); + } +} + +#if (USE_DYNAMIC_PARAMETERS) +void displayCredentials() +{ + Serial.println("\nYour stored Credentials :"); + + for (int i = 0; i < NUM_MENU_ITEMS; i++) + { + Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata); + } +} + +void displayCredentialsOnce() +{ + static bool displayedCredentials = false; + + if (!displayedCredentials) + { + for (int i = 0; i < NUM_MENU_ITEMS; i++) + { + if (!strlen(myMenuItems[i].pdata)) + { + break; + } + + if ( i == (NUM_MENU_ITEMS - 1) ) + { + displayedCredentials = true; + displayCredentials(); + } + } + } +} +#endif + +void loop() +{ + ethernet_manager.run(); + + check_status(); + +#if (USE_DYNAMIC_PARAMETERS) + displayCredentialsOnce(); +#endif +} diff --git a/examples/Ethernet_WT32_ETH01/defines.h b/examples/Ethernet_WT32_ETH01/defines.h new file mode 100644 index 00000000..8dc1e13d --- /dev/null +++ b/examples/Ethernet_WT32_ETH01/defines.h @@ -0,0 +1,70 @@ +/**************************************************************************************************************************** + defines.h + For W5x00, LAN8720 and ENC28J60 Ethernet shields. + + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + AVR Mega is not supported. + + Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager + Licensed under MIT license + *****************************************************************************************************************************/ + +#ifndef defines_h +#define defines_h + +#if ESP32 + #if defined(ETHERNET_USE_WT32_ETH01) + #undef ETHERNET_USE_WT32_ETH01 + #endif + #define ETHERNET_USE_WT32_ETH01 true + #define USE_DYNAMIC_PARAMETERS true + + #warning Use ESP32 architecture for WT32_ETH01 +#else + #error This code is designed to run on WT32_ETH01 and ESP32 platform! Please check your Tools->Board setting. +#endif + +/* Comment this out to disable prints and save space */ +#define DEBUG_ETHERNET_WEBSERVER_PORT Serial + +// Debug Level from 0 to 4 +#define _ETHERNET_WEBSERVER_LOGLEVEL_ 2 +#define _ETHERNET_MANAGER_LOGLEVEL_ 2 + +///////////////////////////////////////////// + +#define DOUBLERESETDETECTOR_DEBUG true + +#define USE_LITTLEFS true +#define USE_SPIFFS false + +///////////////////////////////////////////// + +// Add customs headers from v1.2.0 +#define USING_CUSTOMS_STYLE true +#define USING_CUSTOMS_HEAD_ELEMENT true +#define USING_CORS_FEATURE true + +///////////////////////////////////////////// + +// Config Timeout 120s (default 60s) +#define CONFIG_TIMEOUT 120000L + +#define USE_DYNAMIC_PARAMETERS true + +////////////////////////////////////////// + + +#include + +#ifndef SHIELD_TYPE +#define SHIELD_TYPE "WT32_ETH01" +#endif + +#define W5100_CS 10 +#define SDCARD_CS 4 + +#define ETHERNET_HOST_NAME "WT32_ETH01" + +#endif //defines_h diff --git a/examples/Ethernet_WT32_ETH01/dynamicParams.h b/examples/Ethernet_WT32_ETH01/dynamicParams.h new file mode 100644 index 00000000..c1486b08 --- /dev/null +++ b/examples/Ethernet_WT32_ETH01/dynamicParams.h @@ -0,0 +1,76 @@ +/**************************************************************************************************************************** + dynamicParams.h + For W5x00, LAN8720 and ENC28J60 Ethernet shields. + + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + AVR Mega is not supported. + + Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager + Licensed under MIT license + *****************************************************************************************************************************/ + +#ifndef dynamicParams_h +#define dynamicParams_h + +#include "defines.h" + +// USE_DYNAMIC_PARAMETERS defined in defined.h + +/////////////// Start dynamic Credentials /////////////// + +/************************************** + #define MAX_ID_LEN 5 + #define MAX_DISPLAY_NAME_LEN 16 + + typedef struct + { + char id [MAX_ID_LEN + 1]; + char displayName [MAX_DISPLAY_NAME_LEN + 1]; + char *pdata; + uint8_t maxlen; + } MenuItem; +**************************************/ + +#if USE_DYNAMIC_PARAMETERS + + #define MAX_MQTT_SERVER_LEN 34 + char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server"; + + #define MAX_MQTT_PORT_LEN 6 + char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883"; + + #define MAX_MQTT_USERNAME_LEN 34 + char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username"; + + #define MAX_MQTT_PW_LEN 34 + char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password"; + + #define MAX_MQTT_SUBS_TOPIC_LEN 34 + char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic"; + + #define MAX_MQTT_PUB_TOPIC_LEN 34 + char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic"; + + MenuItem myMenuItems [] = + { + { "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN }, + { "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN }, + { "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN }, + { "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN }, + { "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN }, + { "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN }, + }; + + uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize; + +#else + + MenuItem myMenuItems [] = {}; + + uint16_t NUM_MENU_ITEMS = 0; +#endif + +/////// // End dynamic Credentials /////////// + +#endif //dynamicParams_h diff --git a/examples/Ethernet_nRF52/Credentials.h b/examples/Ethernet_nRF52/Credentials.h index 6b14fa72..d7b1ee21 100644 --- a/examples/Ethernet_nRF52/Credentials.h +++ b/examples/Ethernet_nRF52/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_nRF52/Ethernet_nRF52.ino b/examples/Ethernet_nRF52/Ethernet_nRF52.ino index ce658244..1763b74a 100644 --- a/examples/Ethernet_nRF52/Ethernet_nRF52.ino +++ b/examples/Ethernet_nRF52/Ethernet_nRF52.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** Ethernet_nRF52.ino - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/Ethernet_nRF52/defines.h b/examples/Ethernet_nRF52/defines.h index 95679615..d71b0da8 100644 --- a/examples/Ethernet_nRF52/defines.h +++ b/examples/Ethernet_nRF52/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/Ethernet_nRF52/dynamicParams.h b/examples/Ethernet_nRF52/dynamicParams.h index ba75afdc..c1486b08 100644 --- a/examples/Ethernet_nRF52/dynamicParams.h +++ b/examples/Ethernet_nRF52/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_Generic/Credentials.h b/examples/MQTT_ThingStream_Ethernet_Generic/Credentials.h index 56fd9f8a..d25f73e3 100644 --- a/examples/MQTT_ThingStream_Ethernet_Generic/Credentials.h +++ b/examples/MQTT_ThingStream_Ethernet_Generic/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_Generic/MQTT_ThingStream_Ethernet_Generic.ino b/examples/MQTT_ThingStream_Ethernet_Generic/MQTT_ThingStream_Ethernet_Generic.ino index 9ed98fe9..ee98bc1f 100644 --- a/examples/MQTT_ThingStream_Ethernet_Generic/MQTT_ThingStream_Ethernet_Generic.ino +++ b/examples/MQTT_ThingStream_Ethernet_Generic/MQTT_ThingStream_Ethernet_Generic.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** MQTT_ThingStream_Ethernet_Generic.ino - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/MQTT_ThingStream_Ethernet_Generic/defines.h b/examples/MQTT_ThingStream_Ethernet_Generic/defines.h index d90fcb37..2539d4fe 100644 --- a/examples/MQTT_ThingStream_Ethernet_Generic/defines.h +++ b/examples/MQTT_ThingStream_Ethernet_Generic/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_Generic/dynamicParams.h b/examples/MQTT_ThingStream_Ethernet_Generic/dynamicParams.h index 38d26c81..f23150da 100644 --- a/examples/MQTT_ThingStream_Ethernet_Generic/dynamicParams.h +++ b/examples/MQTT_ThingStream_Ethernet_Generic/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_RP2040/Credentials.h b/examples/MQTT_ThingStream_Ethernet_RP2040/Credentials.h index dba89af1..6b99362d 100644 --- a/examples/MQTT_ThingStream_Ethernet_RP2040/Credentials.h +++ b/examples/MQTT_ThingStream_Ethernet_RP2040/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_RP2040/MQTT_ThingStream_Ethernet_RP2040.ino b/examples/MQTT_ThingStream_Ethernet_RP2040/MQTT_ThingStream_Ethernet_RP2040.ino index 6728b1c6..46d6927b 100644 --- a/examples/MQTT_ThingStream_Ethernet_RP2040/MQTT_ThingStream_Ethernet_RP2040.ino +++ b/examples/MQTT_ThingStream_Ethernet_RP2040/MQTT_ThingStream_Ethernet_RP2040.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** MQTT_ThingStream_Ethernet_RP2040.ino - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/MQTT_ThingStream_Ethernet_RP2040/defines.h b/examples/MQTT_ThingStream_Ethernet_RP2040/defines.h index ba9bd6c1..366ab069 100644 --- a/examples/MQTT_ThingStream_Ethernet_RP2040/defines.h +++ b/examples/MQTT_ThingStream_Ethernet_RP2040/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_RP2040/dynamicParams.h b/examples/MQTT_ThingStream_Ethernet_RP2040/dynamicParams.h index 38d26c81..f23150da 100644 --- a/examples/MQTT_ThingStream_Ethernet_RP2040/dynamicParams.h +++ b/examples/MQTT_ThingStream_Ethernet_RP2040/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_SAMD/Credentials.h b/examples/MQTT_ThingStream_Ethernet_SAMD/Credentials.h index e750adc4..2378f224 100644 --- a/examples/MQTT_ThingStream_Ethernet_SAMD/Credentials.h +++ b/examples/MQTT_ThingStream_Ethernet_SAMD/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_SAMD/MQTT_ThingStream_Ethernet_SAMD.ino b/examples/MQTT_ThingStream_Ethernet_SAMD/MQTT_ThingStream_Ethernet_SAMD.ino index 15ab78fe..4a1b4127 100644 --- a/examples/MQTT_ThingStream_Ethernet_SAMD/MQTT_ThingStream_Ethernet_SAMD.ino +++ b/examples/MQTT_ThingStream_Ethernet_SAMD/MQTT_ThingStream_Ethernet_SAMD.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** MQTT_ThingStream_Ethernet_SAMD.ino - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/MQTT_ThingStream_Ethernet_SAMD/defines.h b/examples/MQTT_ThingStream_Ethernet_SAMD/defines.h index 3225a9af..a2450e37 100644 --- a/examples/MQTT_ThingStream_Ethernet_SAMD/defines.h +++ b/examples/MQTT_ThingStream_Ethernet_SAMD/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_SAMD/dynamicParams.h b/examples/MQTT_ThingStream_Ethernet_SAMD/dynamicParams.h index 38d26c81..f23150da 100644 --- a/examples/MQTT_ThingStream_Ethernet_SAMD/dynamicParams.h +++ b/examples/MQTT_ThingStream_Ethernet_SAMD/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_SAM_DUE/Credentials.h b/examples/MQTT_ThingStream_Ethernet_SAM_DUE/Credentials.h index e750adc4..2378f224 100644 --- a/examples/MQTT_ThingStream_Ethernet_SAM_DUE/Credentials.h +++ b/examples/MQTT_ThingStream_Ethernet_SAM_DUE/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_SAM_DUE/MQTT_ThingStream_Ethernet_SAM_DUE.ino b/examples/MQTT_ThingStream_Ethernet_SAM_DUE/MQTT_ThingStream_Ethernet_SAM_DUE.ino index c93e3500..7e2f95ee 100644 --- a/examples/MQTT_ThingStream_Ethernet_SAM_DUE/MQTT_ThingStream_Ethernet_SAM_DUE.ino +++ b/examples/MQTT_ThingStream_Ethernet_SAM_DUE/MQTT_ThingStream_Ethernet_SAM_DUE.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** MQTT_ThingStream_Ethernet_SAM_DUE.ino - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/MQTT_ThingStream_Ethernet_SAM_DUE/defines.h b/examples/MQTT_ThingStream_Ethernet_SAM_DUE/defines.h index f9ddfe5e..5e5cbf1c 100644 --- a/examples/MQTT_ThingStream_Ethernet_SAM_DUE/defines.h +++ b/examples/MQTT_ThingStream_Ethernet_SAM_DUE/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_SAM_DUE/dynamicParams.h b/examples/MQTT_ThingStream_Ethernet_SAM_DUE/dynamicParams.h index 38d26c81..f23150da 100644 --- a/examples/MQTT_ThingStream_Ethernet_SAM_DUE/dynamicParams.h +++ b/examples/MQTT_ThingStream_Ethernet_SAM_DUE/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_Teensy/Credentials.h b/examples/MQTT_ThingStream_Ethernet_Teensy/Credentials.h index e750adc4..2378f224 100644 --- a/examples/MQTT_ThingStream_Ethernet_Teensy/Credentials.h +++ b/examples/MQTT_ThingStream_Ethernet_Teensy/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_Teensy/MQTT_ThingStream_Ethernet_Teensy.ino b/examples/MQTT_ThingStream_Ethernet_Teensy/MQTT_ThingStream_Ethernet_Teensy.ino index 68b58c57..91c59e9b 100644 --- a/examples/MQTT_ThingStream_Ethernet_Teensy/MQTT_ThingStream_Ethernet_Teensy.ino +++ b/examples/MQTT_ThingStream_Ethernet_Teensy/MQTT_ThingStream_Ethernet_Teensy.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** MQTT_ThingStream_Ethernet_Teensy.ino - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/MQTT_ThingStream_Ethernet_Teensy/defines.h b/examples/MQTT_ThingStream_Ethernet_Teensy/defines.h index 2d588127..d2ba9487 100644 --- a/examples/MQTT_ThingStream_Ethernet_Teensy/defines.h +++ b/examples/MQTT_ThingStream_Ethernet_Teensy/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_Teensy/dynamicParams.h b/examples/MQTT_ThingStream_Ethernet_Teensy/dynamicParams.h index 38d26c81..f23150da 100644 --- a/examples/MQTT_ThingStream_Ethernet_Teensy/dynamicParams.h +++ b/examples/MQTT_ThingStream_Ethernet_Teensy/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_WT32_ETH01/Credentials.h b/examples/MQTT_ThingStream_Ethernet_WT32_ETH01/Credentials.h new file mode 100644 index 00000000..e1202902 --- /dev/null +++ b/examples/MQTT_ThingStream_Ethernet_WT32_ETH01/Credentials.h @@ -0,0 +1,67 @@ +/**************************************************************************************************************************** + Credentials.h + For W5x00, LAN8720 and ENC28J60 Ethernet shields. + + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + AVR Mega is not supported. + + Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager + Licensed under MIT license + *****************************************************************************************************************************/ + +#ifndef Credentials_h +#define Credentials_h + +#include "defines.h" + +/// Start Default Config Data ////////////////// + +/* +typedef struct Configuration +{ + char header [16]; + char static_IP [16]; + char board_name [24]; + int checkSum; +} Ethernet_Configuration; +*/ + +#define TO_LOAD_DEFAULT_CONFIG_DATA true + +#if TO_LOAD_DEFAULT_CONFIG_DATA + +bool LOAD_DEFAULT_CONFIG_DATA = false; + +Ethernet_Configuration defaultConfig = +{ + //char header[16], dummy, not used +#if USE_SSL + "Eth_SSL", +#else + "Eth_NonSSL", +#endif + + // char static_IP [16]; + //"192.168.2.232", + // Use dynamic DHCP IP + "", + //char board_name [24]; + "WT32-ETH01", + // terminate the list + //int checkSum, dummy, not used + 0 + /////////// End Default Config Data ///////////// +}; + +#else + +bool LOAD_DEFAULT_CONFIG_DATA = false; + +Ethernet_Configuration defaultConfig; + +#endif // TO_LOAD_DEFAULT_CONFIG_DATA + +/////////// End Default Config Data ///////////// + +#endif //Credentials_h diff --git a/examples/MQTT_ThingStream_Ethernet_WT32_ETH01/MQTT_ThingStream_Ethernet_WT32_ETH01.ino b/examples/MQTT_ThingStream_Ethernet_WT32_ETH01/MQTT_ThingStream_Ethernet_WT32_ETH01.ino new file mode 100644 index 00000000..ade9ba89 --- /dev/null +++ b/examples/MQTT_ThingStream_Ethernet_WT32_ETH01/MQTT_ThingStream_Ethernet_WT32_ETH01.ino @@ -0,0 +1,363 @@ +/**************************************************************************************************************************** + MQTT_ThingStream_Ethernet_RP2040.ino + For W5x00, LAN8720 and ENC28J60 Ethernet shields. + + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + AVR Mega is not supported. + + Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager + Licensed under MIT license + + Version: 1.5.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 14/12/2020 Initial coding. + 1.1.0 K Hoang 17/12/2020 Add support to ESP32/ESP8266. Add MQTT related examples to demo dynamic parameter usage + 1.1.1 K Hoang 28/12/2020 Suppress all possible compiler warnings + 1.2.0 K Hoang 22/02/2021 Optimize code and use better FlashStorage_SAMD and FlashStorage_STM32. + Add customs HTML header feature. Fix bug. + 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO + 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards + *****************************************************************************************************************************/ + +#include "defines.h" +#include "Credentials.h" +#include "dynamicParams.h" + +///////////// Start MQTT ThingStream /////////////// +#include + +// GOT FROM ThingsStream! + +const char *MQTT_PREFIX_TOPIC = "esp32-sniffer/"; +const char *MQTT_ANNOUNCE_TOPIC = "/status"; +const char *MQTT_CONTROL_TOPIC = "/control"; +const char *MQTT_BLE_TOPIC = "/ble"; + +String topic = MQTT_PREFIX_TOPIC + String("12345678") + MQTT_BLE_TOPIC; +String subTopic = MQTT_PREFIX_TOPIC + String("12345678") + MQTT_BLE_TOPIC; + +//////////// End MQTT ThingStream /////////////// + +Ethernet_Manager ethernet_manager; + +IPAddress localEthernetIP; + + +///////////// Start MQTT ThingStream /////////////// + +void mqtt_receive_callback(char* topic, byte* payload, unsigned int length); + +unsigned long lastMsg = 0; + +// Initialize the SSL client library +WiFiClient ethClient; + +PubSubClient* client = NULL; + +/* + Called whenever a payload is received from a subscribed MQTT topic +*/ +void mqtt_receive_callback(char* topic, byte* payload, unsigned int length) +{ + Serial.print("\nMQTT Message receive ["); + Serial.print(topic); + Serial.print("] "); + + for (unsigned int i = 0; i < length; i++) + { + Serial.print((char)payload[i]); + } + + Serial.println(); +} + +void reconnect() +{ + // Loop until we're reconnected + while (!client->connected()) + { + Serial.print("Attempting MQTT connection to "); + Serial.println(MQTT_SERVER); + + Serial.print("MQTT_CLIENT_ID = "); + Serial.println(MQTT_CLIENT_ID); + Serial.print("MQTT_USER = "); + Serial.println(MQTT_USER); + Serial.print("MQTT_PASS = "); + Serial.println(MQTT_PASS); + + // Attempt to connect + int connect_status = client->connect(MQTT_CLIENT_ID, MQTT_USER, MQTT_PASS, topic.c_str(), 2, false, ""); + + if (connect_status) + { + Serial.println("...connected"); + + // Once connected, publish an announcement... + String data = "Hello from MQTTClient_SSL on " + String(BOARD_NAME); + + client->publish(topic.c_str(), data.c_str()); + + Serial.println("Published connection message successfully!"); + + Serial.print("Subcribed to: "); + Serial.println(subTopic); + + // ... and resubscribe + client->subscribe(subTopic.c_str()); + // for loopback testing + client->subscribe(topic.c_str()); + } + else + { + Serial.print("failed, rc="); + Serial.print(client->state()); + Serial.println(" try again in 5 seconds"); + + // Wait 5 seconds before retrying + delay(5000); + } + } +} + +///////////// End MQTT ThingStream /////////////// + +void heartBeatPrint() +{ + static int num = 1; + + localEthernetIP = ETH.localIP(); + + if ( ( (uint32_t) localEthernetIP != 0 ) ) + { + Serial.print(F("H")); + } + else + Serial.print(F("F")); + + if (num == 80) + { + Serial.println(); + num = 1; + } + else if (num++ % 10 == 0) + { + Serial.print(F(" ")); + } +} + +void check_status() +{ + #define STATUS_CHECK_INTERVAL 10000L + + static unsigned long checkstatus_timeout = STATUS_CHECK_INTERVAL; + + // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change. + if ((millis() > checkstatus_timeout)) + { + heartBeatPrint(); + checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL; + } +} + +#if USING_CUSTOMS_STYLE +const char NewCustomsStyle[] /*PROGMEM*/ = ""; +#endif + +void WiFiEvent(WiFiEvent_t event) +{ + switch (event) + { + case SYSTEM_EVENT_ETH_START: + ETM_LOGERROR(F("ETH Started")); + //set eth hostname here + ETH.setHostname("WT32-ETH01"); + break; + case SYSTEM_EVENT_ETH_CONNECTED: + ETM_LOGERROR(F("ETH Connected")); + break; + + case SYSTEM_EVENT_ETH_GOT_IP: + if (!ethernet_manager.ethernetConnected) + { + ETM_LOGERROR3(F("ETH MAC:"), ETH.macAddress(), F(", IPv4:"), ETH.localIP()); + + if (ETH.fullDuplex()) + { + ETM_LOGERROR1(F("FULL_DUPLEX, Link Speed (Mbps)"), ETH.linkSpeed()); + } + else + { + ETM_LOGERROR1(F("HALF_DUPLEX, Link Speed (Mbps)"), ETH.linkSpeed()); + } + + ethernet_manager.ethernetConnected = true; + } + + break; + + case SYSTEM_EVENT_ETH_DISCONNECTED: + ETM_LOGERROR(F("ETH Disconnected")); + ethernet_manager.ethernetConnected = false; + break; + + case SYSTEM_EVENT_ETH_STOP: + ETM_LOGERROR(F("\nETH Stopped")); + ethernet_manager.ethernetConnected = false; + break; + + default: + break; + } +} + +void setup() +{ + // Debug console + Serial.begin(115200); + while (!Serial); + + // Using this if Serial debugging is not necessary or not using Serial port + //while (!Serial && (millis() < 3000)); + + Serial.print("\nStart MQTT_ThingStream_Ethernet_WT32_ETH01 on "); Serial.println(BOARD_NAME); + Serial.print("Ethernet Shield type : "); Serial.println(SHIELD_TYPE); + Serial.println(WEBSERVER_WT32_ETH01_VERSION); + Serial.println(ETHERNET_MANAGER_VERSION); + Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION); + + WiFi.onEvent(WiFiEvent); + + ////////////////////////////////////////////// + +#if USING_CUSTOMS_STYLE + ethernet_manager.setCustomsStyle(NewCustomsStyle); +#endif + +#if USING_CUSTOMS_HEAD_ELEMENT + ethernet_manager.setCustomsHeadElement(""); +#endif + +#if USING_CORS_FEATURE + ethernet_manager.setCORSHeader("Your Access-Control-Allow-Origin"); +#endif + + ethernet_manager.begin(); + + ////////////////////////////////////////////// + + localEthernetIP = ETH.localIP(); + + if ( (uint32_t) localEthernetIP != 0 ) + { + Serial.print(F("Connected! IP address: ")); + Serial.println(localEthernetIP); + } + else + { + Serial.println(F("Ethernet not Connected! Please check.")); + } + + Serial.println("***************************************"); + Serial.println(topic); + Serial.println("***************************************"); +} + +#if (USE_DYNAMIC_PARAMETERS) +void displayCredentials() +{ + Serial.println("\nYour stored Credentials :"); + + for (int i = 0; i < NUM_MENU_ITEMS; i++) + { + Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata); + } +} + +void displayCredentialsOnce() +{ + static bool displayedCredentials = false; + + if (!displayedCredentials) + { + for (int i = 0; i < NUM_MENU_ITEMS; i++) + { + if (!strlen(myMenuItems[i].pdata)) + { + break; + } + + if ( i == (NUM_MENU_ITEMS - 1) ) + { + displayedCredentials = true; + displayCredentials(); + } + } + } +} +#endif + +#define MQTT_PUBLISH_INTERVAL_MS 20000L + +String data = "Hello from MQTT_ThingStream on " + String(BOARD_NAME) + " with " + String(SHIELD_TYPE); +const char *pubData = data.c_str(); + +void loop() +{ + static bool inConfigMode = true; + static unsigned long currentMillis; + + inConfigMode = ethernet_manager.run(); + + if (!inConfigMode) + { + if (!client) + { + Serial.print("Connecting to MQTT_SERVER = "); + Serial.print(MQTT_SERVER); + Serial.print(", MQTT_PORT= "); + Serial.println(atoi(MQTT_PORT)); + + client = new PubSubClient(MQTT_SERVER, atoi(MQTT_PORT), mqtt_receive_callback, ethClient); + + // Note - the default maximum packet size is 256 bytes. If the + // combined length of clientId, username and password exceed this use the + // following to increase the buffer size: + //client->setBufferSize(256); + } + + if (!client->connected()) + { + reconnect(); + } + + // Sending Data + currentMillis = millis(); + + if (currentMillis - lastMsg > MQTT_PUBLISH_INTERVAL_MS) + { + lastMsg = currentMillis; + + if (!client->publish(topic.c_str(), pubData)) + { + Serial.println("Message failed to send."); + } + + Serial.print("\nMQTT Message Send : " + topic + " => "); + Serial.println(data); + } + + client->loop(); + + check_status(); + + #if (USE_DYNAMIC_PARAMETERS) + displayCredentialsOnce(); + #endif + } +} diff --git a/examples/MQTT_ThingStream_Ethernet_WT32_ETH01/defines.h b/examples/MQTT_ThingStream_Ethernet_WT32_ETH01/defines.h new file mode 100644 index 00000000..a12b08e3 --- /dev/null +++ b/examples/MQTT_ThingStream_Ethernet_WT32_ETH01/defines.h @@ -0,0 +1,71 @@ +/**************************************************************************************************************************** + defines.h + For W5x00, LAN8720 and ENC28J60 Ethernet shields. + + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + AVR Mega is not supported. + + Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager + Licensed under MIT license + *****************************************************************************************************************************/ + + +#ifndef defines_h +#define defines_h + +#if ESP32 + #if defined(ETHERNET_USE_WT32_ETH01) + #undef ETHERNET_USE_WT32_ETH01 + #endif + #define ETHERNET_USE_WT32_ETH01 true + #define USE_DYNAMIC_PARAMETERS true + + #warning Use ESP32 architecture for WT32_ETH01 +#else + #error This code is designed to run on WT32_ETH01 and ESP32 platform! Please check your Tools->Board setting. +#endif + +/* Comment this out to disable prints and save space */ +#define DEBUG_ETHERNET_WEBSERVER_PORT Serial + +// Debug Level from 0 to 4 +#define _ETHERNET_WEBSERVER_LOGLEVEL_ 2 +#define _ETHERNET_MANAGER_LOGLEVEL_ 4 + +///////////////////////////////////////////// + +#define DOUBLERESETDETECTOR_DEBUG true + +#define USE_LITTLEFS true +#define USE_SPIFFS false + +///////////////////////////////////////////// + +// Add customs headers from v1.2.0 +#define USING_CUSTOMS_STYLE true +#define USING_CUSTOMS_HEAD_ELEMENT true +#define USING_CORS_FEATURE true + +///////////////////////////////////////////// + +// Config Timeout 120s (default 60s) +#define CONFIG_TIMEOUT 120000L + +#define USE_DYNAMIC_PARAMETERS true + +////////////////////////////////////////// + + +#include + +#ifndef SHIELD_TYPE +#define SHIELD_TYPE "WT32_ETH01" +#endif + +#define W5100_CS 10 +#define SDCARD_CS 4 + +#define ETHERNET_HOST_NAME "WT32_ETH01" + +#endif //defines_h diff --git a/examples/MQTT_ThingStream_Ethernet_WT32_ETH01/dynamicParams.h b/examples/MQTT_ThingStream_Ethernet_WT32_ETH01/dynamicParams.h new file mode 100644 index 00000000..f23150da --- /dev/null +++ b/examples/MQTT_ThingStream_Ethernet_WT32_ETH01/dynamicParams.h @@ -0,0 +1,72 @@ +/**************************************************************************************************************************** + dynamicParams.h + For W5x00, LAN8720 and ENC28J60 Ethernet shields. + + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + AVR Mega is not supported. + + Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager + Licensed under MIT license + *****************************************************************************************************************************/ + +#ifndef dynamicParams_h +#define dynamicParams_h + +#include "defines.h" + +// USE_DYNAMIC_PARAMETERS defined in defined.h + +/////////////// Start dynamic Credentials /////////////// + +/************************************** + #define MAX_ID_LEN 5 + #define MAX_DISPLAY_NAME_LEN 16 + + typedef struct + { + char id [MAX_ID_LEN + 1]; + char displayName [MAX_DISPLAY_NAME_LEN + 1]; + char *pdata; + uint8_t maxlen; + } MenuItem; +**************************************/ + +#if USE_DYNAMIC_PARAMETERS + + #define MAX_MQTT_SERVER_LEN 48 + char MQTT_SERVER [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server"; + + #define MAX_MQTT_PORT_LEN 6 + char MQTT_PORT [MAX_MQTT_PORT_LEN + 1] = "1883"; + + #define MAX_MQTT_USERNAME_LEN 34 + char MQTT_USER [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username"; + + #define MAX_MQTT_PW_LEN 48 + char MQTT_PASS [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password"; + + #define MAX_MQTT_CLIENT_ID 48 + char MQTT_CLIENT_ID [MAX_MQTT_CLIENT_ID + 1] = "default-mqtt-clientID"; + + MenuItem myMenuItems [] = + { + { "mqtt", "MQTT Server", MQTT_SERVER, MAX_MQTT_SERVER_LEN }, + { "mqpt", "Port", MQTT_PORT, MAX_MQTT_PORT_LEN }, + { "user", "MQTT UserName", MQTT_USER, MAX_MQTT_USERNAME_LEN }, + { "mqpw", "MQTT PWD", MQTT_PASS, MAX_MQTT_PW_LEN }, + { "clid", "Client ID", MQTT_CLIENT_ID, MAX_MQTT_CLIENT_ID }, + }; + + uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize; + +#else + + MenuItem myMenuItems [] = {}; + + uint16_t NUM_MENU_ITEMS = 0; +#endif + +/////// // End dynamic Credentials /////////// + +#endif //dynamicParams_h diff --git a/examples/MQTT_ThingStream_Ethernet_nRF52/Credentials.h b/examples/MQTT_ThingStream_Ethernet_nRF52/Credentials.h index e750adc4..2378f224 100644 --- a/examples/MQTT_ThingStream_Ethernet_nRF52/Credentials.h +++ b/examples/MQTT_ThingStream_Ethernet_nRF52/Credentials.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** Credentials.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_nRF52/MQTT_ThingStream_Ethernet_nRF52.ino b/examples/MQTT_ThingStream_Ethernet_nRF52/MQTT_ThingStream_Ethernet_nRF52.ino index a5be652e..dcc1a14a 100644 --- a/examples/MQTT_ThingStream_Ethernet_nRF52/MQTT_ThingStream_Ethernet_nRF52.ino +++ b/examples/MQTT_ThingStream_Ethernet_nRF52/MQTT_ThingStream_Ethernet_nRF52.ino @@ -1,15 +1,15 @@ /**************************************************************************************************************************** MQTT_ThingStream_Ethernet_nRF52.ino - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -20,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #include "defines.h" diff --git a/examples/MQTT_ThingStream_Ethernet_nRF52/defines.h b/examples/MQTT_ThingStream_Ethernet_nRF52/defines.h index dfb77208..ab36963c 100644 --- a/examples/MQTT_ThingStream_Ethernet_nRF52/defines.h +++ b/examples/MQTT_ThingStream_Ethernet_nRF52/defines.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** defines.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/examples/MQTT_ThingStream_Ethernet_nRF52/dynamicParams.h b/examples/MQTT_ThingStream_Ethernet_nRF52/dynamicParams.h index 38d26c81..f23150da 100644 --- a/examples/MQTT_ThingStream_Ethernet_nRF52/dynamicParams.h +++ b/examples/MQTT_ThingStream_Ethernet_nRF52/dynamicParams.h @@ -1,8 +1,8 @@ /**************************************************************************************************************************** dynamicParams.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. diff --git a/library.json b/library.json index 53ca2de3..3965b76f 100644 --- a/library.json +++ b/library.json @@ -1,8 +1,8 @@ { "name": "Ethernet_Manager", - "version": "1.4.0", + "version": "1.5.0", "description": "Simple Ethernet Manager for Teensy, SAM DUE, SAMD, nRF52, ESP32 (including ESP32-S2/C3), ESP8266, RP2040-based Nano_RP2040_Connect, RASPBERRY_PI_PICO, etc. boards. Config data saved in ESP LittleFS, SPIFFS or EEPROM, nRF52 LittleFS, EEPROM, DueFlashStorage or SAMD FlashStorage. For configuring/auto(re)connecting Ethernet W5x00, ENC28J60 and NativeEthernet at runtime. Use much less memory compared to full-fledge WiFiManager. Config Portal (CP) will be auto-adjusted to match the number of dynamic custom parameters. Optional default Credentials to be autoloaded into CP to use or change instead of manually input. Credentials are saved in LittleFS, (emulated-)EEPROM, FlashStorage_SAMD or DueFlashStorage. New powerful-yet-simple-to-use feature to enable adding dynamic parameters from sketch and input using the same CP. DoubleDetectDetector as well as Virtual Switches feature permits entering CP as requested. Configurable HTML Headers, including Customs Style, Head Elements, CORS Header", - "keywords": "communication, ethernet, esp8266, esp32, esp32-s2, esp32-c3, rpi-pico, rp2040, nano-rp2040-connect, W5x00, ENC28J60, Teensy, SAM DUE, SAMD, STM32, nRF52, Credentials, config-portal, Double-Reset, MQTT, SAMD51, DynamicParameters, dynamic-params, customs-header, Manager", + "keywords": "communication, ethernet, esp8266, esp32, esp32-s2, esp32-c3, rpi-pico, rp2040, nano-rp2040-connect, W5x00, ENC28J60, lan8720, SAM DUE, SAMD, STM32, nRF52, Credentials, config-portal, WT32-ETH01, Double-Reset, MQTT, SAMD51, DynamicParameters, dynamic-params, customs-header, Manager", "authors": { "name": "Khoi Hoang", @@ -39,7 +39,7 @@ { "owner": "khoih.prog", "name": "DoubleResetDetector_Generic", - "version": ">=1.3.0", + "version": ">=1.4.0", "platforms": ["*"] }, { @@ -54,6 +54,12 @@ "version": "^1.1.0", "platforms": ["*"] }, + { + "owner": "khoih.prog", + "name": "WebServer_WT32_ETH01", + "version": "^1.1.0", + "platforms": ["espressif32"] + }, { "owner": "sebnil", "name": "DueFlashStorage", diff --git a/library.properties b/library.properties index 83ff218d..7f852ede 100644 --- a/library.properties +++ b/library.properties @@ -1,12 +1,12 @@ name=Ethernet_Manager -version=1.4.0 +version=1.5.0 author=Khoi Hoang license=MIT maintainer=Khoi Hoang -sentence=Simple Ethernet Manager for Teensy, SAM DUE, SAMD21, SAMD51, nRF52, ESP32 (including ESP32-S2, ESP32-C3), ESP8266, RP2040-based Nano_RP2040_Connect, RASPBERRY_PI_PICO, etc. boards, with or without SSL, configuration data saved in ESP8266/ESP32 LittleFS, SPIFFS or EEPROM, nRF52/RP2040 LittleFS/InternalFS, EEPROM, DueFlashStorage or FlashStorage_SAMD. +sentence=Simple Ethernet Manager for Teensy, SAM DUE, SAMD21, SAMD51, nRF52, ESP32 (including ESP32-S2, ESP32-C3, WT32-ETH01), ESP8266, RP2040-based Nano_RP2040_Connect, RASPBERRY_PI_PICO, etc. boards, with or without SSL, configuration data saved in ESP8266/ESP32 LittleFS, SPIFFS or EEPROM, nRF52/RP2040 LittleFS/InternalFS, EEPROM, DueFlashStorage or FlashStorage_SAMD. paragraph=Library for configuring/auto(re)connecting Ethernet W5100/W5200/W5500, ENC28J60 and Teensy 4.1 NativeEthernet at runtime. Use much less memory compared to full-fledge WiFiManager. Config Portal will be auto-adjusted to match the number of dynamic custom parameters. Optional default Credentials to be autoloaded into Config Portal to use or change instead of manually input. Credentials are saved in LittleFS/InternalFS, (emulated-)EEPROM, FlashStorage_SAMD or DueFlashStorage. New powerful-yet-simple-to-use feature to enable adding dynamic custom parameters from sketch and input using the same Config Portal. DoubleDetectDetector as well as Virtual Switches feature permits entering Config Portal as requested. Configurable Customs HTML Headers, including Customs Style, Customs Head Elements, CORS Header. category=Communication url=https://github.com/khoih-prog/Ethernet_Manager architectures=* -depends=EthernetWebServer,DoubleResetDetector_Generic,ESP_DoubleResetDetector,Functional-Vlpp,FlashStorage_SAMD +depends=EthernetWebServer,DoubleResetDetector_Generic,ESP_DoubleResetDetector,Functional-Vlpp,FlashStorage_SAMD,WebServer_WT32_ETH01 includes=Ethernet_Manager.h diff --git a/platformio/platformio.ini b/platformio/platformio.ini index 12f44f7c..05916480 100644 --- a/platformio/platformio.ini +++ b/platformio/platformio.ini @@ -33,15 +33,17 @@ lib_deps = ; PlatformIO 4.x EthernetWebServer@>=1.5.0 ESP_DoubleResetDetector@>=1.1.1 - DoubleResetDetector_Generic@>=1.3.0 + DoubleResetDetector_Generic@>=1.4.0 Functional-Vlpp@>=1.0.2 FlashStorage_SAMD@>=1.1.0 + WebServer_WT32_ETH01@>=1.1.0 ; PlatformIO 5.x ; khoih-prog/EthernetWebServer@>=1.5.0 ; khoih.prog/ESP_DoubleResetDetector@>=1.1.1 -; khoih.prog/DoubleResetDetector_Generic@>=1.3.0 +; khoih.prog/DoubleResetDetector_Generic@>=1.4.0 ; khoih-prog/Functional-Vlpp@>=1.0.2 ; khoih.prog/FlashStorage_SAMD@>=1.1.0 +; khoih.prog/WebServer_WT32_ETH01@>=1.1.0 build_flags = ; set your debug output (default=Serial) diff --git a/src/Adapters/Ethernet_DUE_Manager.h b/src/Adapters/Ethernet_DUE_Manager.h index 24f0eb02..ce0418fc 100644 --- a/src/Adapters/Ethernet_DUE_Manager.h +++ b/src/Adapters/Ethernet_DUE_Manager.h @@ -1,14 +1,15 @@ /**************************************************************************************************************************** Ethernet_DUE_Manager.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #pragma once diff --git a/src/Adapters/Ethernet_ESP32_Manager.h b/src/Adapters/Ethernet_ESP32_Manager.h index 529970cf..6459b9d9 100644 --- a/src/Adapters/Ethernet_ESP32_Manager.h +++ b/src/Adapters/Ethernet_ESP32_Manager.h @@ -1,14 +1,15 @@ /**************************************************************************************************************************** Ethernet_ESP32_Manager.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #pragma once diff --git a/src/Adapters/Ethernet_ESP8266_Manager.h b/src/Adapters/Ethernet_ESP8266_Manager.h index 26cdc3bf..9433ea49 100644 --- a/src/Adapters/Ethernet_ESP8266_Manager.h +++ b/src/Adapters/Ethernet_ESP8266_Manager.h @@ -1,14 +1,15 @@ /**************************************************************************************************************************** Ethernet_ESP8266_Manager.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #pragma once diff --git a/src/Adapters/Ethernet_MBED_RP2040_Manager.h b/src/Adapters/Ethernet_MBED_RP2040_Manager.h index 2b659cb7..362774a9 100644 --- a/src/Adapters/Ethernet_MBED_RP2040_Manager.h +++ b/src/Adapters/Ethernet_MBED_RP2040_Manager.h @@ -1,14 +1,15 @@ /**************************************************************************************************************************** Ethernet_MBED_RP2040_Manager.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE, SAMD and RP2040 boards, with Ethernet W5x00 or - ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #pragma once diff --git a/src/Adapters/Ethernet_NRF52_Manager.h b/src/Adapters/Ethernet_NRF52_Manager.h index 4b9c8bdd..5f38e6e9 100644 --- a/src/Adapters/Ethernet_NRF52_Manager.h +++ b/src/Adapters/Ethernet_NRF52_Manager.h @@ -1,14 +1,15 @@ /**************************************************************************************************************************** Ethernet_NRF52_Manager.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #pragma once diff --git a/src/Adapters/Ethernet_RP2040_Manager.h b/src/Adapters/Ethernet_RP2040_Manager.h index a093fe05..45391458 100644 --- a/src/Adapters/Ethernet_RP2040_Manager.h +++ b/src/Adapters/Ethernet_RP2040_Manager.h @@ -1,14 +1,15 @@ /**************************************************************************************************************************** Ethernet_RP2040_Manager.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE, SAMD and RP2040 boards, with Ethernet W5x00 or - ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #pragma once diff --git a/src/Adapters/Ethernet_SAMD_Manager.h b/src/Adapters/Ethernet_SAMD_Manager.h index c4c22dab..3f533312 100644 --- a/src/Adapters/Ethernet_SAMD_Manager.h +++ b/src/Adapters/Ethernet_SAMD_Manager.h @@ -1,14 +1,15 @@ /**************************************************************************************************************************** Ethernet_SAMD_Manager.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #pragma once diff --git a/src/Adapters/Ethernet_Teensy_Manager.h b/src/Adapters/Ethernet_Teensy_Manager.h index f99eec4c..58dc02b4 100644 --- a/src/Adapters/Ethernet_Teensy_Manager.h +++ b/src/Adapters/Ethernet_Teensy_Manager.h @@ -1,14 +1,15 @@ /**************************************************************************************************************************** Ethernet_Teensy_Manager.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #pragma once diff --git a/src/Adapters/Ethernet_WT32_ETH01_Manager.h b/src/Adapters/Ethernet_WT32_ETH01_Manager.h new file mode 100644 index 00000000..23f925de --- /dev/null +++ b/src/Adapters/Ethernet_WT32_ETH01_Manager.h @@ -0,0 +1,1959 @@ +/**************************************************************************************************************************** + Ethernet_WT32_ETH01_Manager.h + For W5x00, LAN8720 and ENC28J60 Ethernet shields. + + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, + to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. + AVR Mega is not supported. + + Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager + Licensed under MIT license + + Version: 1.5.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 14/12/2020 Initial coding. + 1.1.0 K Hoang 17/12/2020 Add support to ESP32/ESP8266. Add MQTT related examples to demo dynamic parameter usage + 1.1.1 K Hoang 28/12/2020 Suppress all possible compiler warnings + 1.2.0 K Hoang 22/02/2021 Optimize code and use better FlashStorage_SAMD and FlashStorage_STM32. + Add customs HTML header feature. Fix bug. + 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO + 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards +*****************************************************************************************************************************/ + +#pragma once + +#ifndef Ethernet_WT32_ETH01_Manager_h +#define Ethernet_WT32_ETH01_Manager_h + +#if defined(ESP32) + #if defined(ETHERNET_USE_WT32_ETH01) + #undef ETHERNET_USE_WT32_ETH01 + #endif + #warning ETHERNET_USE_WT32_ETH01 from Ethernet_WT32_ETH01_Manager.h + #define ETHERNET_USE_WT32_ETH01 true +#else + #error This code is designed to run on WT32_ETH01 and ESP32 platform! Please check your Tools->Board setting. +#endif + +// Increase HTTP_UPLOAD_BUFLEN to 4K, instead of default 2K in +#ifndef HTTP_UPLOAD_BUFLEN + #define HTTP_UPLOAD_BUFLEN 4096 +#endif + +#if USE_LITTLEFS + // Use LittleFS + #include "FS.h" + + // The library will be depreciated after being merged to future major Arduino esp32 core release 2.x + // At that time, just remove this library inclusion + #include // https://github.com/lorol/LITTLEFS + + FS* filesystem = &LITTLEFS; + #define FileFS LITTLEFS +#elif USE_SPIFFS + #include "FS.h" + #include + FS* filesystem = &SPIFFS; + #define FileFS SPIFFS +#else + #include +#endif + +////////////////////////////////////////// + +#ifndef USING_CUSTOMS_STYLE + #define USING_CUSTOMS_STYLE false +#endif + +#ifndef USING_CUSTOMS_HEAD_ELEMENT + #define USING_CUSTOMS_HEAD_ELEMENT false +#endif + +#ifndef USING_CORS_FEATURE + #define USING_CORS_FEATURE false +#endif + +///////// NEW for DRD ///////////// +// These defines must be put before #include +// to select where to store DoubleResetDetector's variable. +// For ESP32, You must select one to be true (EEPROM or SPIFFS) +// For ESP8266, You must select one to be true (RTC, EEPROM or SPIFFS) +// Otherwise, library will use default EEPROM storage + +#if USE_LITTLEFS + #define ESP_DRD_USE_LITTLEFS true + #define ESP_DRD_USE_SPIFFS false + #define ESP_DRD_USE_EEPROM false +#elif USE_SPIFFS + #define ESP_DRD_USE_LITTLEFS false + #define ESP_DRD_USE_SPIFFS true + #define ESP_DRD_USE_EEPROM false +#else + #define ESP_DRD_USE_LITTLEFS false + #define ESP_DRD_USE_SPIFFS false + #define ESP_DRD_USE_EEPROM true +#endif + +#ifndef DOUBLERESETDETECTOR_DEBUG + #define DOUBLERESETDETECTOR_DEBUG false +#endif + +#include //https://github.com/khoih-prog/ESP_DoubleResetDetector + +// Number of seconds after reset during which a +// subseqent reset will be considered a double reset. +#define DRD_TIMEOUT 10 + +// RTC Memory Address for the DoubleResetDetector to use +#define DRD_ADDRESS 0 + +//DoubleResetDetector drd(DRD_TIMEOUT, DRD_ADDRESS); +DoubleResetDetector* drd; + +///////// NEW for DRD ///////////// + +#include +#define ESP_getChipId() ((uint32_t)ESP.getEfuseMac()) + + +//NEW +#define MAX_ID_LEN 5 +#define MAX_DISPLAY_NAME_LEN 16 + +typedef struct +{ + char id [MAX_ID_LEN + 1]; + char displayName [MAX_DISPLAY_NAME_LEN + 1]; + char *pdata; + uint8_t maxlen; +} MenuItem; +// + +#if USE_DYNAMIC_PARAMETERS + #warning Using Dynamic Parameters + ///NEW + extern uint16_t NUM_MENU_ITEMS; + extern MenuItem myMenuItems []; + bool *menuItemUpdated = NULL; +#else + #warning Not using Dynamic Parameters +#endif + +// Configurable items besides fixed Header +#define NUM_CONFIGURABLE_ITEMS ( 2 ) + +#define HEADER_MAX_LEN 16 +#define STATIC_IP_MAX_LEN 16 +#define BOARD_NAME_MAX_LEN 24 + +typedef struct Configuration +{ + char header [HEADER_MAX_LEN]; + char static_IP [STATIC_IP_MAX_LEN]; + char board_name [BOARD_NAME_MAX_LEN]; + int checkSum; +} Ethernet_Configuration; + +// Currently CONFIG_DATA_SIZE = ( 60 ) +uint16_t CONFIG_DATA_SIZE = sizeof(Ethernet_Configuration); + +extern bool LOAD_DEFAULT_CONFIG_DATA; +extern Ethernet_Configuration defaultConfig; + +// -- HTML page fragments + +const char ETM_HTML_HEAD_START[] /*PROGMEM*/ = "WT32_ETH01_Manager"; + +const char ETM_HTML_HEAD_STYLE[] /*PROGMEM*/ = ""; + +const char ETM_HTML_HEAD_END[] /*PROGMEM*/ = "
\ +
\ +
"; + +const char ETM_FLDSET_START[] /*PROGMEM*/ = "
"; +const char ETM_FLDSET_END[] /*PROGMEM*/ = "
"; +const char ETM_HTML_PARAM[] /*PROGMEM*/ = "
"; +const char ETM_HTML_BUTTON[] /*PROGMEM*/ = "
"; +const char ETM_HTML_SCRIPT[] /*PROGMEM*/ = ""; +const char ETM_HTML_END[] /*PROGMEM*/ = ""; + +////////////////////////////////////////// + +//KH Add repeatedly used const +//KH, from v1.1.0 +const char WM_HTTP_HEAD_CL[] PROGMEM = "Content-Length"; +const char WM_HTTP_HEAD_TEXT_HTML[] PROGMEM = "text/html"; +const char WM_HTTP_HEAD_TEXT_PLAIN[] PROGMEM = "text/plain"; + +const char WM_HTTP_CACHE_CONTROL[] PROGMEM = "Cache-Control"; +const char WM_HTTP_NO_STORE[] PROGMEM = "no-cache, no-store, must-revalidate"; +const char WM_HTTP_PRAGMA[] PROGMEM = "Pragma"; +const char WM_HTTP_NO_CACHE[] PROGMEM = "no-cache"; +const char WM_HTTP_EXPIRES[] PROGMEM = "Expires"; + +const char WM_HTTP_CORS[] PROGMEM = "Access-Control-Allow-Origin"; +const char WM_HTTP_CORS_ALLOW_ALL[] PROGMEM = "*"; + +////////////////////////////////////////// + +class Ethernet_Manager +{ + + public: + + void begin(bool initialConfig = false) + { + //// New DRD //// + drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS); + bool noConfigPortal = true; + + if (drd->detectDoubleReset()) + { + ETM_LOGWARN(F("=====================")); + ETM_LOGWARN(F("DRD. Run ConfigPortal")); + ETM_LOGWARN(F("=====================")); + noConfigPortal = false; + } + + //// New DRD //// + + if (LOAD_DEFAULT_CONFIG_DATA) + { + ETM_LOGERROR(F("======= Start Default Config Data =======")); + displayConfigData(defaultConfig); + } + + hadConfigData = getConfigData(); + + connectEthernet(); + + isForcedConfigPortal = isForcedCP(); + + //// New DRD //// + // noConfigPortal when getConfigData() OK and no MRD/DRD'ed + if (hadConfigData && noConfigPortal && (!isForcedConfigPortal) ) + //// New DRD //// + { + hadConfigData = true; + + if (ethernetConnected) + { + ETM_LOGWARN(F("begin:Ethernet Connected.")); + + if (initialConfig) + { + ETM_LOGWARN(F("begin: Start ConfigPortal")); + // Start configuration mode + startConfigurationMode(); + } + } + } + else + { + ETM_LOGERROR(isForcedConfigPortal? F("bg: isForcedConfigPortal = true") : F("bg: isForcedConfigPortal = false")); + + // If not persistent => clear the flag so that after reset. no more CP, even CP not entered and saved + if (persForcedConfigPortal) + { + ETM_LOGERROR1(F("bg:Stay forever in CP:"), isForcedConfigPortal ? F("Forced-Persistent") : (noConfigPortal ? F("No ConfigDat") : F("DRD/MRD"))); + } + else + { + ETM_LOGERROR1(F("bg:Stay forever in CP:"), isForcedConfigPortal ? F("Forced-non-Persistent") : (noConfigPortal ? F("No ConfigDat") : F("DRD/MRD"))); + clearForcedCP(); + } + + //To permit autoreset after timeout if DRD/MRD or non-persistent forced-CP + hadConfigData = isForcedConfigPortal ? true : (noConfigPortal ? false : true); + + // failed to connect to WiFi, will start configuration mode + startConfigurationMode(); + } + } + + ////////////////////////////////////////// + + // Return true if still in CP mode + bool run() + { + //// New DRD //// + // Call the double reset detector loop method every so often, + // so that it can recognise when the timeout expires. + // You can also call drd.stop() when you wish to no longer + // consider the next reset as a double reset. + drd->loop(); + //// New DRD //// + + // Be sure to reconnect Ethernet first + if (!ethernetConnected) + { + ETM_LOGWARN(F("run: connectEthernet")); + connectEthernet(); + } + + // Connection OK. Run CP if requested. + if (ethernetConnected) + { + // If configTimeout but user hasn't connected to configWeb => try to reconnect Blynk. + // But if user has connected to configWeb, stay there until done, then reset hardware + if ( configuration_mode && ( configTimeout == 0 || millis() < configTimeout ) ) + { + retryTimes = 0; + + if (server) + { + server->handleClient(); + } + } + else + { +#if RESET_IF_CONFIG_TIMEOUT + // If we're here but still in configuration_mode, permit running TIMES_BEFORE_RESET times before reset hardware + // to permit user another chance to config. + if ( configuration_mode && (configTimeout != 0) ) + { + if (++retryTimes <= CONFIG_TIMEOUT_RETRYTIMES_BEFORE_RESET) + { + ETM_LOGWARN1(F("run:TimeOut.Tried #"), retryTimes); + } + else + { + resetFunc(); + } + } +#endif + } + } + else if (configuration_mode) + { + configuration_mode = false; + ETM_LOGWARN(F("run:Ethernet not OK")); + } + + return configuration_mode; + } + + ////////////////////////////////////////// + + String getBoardName() + { + return (String(Ethernet_Manager_config.board_name)); + } + + ////////////////////////////////////////// + + Ethernet_Configuration* getFullConfigData(Ethernet_Configuration *configData) + { + if (!hadConfigData) + getConfigData(); + + // Check if NULL pointer + if (configData) + memcpy(configData, &Ethernet_Manager_config, sizeof(Ethernet_Manager_config)); + + return (configData); + } + + ////////////////////////////////////////// + + void clearConfigData() + { + memset(&Ethernet_Manager_config, 0, sizeof(Ethernet_Manager_config)); + +#if USE_DYNAMIC_PARAMETERS + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + // Actual size of pdata is [maxlen + 1] + memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); + } +#endif + + saveConfigData(); + } + + ////////////////////////////////////////////// + + bool isConfigDataValid() + { + return hadConfigData; + } + + ////////////////////////////////////////////// + + // Forced CP => Flag = 0xBEEFBEEF. Else => No forced CP + // Flag to be stored at (EEPROM_START + DRD_FLAG_DATA_SIZE + CONFIG_DATA_SIZE) + // to avoid corruption to current data + //#define FORCED_CONFIG_PORTAL_FLAG_DATA ( (uint32_t) 0xDEADBEEF) + //#define FORCED_PERS_CONFIG_PORTAL_FLAG_DATA ( (uint32_t) 0xBEEFDEAD) + + const uint32_t FORCED_CONFIG_PORTAL_FLAG_DATA = 0xDEADBEEF; + const uint32_t FORCED_PERS_CONFIG_PORTAL_FLAG_DATA = 0xBEEFDEAD; + + #define FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE 4 + + void resetAndEnterConfigPortal() + { + persForcedConfigPortal = false; + + setForcedCP(false); + + // Delay then reset the ESP8266 after save data + delay(1000); + resetFunc(); + } + + ////////////////////////////////////////////// + + // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag. + void resetAndEnterConfigPortalPersistent() + { + persForcedConfigPortal = true; + + setForcedCP(true); + + // Delay then reset the ESP8266 after save data + delay(1000); + resetFunc(); + } + + ////////////////////////////////////////////// + + void resetFunc() + { + delay(1000); + ESP.restart(); + } + + ////////////////////////////////////// + + // Add customs headers from v1.1.0 + + // New from v1.1.0, for configure CORS Header, default to WM_HTTP_CORS_ALLOW_ALL = "*" + +#if USING_CUSTOMS_STYLE + //sets a custom style, such as color + // ""; + void setCustomsStyle(const char* CustomsStyle = ETM_HTML_HEAD_STYLE) + { + ETM_HTML_HEAD_CUSTOMS_STYLE = CustomsStyle; + ETM_LOGDEBUG1(F("Set CustomsStyle to : "), ETM_HTML_HEAD_CUSTOMS_STYLE); + } + + const char* getCustomsStyle() + { + ETM_LOGDEBUG1(F("Get CustomsStyle = "), ETM_HTML_HEAD_CUSTOMS_STYLE); + return ETM_HTML_HEAD_CUSTOMS_STYLE; + } +#endif + +#if USING_CUSTOMS_HEAD_ELEMENT + //sets a custom element to add to head, like a new style tag + void setCustomsHeadElement(const char* CustomsHeadElement = NULL) + { + _CustomsHeadElement = CustomsHeadElement; + ETM_LOGDEBUG1(F("Set CustomsHeadElement to : "), _CustomsHeadElement); + } + + const char* getCustomsHeadElement() + { + ETM_LOGDEBUG1(F("Get CustomsHeadElement = "), _CustomsHeadElement); + return _CustomsHeadElement; + } +#endif + +#if USING_CORS_FEATURE + void setCORSHeader(const char* CORSHeaders = NULL) + { + _CORS_Header = CORSHeaders; + + ETM_LOGDEBUG1(F("Set CORS Header to : "), _CORS_Header); + } + + const char* getCORSHeader() + { + ETM_LOGDEBUG1(F("Get CORS Header = "), _CORS_Header); + return _CORS_Header; + } +#endif + + ////////////////////////////////////// + + public: + + bool ethernetConnected = false; + + private: + + // Initialize the Ethernet server library + // with the IP address and port you want to use + // (port 80 is default for HTTP): + //EthernetWebServer *server; + WebServer *server; + + //bool ethernetConnected = false; + //static bool ethernetConnected = false; + //static bool ethernetConnected; + + int retryTimes = 0; + + bool configuration_mode = false; + + unsigned long configTimeout; + bool hadConfigData = false; + + bool isForcedConfigPortal = false; + bool persForcedConfigPortal = false; + + Ethernet_Configuration Ethernet_Manager_config; + + uint16_t totalDataSize = 0; + + uint8_t currentBlynkServerIndex = 255; + +///////////////////////////////////// + + // Add customs headers from v1.1.0 + +#if USING_CUSTOMS_STYLE + const char* ETM_HTML_HEAD_CUSTOMS_STYLE = NULL; +#endif + +#if USING_CUSTOMS_HEAD_ELEMENT + const char* _CustomsHeadElement = NULL; +#endif + +#if USING_CORS_FEATURE + const char* _CORS_Header = WM_HTTP_CORS_ALLOW_ALL; //"*"; +#endif + + ////////////////////////////////////// + +#define RFC952_HOSTNAME_MAXLEN 24 + + char RFC952_hostname[RFC952_HOSTNAME_MAXLEN + 1]; + + void setRFC952_hostname(const char* iHostname = "") + { + if (iHostname[0] == 0) + { + String _hostname = "WT32-ETH01-XXXXXX"; // + String(macAddress, HEX); + _hostname.toUpperCase(); + + getRFC952_hostname(_hostname.c_str()); + + } + else + { + // Prepare and store the hostname only not NULL + getRFC952_hostname(iHostname); + } + + ETM_LOGWARN1(F("Hostname="), RFC952_hostname); + } + + ////////////////////////////////////// + + char* getRFC952_hostname(const char* iHostname) + { + memset(RFC952_hostname, 0, sizeof(RFC952_hostname)); + + size_t len = ( RFC952_HOSTNAME_MAXLEN < strlen(iHostname) ) ? RFC952_HOSTNAME_MAXLEN : strlen(iHostname); + + size_t j = 0; + + for (size_t i = 0; i < len - 1; i++) + { + if ( isalnum(iHostname[i]) || iHostname[i] == '-' ) + { + RFC952_hostname[j] = iHostname[i]; + j++; + } + } + + // no '-' as last char + if ( isalnum(iHostname[len - 1]) || (iHostname[len - 1] != '-') ) + RFC952_hostname[j] = iHostname[len - 1]; + + return RFC952_hostname; + } + + ////////////////////////////////////// + + void displayConfigData(Ethernet_Configuration configData) + { + ETM_LOGWARN3(F("Header="), configData.header, + F(", BoardName="), configData.board_name); + ETM_LOGWARN1(F("StaticIP="), configData.static_IP); + +#if USE_DYNAMIC_PARAMETERS + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + ETM_LOGINFO3("i=", i, ",id=", myMenuItems[i].id); + ETM_LOGINFO1("data=", myMenuItems[i].pdata); + } +#endif + } + + ////////////////////////////////////// + +#define ETHERNET_BOARD_TYPE "WT32_ETH01" +#define WM_NO_CONFIG "blank" + + int calcChecksum() + { + int checkSum = 0; + for (uint16_t index = 0; index < (sizeof(Ethernet_Manager_config) - sizeof(Ethernet_Manager_config.checkSum)); index++) + { + checkSum += * ( ( (byte*) &Ethernet_Manager_config ) + index); + } + + return checkSum; + } + +#if ( USE_LITTLEFS || USE_SPIFFS ) + +#define CONFIG_FILENAME ("/etm_config.dat") +#define CONFIG_FILENAME_BACKUP ("/etm_config.bak") + +#define CREDENTIALS_FILENAME ("/etm_cred.dat") +#define CREDENTIALS_FILENAME_BACKUP ("/etm_cred.bak") + +#define CONFIG_PORTAL_FILENAME ("/etm_cp.dat") +#define CONFIG_PORTAL_FILENAME_BACKUP ("/etm_cp.bak") + + ////////////////////////////////////////////// + + void saveForcedCP(uint32_t value) + { + File file = FileFS.open(CONFIG_PORTAL_FILENAME, "w"); + + ETM_LOGINFO(F("SaveCPFile ")); + + if (file) + { + file.write((uint8_t*) &value, sizeof(value)); + file.close(); + ETM_LOGINFO(F("OK")); + } + else + { + ETM_LOGINFO(F("failed")); + } + + // Trying open redundant CP file + file = FileFS.open(CONFIG_PORTAL_FILENAME_BACKUP, "w"); + + ETM_LOGINFO(F("SaveBkUpCPFile ")); + + if (file) + { + file.write((uint8_t *) &value, sizeof(value)); + file.close(); + ETM_LOGINFO(F("OK")); + } + else + { + ETM_LOGINFO(F("failed")); + } + } + + ////////////////////////////////////////////// + + void setForcedCP(bool isPersistent) + { + uint32_t readForcedConfigPortalFlag = isPersistent? FORCED_PERS_CONFIG_PORTAL_FLAG_DATA : FORCED_CONFIG_PORTAL_FLAG_DATA; + + ETM_LOGDEBUG(isPersistent ? F("setForcedCP Persistent") : F("setForcedCP non-Persistent")); + + saveForcedCP(readForcedConfigPortalFlag); + } + + ////////////////////////////////////////////// + + void clearForcedCP() + { + uint32_t readForcedConfigPortalFlag = 0; + + ETM_LOGDEBUG(F("clearForcedCP")); + + saveForcedCP(readForcedConfigPortalFlag); + } + + ////////////////////////////////////////////// + + bool isForcedCP() + { + uint32_t readForcedConfigPortalFlag; + + ETM_LOGDEBUG(F("Check if isForcedCP")); + + File file = FileFS.open(CONFIG_PORTAL_FILENAME, "r"); + ETM_LOGINFO(F("LoadCPFile ")); + + if (!file) + { + ETM_LOGINFO(F("failed")); + + // Trying open redundant config file + file = FileFS.open(CONFIG_PORTAL_FILENAME_BACKUP, "r"); + ETM_LOGINFO(F("LoadBkUpCPFile ")); + + if (!file) + { + ETM_LOGINFO(F("failed")); + return false; + } + } + + file.readBytes((char *) &readForcedConfigPortalFlag, sizeof(readForcedConfigPortalFlag)); + + ETM_LOGINFO(F("OK")); + file.close(); + + // Return true if forced CP (0xDEADBEEF read at offset EPROM_START + DRD_FLAG_DATA_SIZE + CONFIG_DATA_SIZE) + // => set flag noForcedConfigPortal = false + if (readForcedConfigPortalFlag == FORCED_CONFIG_PORTAL_FLAG_DATA) + { + persForcedConfigPortal = false; + return true; + } + else if (readForcedConfigPortalFlag == FORCED_PERS_CONFIG_PORTAL_FLAG_DATA) + { + persForcedConfigPortal = true; + return true; + } + else + { + return false; + } + } + + ////////////////////////////////////////////// + +#if USE_DYNAMIC_PARAMETERS + + bool checkDynamicData() + { + int checkSum = 0; + int readCheckSum; + char* readBuffer; + + File file = FileFS.open(CREDENTIALS_FILENAME, "r"); + ETM_LOGINFO(F("LoadCredFile ")); + + if (!file) + { + ETM_LOGINFO(F("failed")); + + // Trying open redundant config file + file = FileFS.open(CREDENTIALS_FILENAME_BACKUP, "r"); + ETM_LOGINFO(F("LoadBkUpCredFile ")); + + if (!file) + { + ETM_LOGINFO(F("failed")); + return false; + } + } + + // Find the longest pdata, then dynamically allocate buffer. Remember to free when done + // This is used to store tempo data to calculate checksum to see of data is valid + // We dont like to destroy myMenuItems[i].pdata with invalid data + + uint16_t maxBufferLength = 0; + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + if (myMenuItems[i].maxlen > maxBufferLength) + maxBufferLength = myMenuItems[i].maxlen; + } + + if (maxBufferLength > 0) + { + readBuffer = new char[ maxBufferLength + 1 ]; + + // check to see NULL => stop and return false + if (readBuffer == NULL) + { + ETM_LOGERROR(F("ChkCrR: Error can't allocate buffer.")); + return false; + } + else + { + ETM_LOGDEBUG1(F("ChkCrR: Buffer allocated, sz="), maxBufferLength + 1); + } + + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + char* _pointer = readBuffer; + + // Actual size of pdata is [maxlen + 1] + memset(readBuffer, 0, myMenuItems[i].maxlen + 1); + + file.readBytes(_pointer, myMenuItems[i].maxlen); + + ETM_LOGDEBUG3(F("ChkCrR:pdata="), readBuffer, F(",len="), myMenuItems[i].maxlen); + + for (uint16_t j = 0; j < myMenuItems[i].maxlen; j++,_pointer++) + { + checkSum += *_pointer; + } + } + + file.readBytes((char *) &readCheckSum, sizeof(readCheckSum)); + + ETM_LOGINFO(F("OK")); + file.close(); + + ETM_LOGINFO3(F("CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX)); + + // Free buffer + delete [] readBuffer; + ETM_LOGDEBUG(F("Buffer freed")); + + if ( checkSum != readCheckSum) + { + return true; + } + } + + return false; + } + + ////////////////////////////////////////////// + + bool loadDynamicData() + { + int checkSum = 0; + int readCheckSum; + totalDataSize = sizeof(Ethernet_Manager_config) + sizeof(readCheckSum); + + File file = FileFS.open(CREDENTIALS_FILENAME, "r"); + ETM_LOGINFO(F("LoadCredFile ")); + + if (!file) + { + ETM_LOGINFO(F("failed")); + + // Trying open redundant config file + file = FileFS.open(CREDENTIALS_FILENAME_BACKUP, "r"); + ETM_LOGINFO(F("LoadBkUpCredFile ")); + + if (!file) + { + ETM_LOGINFO(F("failed")); + return false; + } + } + + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + char* _pointer = myMenuItems[i].pdata; + totalDataSize += myMenuItems[i].maxlen; + + // Actual size of pdata is [maxlen + 1] + memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); + + file.readBytes(_pointer, myMenuItems[i].maxlen); + + ETM_LOGDEBUG3(F("CrR:pdata="), myMenuItems[i].pdata, F(",len="), myMenuItems[i].maxlen); + + for (uint16_t j = 0; j < myMenuItems[i].maxlen; j++,_pointer++) + { + checkSum += *_pointer; + } + } + + file.readBytes((char *) &readCheckSum, sizeof(readCheckSum)); + + ETM_LOGINFO(F("OK")); + file.close(); + + ETM_LOGINFO3(F("CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX)); + + if ( checkSum != readCheckSum) + { + return false; + } + + return true; + } + + ////////////////////////////////////////////// + + void saveDynamicData() + { + int checkSum = 0; + + File file = FileFS.open(CREDENTIALS_FILENAME, "w"); + ETM_LOGINFO(F("SaveCredFile ")); + + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + char* _pointer = myMenuItems[i].pdata; + + ETM_LOGDEBUG3(F("CW1:pdata="), myMenuItems[i].pdata, F(",len="), myMenuItems[i].maxlen); + + if (file) + { + file.write((uint8_t*) _pointer, myMenuItems[i].maxlen); + } + else + { + ETM_LOGINFO(F("failed")); + } + + for (uint16_t j = 0; j < myMenuItems[i].maxlen; j++,_pointer++) + { + checkSum += *_pointer; + } + } + + if (file) + { + file.write((uint8_t*) &checkSum, sizeof(checkSum)); + file.close(); + ETM_LOGINFO(F("OK")); + } + else + { + ETM_LOGINFO(F("failed")); + } + + ETM_LOGINFO1(F("CrWCSum=0x"), String(checkSum, HEX)); + + // Trying open redundant Auth file + file = FileFS.open(CREDENTIALS_FILENAME_BACKUP, "w"); + ETM_LOGINFO(F("SaveBkUpCredFile ")); + + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + char* _pointer = myMenuItems[i].pdata; + + ETM_LOGDEBUG3(F("CW2:pdata="), myMenuItems[i].pdata, F(",len="), myMenuItems[i].maxlen); + + if (file) + { + file.write((uint8_t*) _pointer, myMenuItems[i].maxlen); + } + else + { + ETM_LOGINFO(F("failed")); + } + + for (uint16_t j = 0; j < myMenuItems[i].maxlen; j++,_pointer++) + { + checkSum += *_pointer; + } + } + + if (file) + { + file.write((uint8_t*) &checkSum, sizeof(checkSum)); + file.close(); + ETM_LOGINFO(F("OK")); + } + else + { + ETM_LOGINFO(F("failed")); + } + } +#endif + + ////////////////////////////////////////////// + + void NULLTerminateConfig() + { + //#define HEADER_MAX_LEN 16 + //#define STATIC_IP_MAX_LEN 16 + //#define BOARD_NAME_MAX_LEN 24 + + // NULL Terminating to be sure + Ethernet_Manager_config.header [HEADER_MAX_LEN - 1] = 0; + Ethernet_Manager_config.static_IP [STATIC_IP_MAX_LEN - 1] = 0; + Ethernet_Manager_config.board_name[BOARD_NAME_MAX_LEN - 1] = 0; + } + + ////////////////////////////////////////////// + + bool loadConfigData() + { + ETM_LOGINFO(F("LoadCfgFile ")); + + // file existed + File file = FileFS.open(CONFIG_FILENAME, "r"); + + if (!file) + { + ETM_LOGINFO(F("failed")); + + // Trying open redundant config file + file = FileFS.open(CONFIG_FILENAME_BACKUP, "r"); + + ETM_LOGINFO(F("LoadBkUpCfgFile ")); + + if (!file) + { + ETM_LOGINFO(F("failed")); + return false; + } + } + + file.readBytes((char *) &Ethernet_Manager_config, sizeof(Ethernet_Manager_config)); + + ETM_LOGINFO(F("OK")); + file.close(); + + NULLTerminateConfig(); + + return true; + } + + void saveConfigData() + { + ETM_LOGINFO(F("SaveCfgFile ")); + + int calChecksum = calcChecksum(); + Ethernet_Manager_config.checkSum = calChecksum; + ETM_LOGINFO1(F("WCSum=0x"), String(calChecksum, HEX)); + + File file = FileFS.open(CONFIG_FILENAME, "w"); + + if (file) + { + file.write((uint8_t*) &Ethernet_Manager_config, sizeof(Ethernet_Manager_config)); + + + file.close(); + ETM_LOGINFO(F("OK")); + } + else + { + ETM_LOGINFO(F("failed")); + } + + ETM_LOGINFO(F("SaveBkUpCfgFile ")); + + // Trying open redundant Auth file + file = FileFS.open(CONFIG_FILENAME_BACKUP, "w"); + + if (file) + { + file.write((uint8_t *) &Ethernet_Manager_config, sizeof(Ethernet_Manager_config)); + + file.close(); + ETM_LOGINFO(F("OK")); + } + else + { + ETM_LOGINFO(F("failed")); + } + } + + ////////////////////////////////////////////// + + void saveAllConfigData() + { + saveConfigData(); + +#if USE_DYNAMIC_PARAMETERS + saveDynamicData(); +#endif + } + + ////////////////////////////////////////////// + + void loadAndSaveDefaultConfigData() + { + // Load Default Config Data from Sketch + memcpy(&Ethernet_Manager_config, &defaultConfig, sizeof(Ethernet_Manager_config)); + strcpy(Ethernet_Manager_config.header, ETHERNET_BOARD_TYPE); + + // Including config and dynamic data, and assume valid + saveConfigData(); + + ETM_LOGDEBUG(F("======= Start Loaded Config Data =======")); + displayConfigData(Ethernet_Manager_config); + } + + ////////////////////////////////////////////// + + // Return false if init new EEPROM or SPIFFS. No more need trying to connect. Go directly to config mode + bool getConfigData() + { + bool dynamicDataValid = true; + int calChecksum; + + hadConfigData = false; + + // Format SPIFFS if not yet + if (!FileFS.begin(true)) + { + ETM_LOGERROR(F("SPIFFS/LittleFS failed! Formatting.")); + + if (!FileFS.begin()) + { +#if USE_LITTLEFS + ETM_LOGERROR(F("LittleFS failed!. Please use SPIFFS or EEPROM.")); +#else + ETM_LOGERROR(F("SPIFFS failed!. Please use LittleFS or EEPROM.")); +#endif + return false; + } + } + + if (LOAD_DEFAULT_CONFIG_DATA) + { + // Load Config Data from Sketch + memcpy(&Ethernet_Manager_config, &defaultConfig, sizeof(Ethernet_Manager_config)); + strcpy(Ethernet_Manager_config.header, ETHERNET_BOARD_TYPE); + + // Including config and dynamic data, and assume valid + saveAllConfigData(); + + ETM_LOGINFO(F("======= Start Loaded Config Data =======")); + displayConfigData(Ethernet_Manager_config); + + // Don't need Config Portal anymore + return true; + } +#if USE_DYNAMIC_PARAMETERS + else if ( ( FileFS.exists(CONFIG_FILENAME) || FileFS.exists(CONFIG_FILENAME_BACKUP) ) && + ( FileFS.exists(CREDENTIALS_FILENAME) || FileFS.exists(CREDENTIALS_FILENAME_BACKUP) ) ) +#else + else if ( FileFS.exists(CONFIG_FILENAME) || FileFS.exists(CONFIG_FILENAME_BACKUP) ) +#endif + { + // if config file exists, load + if (!loadConfigData()) + { + return false; + } + + ETM_LOGINFO(F("======= Start Stored Config Data =======")); + displayConfigData(Ethernet_Manager_config); + + calChecksum = calcChecksum(); + + ETM_LOGINFO3(F("CCSum=0x"), String(calChecksum, HEX), + F(",RCSum=0x"), String(Ethernet_Manager_config.checkSum, HEX)); + +#if USE_DYNAMIC_PARAMETERS + // Load dynamic data + dynamicDataValid = loadDynamicData(); + + if (dynamicDataValid) + { + ETM_LOGINFO(F("Valid Stored Dynamic Data")); + } + else + { + ETM_LOGINFO(F("Invalid Stored Dynamic Data. Ignored")); + } +#endif + } + else + { + // Not loading Default config data, but having no config file => Config Portal + return false; + } + + if ( (strncmp(Ethernet_Manager_config.header, ETHERNET_BOARD_TYPE, strlen(ETHERNET_BOARD_TYPE)) != 0) || + (calChecksum != Ethernet_Manager_config.checkSum) || !dynamicDataValid || + ( (calChecksum == 0) && (Ethernet_Manager_config.checkSum == 0) ) ) + + { + // Including Credentials CSum + ETM_LOGINFO1(F("InitCfgFile,sz="), sizeof(Ethernet_Manager_config)); + + // doesn't have any configuration + if (LOAD_DEFAULT_CONFIG_DATA) + { + memcpy(&Ethernet_Manager_config, &defaultConfig, sizeof(Ethernet_Manager_config)); + } + else + { + memset(&Ethernet_Manager_config, 0, sizeof(Ethernet_Manager_config)); + + strcpy(Ethernet_Manager_config.static_IP, WM_NO_CONFIG); + strcpy(Ethernet_Manager_config.board_name, WM_NO_CONFIG); + +#if USE_DYNAMIC_PARAMETERS + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + // Actual size of pdata is [maxlen + 1] + memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); + strncpy(myMenuItems[i].pdata, WM_NO_CONFIG, myMenuItems[i].maxlen); + } +#endif + } + + strcpy(Ethernet_Manager_config.header, ETHERNET_BOARD_TYPE); + +#if USE_DYNAMIC_PARAMETERS + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + ETM_LOGDEBUG3(F("g:myMenuItems["), i, F("]="), myMenuItems[i].pdata ); + } +#endif + + // Don't need + Ethernet_Manager_config.checkSum = 0; + + saveAllConfigData(); + + return false; + } + else + { + //displayConfigData(Ethernet_Manager_config); + } + + return true; + } + + ////////////////////////////////////////////// + +#else // USE_EEPROM + +#ifndef EEPROM_SIZE + #define EEPROM_SIZE 2048 +#else + #if (EEPROM_SIZE > 2048) + #warning EEPROM_SIZE must be <= 2048. Reset to 2048 + #undef EEPROM_SIZE + #define EEPROM_SIZE 2048 + #endif + + // FLAG_DATA_SIZE is 4, to store DRD flag + #if (EEPROM_SIZE < FLAG_DATA_SIZE + CONFIG_DATA_SIZE) + #warning EEPROM_SIZE must be > CONFIG_DATA_SIZE. Reset to 512 + #undef EEPROM_SIZE + #define EEPROM_SIZE 2048 + #endif +#endif + +#ifndef EEPROM_START + #define EEPROM_START 0 //define 256 in DRD + #warning EEPROM_START not defined. Set to 0 +#else + #if (EEPROM_START + DRD_FLAG_DATA_SIZE + CONFIG_DATA_SIZE + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE > EEPROM_SIZE) + #error EPROM_START + DRD_FLAG_DATA_SIZE + CONFIG_DATA_SIZE + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE > EEPROM_SIZE. Please adjust. + #endif +#endif + +// Stating positon to store Blynk8266_WM_config +#define CONFIG_EEPROM_START (EEPROM_START + FLAG_DATA_SIZE) + + ////////////////////////////////////////////// + + void setForcedCP(bool isPersistent) + { + uint32_t readForcedConfigPortalFlag = isPersistent? FORCED_PERS_CONFIG_PORTAL_FLAG_DATA : FORCED_CONFIG_PORTAL_FLAG_DATA; + + ETM_LOGINFO(F("setForcedCP")); + + EEPROM.put(CONFIG_EEPROM_START + CONFIG_DATA_SIZE, readForcedConfigPortalFlag); + EEPROM.commit(); + } + ////////////////////////////////////////////// + + void clearForcedCP() + { + ETM_LOGINFO(F("clearForcedCP")); + + EEPROM.put(CONFIG_EEPROM_START + CONFIG_DATA_SIZE, 0); + EEPROM.commit(); + } + + ////////////////////////////////////////////// + + bool isForcedCP() + { + uint32_t readForcedConfigPortalFlag; + + ETM_LOGINFO(F("Check if isForcedCP")); + + // Return true if forced CP (0xDEADBEEF read at offset EPROM_START + DRD_FLAG_DATA_SIZE + CONFIG_DATA_SIZE) + // => set flag noForcedConfigPortal = false + EEPROM.get(CONFIG_EEPROM_START + CONFIG_DATA_SIZE, readForcedConfigPortalFlag); + + // Return true if forced CP (0xDEADBEEF read at offset EPROM_START + DRD_FLAG_DATA_SIZE + CONFIG_DATA_SIZE) + // => set flag noForcedConfigPortal = false + if (readForcedConfigPortalFlag == FORCED_CONFIG_PORTAL_FLAG_DATA) + { + persForcedConfigPortal = false; + return true; + } + else if (readForcedConfigPortalFlag == FORCED_PERS_CONFIG_PORTAL_FLAG_DATA) + { + persForcedConfigPortal = true; + return true; + } + else + { + return false; + } + } + + ////////////////////////////////////////////// + +#if USE_DYNAMIC_PARAMETERS + + bool checkDynamicData() + { + int checkSum = 0; + int readCheckSum; + + #define BUFFER_LEN 128 + char readBuffer[BUFFER_LEN + 1]; + + uint16_t offset = CONFIG_EEPROM_START + sizeof(Ethernet_Manager_config) + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE; + + // Find the longest pdata, then dynamically allocate buffer. Remember to free when done + // This is used to store tempo data to calculate checksum to see of data is valid + // We dont like to destroy myMenuItems[i].pdata with invalid data + + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + if (myMenuItems[i].maxlen > BUFFER_LEN) + { + // Size too large, abort and flag false + ETM_LOGERROR(F("ChkCrR: Error Small Buffer.")); + return false; + } + } + + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + char* _pointer = readBuffer; + + // Prepare buffer, more than enough + memset(readBuffer, 0, sizeof(readBuffer)); + + // Read more than necessary, but OK and easier to code + EEPROM.get(offset, readBuffer); + // NULL terminated + readBuffer[myMenuItems[i].maxlen] = 0; + + ETM_LOGDEBUG3(F("ChkCrR:pdata="), readBuffer, F(",len="), myMenuItems[i].maxlen); + + for (uint16_t j = 0; j < myMenuItems[i].maxlen; j++,_pointer++) + { + checkSum += *_pointer; + } + + offset += myMenuItems[i].maxlen; + } + + EEPROM.get(offset, readCheckSum); + + ETM_LOGINFO3(F("ChkCrR:CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX)); + + if ( checkSum != readCheckSum) + { + return false; + } + + return true; + } + + ////////////////////////////////////////////// + + bool EEPROM_getDynamicData() + { + int readCheckSum; + int checkSum = 0; + uint16_t offset = CONFIG_EEPROM_START + sizeof(Ethernet_Manager_config) + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE; + + totalDataSize = sizeof(Ethernet_Manager_config) + sizeof(readCheckSum); + + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + char* _pointer = myMenuItems[i].pdata; + totalDataSize += myMenuItems[i].maxlen; + + // Actual size of pdata is [maxlen + 1] + memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); + + for (uint16_t j = 0; j < myMenuItems[i].maxlen; j++,_pointer++,offset++) + { + *_pointer = EEPROM.read(offset); + + checkSum += *_pointer; + } + + ETM_LOGDEBUG3(F("CR:pdata="), myMenuItems[i].pdata, F(",len="), myMenuItems[i].maxlen); + } + + EEPROM.get(offset, readCheckSum); + + ETM_LOGINFO3(F("CrCCsum=0x"), String(checkSum, HEX), F(",CrRCsum=0x"), String(readCheckSum, HEX)); + + if ( checkSum != readCheckSum) + { + return false; + } + + return true; + } + + ////////////////////////////////////////////// + + void EEPROM_putDynamicData() + { + int checkSum = 0; + uint16_t offset = CONFIG_EEPROM_START + sizeof(Ethernet_Manager_config) + FORCED_CONFIG_PORTAL_FLAG_DATA_SIZE; + + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + char* _pointer = myMenuItems[i].pdata; + + ETM_LOGDEBUG3(F("CW:pdata="), myMenuItems[i].pdata, F(",len="), myMenuItems[i].maxlen); + + for (uint16_t j = 0; j < myMenuItems[i].maxlen; j++,_pointer++,offset++) + { + EEPROM.write(offset, *_pointer); + + checkSum += *_pointer; + } + } + + EEPROM.put(offset, checkSum); + //EEPROM.commit(); + + ETM_LOGINFO1(F("CrWCSum=0x"), String(checkSum, HEX)); + } +#endif + + ////////////////////////////////////////////// + + void saveConfigData() + { + int calChecksum = calcChecksum(); + Ethernet_Manager_config.checkSum = calChecksum; + ETM_LOGINFO3(F("SaveEEPROM,sz="), EEPROM_SIZE, F(",CSum=0x"), String(calChecksum, HEX)) + + EEPROM.put(CONFIG_EEPROM_START, Ethernet_Manager_config); + + EEPROM.commit(); + } + + ////////////////////////////////////////////// + + void saveAllConfigData() + { + int calChecksum = calcChecksum(); + Ethernet_Manager_config.checkSum = calChecksum; + ETM_LOGINFO3(F("SaveEEPROM,sz="), EEPROM_SIZE, F(",CSum=0x"), String(calChecksum, HEX)) + + EEPROM.put(CONFIG_EEPROM_START, Ethernet_Manager_config); + +#if USE_DYNAMIC_PARAMETERS + EEPROM_putDynamicData(); +#endif + + EEPROM.commit(); + } + + ////////////////////////////////////////////// + + void loadAndSaveDefaultConfigData() + { + // Load Default Config Data from Sketch + memcpy(&Ethernet_Manager_config, &defaultConfig, sizeof(Ethernet_Manager_config)); + strcpy(Ethernet_Manager_config.header, ETHERNET_BOARD_TYPE); + + // Including config and dynamic data, and assume valid + saveConfigData(); + + ETM_LOGINFO(F("======= Start Loaded Config Data =======")); + displayConfigData(Ethernet_Manager_config); + } + + ////////////////////////////////////////////// + + bool getConfigData() + { + bool dynamicDataValid = true; + int calChecksum; + + hadConfigData = false; + + EEPROM.begin(EEPROM_SIZE); + ETM_LOGINFO1(F("EEPROMsz:"), EEPROM_SIZE); + + if (LOAD_DEFAULT_CONFIG_DATA) + { + // Load Config Data from Sketch + memcpy(&Ethernet_Manager_config, &defaultConfig, sizeof(Ethernet_Manager_config)); + strcpy(Ethernet_Manager_config.header, ETHERNET_BOARD_TYPE); + + // Including config and dynamic data, and assume valid + saveAllConfigData(); + + ETM_LOGINFO(F("======= Start Loaded Config Data =======")); + displayConfigData(Ethernet_Manager_config); + + // Don't need Config Portal anymore + return true; + } + else + { + // Load data from EEPROM + EEPROM.get(CONFIG_EEPROM_START, Ethernet_Manager_config); + + ETM_LOGINFO(F("======= Start Stored Config Data =======")); + displayConfigData(Ethernet_Manager_config); + + calChecksum = calcChecksum(); + + ETM_LOGINFO3(F("CCSum=0x"), String(calChecksum, HEX), + F(",RCSum=0x"), String(Ethernet_Manager_config.checkSum, HEX)); + +#if USE_DYNAMIC_PARAMETERS + + // Load dynamic data from EEPROM + dynamicDataValid = EEPROM_getDynamicData(); + + if (dynamicDataValid) + { + ETM_LOGINFO(F("Valid Stored Dynamic Data")); + } + else + { + ETM_LOGINFO(F("Invalid Stored Dynamic Data. Ignored")); + } +#endif + } + + if ( (strncmp(Ethernet_Manager_config.header, ETHERNET_BOARD_TYPE, strlen(ETHERNET_BOARD_TYPE)) != 0) || + (calChecksum != Ethernet_Manager_config.checkSum) || !dynamicDataValid || + ( (calChecksum == 0) && (Ethernet_Manager_config.checkSum == 0) ) ) + { + // Including Credentials CSum + ETM_LOGINFO3(F("InitEEPROM,sz="), EEPROM_SIZE, F(",DataSz="), totalDataSize); + + // doesn't have any configuration + if (LOAD_DEFAULT_CONFIG_DATA) + { + memcpy(&Ethernet_Manager_config, &defaultConfig, sizeof(Ethernet_Manager_config)); + } + else + { + memset(&Ethernet_Manager_config, 0, sizeof(Ethernet_Manager_config)); + + //strcpy(Ethernet_Manager_config.static_IP, WM_NO_CONFIG); + strcpy(Ethernet_Manager_config.board_name, ETHERNET_BOARD_TYPE); + +#if USE_DYNAMIC_PARAMETERS + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + // Actual size of pdata is [maxlen + 1] + memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); + strncpy(myMenuItems[i].pdata, WM_NO_CONFIG, myMenuItems[i].maxlen); + } +#endif + } + + strcpy(Ethernet_Manager_config.header, ETHERNET_BOARD_TYPE); + +#if USE_DYNAMIC_PARAMETERS + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + ETM_LOGDEBUG3(F("g:myMenuItems["), i, F("]="), myMenuItems[i].pdata ); + } +#endif + + // Don't need + Ethernet_Manager_config.checkSum = 0; + + saveAllConfigData(); + + return false; + } + else + { + displayConfigData(Ethernet_Manager_config); + } + + return true; + } + +#endif // ( USE_LITTLEFS || USE_SPIFFS ) + + ////////////////////////////////////////////// + + // NEW + void createHTML(String& root_html_template) + { + String pitem; + + root_html_template = ETM_HTML_HEAD_START; + + #if USING_CUSTOMS_STYLE + // Using Customs style when not NULL + if (ETM_HTML_HEAD_CUSTOMS_STYLE) + root_html_template += ETM_HTML_HEAD_CUSTOMS_STYLE; + else + root_html_template += ETM_HTML_HEAD_STYLE; + #else + root_html_template += ETM_HTML_HEAD_STYLE; + #endif + + #if USING_CUSTOMS_HEAD_ELEMENT + if (_CustomsHeadElement) + root_html_template += _CustomsHeadElement; + #endif + + root_html_template += String(ETM_HTML_HEAD_END) + ETM_FLDSET_START; + +#if USE_DYNAMIC_PARAMETERS + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + pitem = String(ETM_HTML_PARAM); + + pitem.replace("{b}", myMenuItems[i].displayName); + pitem.replace("{v}", myMenuItems[i].id); + pitem.replace("{i}", myMenuItems[i].id); + + root_html_template += pitem; + } +#endif + + root_html_template += String(ETM_FLDSET_END) + ETM_HTML_BUTTON + ETM_HTML_SCRIPT; + +#if USE_DYNAMIC_PARAMETERS + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + pitem = String(ETM_HTML_SCRIPT_ITEM); + + pitem.replace("{d}", myMenuItems[i].id); + + root_html_template += pitem; + } +#endif + + root_html_template += String(ETM_HTML_SCRIPT_END) + ETM_HTML_END; + + return; + } + + ////////////////////////////////////////////// + + void serverSendHeaders() + { + ETM_LOGDEBUG3(F("serverSendHeaders:WM_HTTP_CACHE_CONTROL:"), WM_HTTP_CACHE_CONTROL, "=", WM_HTTP_NO_STORE); + server->sendHeader(WM_HTTP_CACHE_CONTROL, WM_HTTP_NO_STORE); + +#if USING_CORS_FEATURE + // New from v1.2.0, for configure CORS Header, default to WM_HTTP_CORS_ALLOW_ALL = "*" + ETM_LOGDEBUG3(F("serverSendHeaders:WM_HTTP_CORS:"), WM_HTTP_CORS, " : ", _CORS_Header); + server->sendHeader(WM_HTTP_CORS, _CORS_Header); +#endif + + ETM_LOGDEBUG3(F("serverSendHeaders:WM_HTTP_PRAGMA:"), WM_HTTP_PRAGMA, " : ", WM_HTTP_NO_CACHE); + server->sendHeader(WM_HTTP_PRAGMA, WM_HTTP_NO_CACHE); + + ETM_LOGDEBUG3(F("serverSendHeaders:WM_HTTP_EXPIRES:"), WM_HTTP_EXPIRES, " : ", "-1"); + server->sendHeader(WM_HTTP_EXPIRES, "-1"); + } + + ////////////////////////////////////////////// + + void handleRequest() + { + if (server) + { + String key = server->arg("key"); + String value = server->arg("value"); + + static int number_items_Updated = 0; + + if (key == "" && value == "") + { + // New from v1.2.0 + serverSendHeaders(); + ////// + + String result; + createHTML(result); + + ETM_LOGDEBUG1(F("h:Repl:"), result); + + // Reset configTimeout to stay here until finished. + configTimeout = 0; + + if ( RFC952_hostname[0] != 0 ) + { + // Replace only if Hostname is valid + result.replace("WT32_ETH01_Manager", RFC952_hostname); + } + else if ( Ethernet_Manager_config.board_name[0] != 0 ) + { + // Or replace only if board_name is valid. Otherwise, keep intact + result.replace("WT32_ETH01_Manager", Ethernet_Manager_config.board_name); + } + + if (hadConfigData) + { + result.replace("[[ip]]", Ethernet_Manager_config.static_IP); + result.replace("[[nm]]", Ethernet_Manager_config.board_name); + } + else + { + result.replace("[[ip]]", "0"); + result.replace("[[nm]]", ETHERNET_BOARD_TYPE); + } + +#if USE_DYNAMIC_PARAMETERS + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + String toChange = String("[[") + myMenuItems[i].id + "]]"; + result.replace(toChange, myMenuItems[i].pdata); + + ETM_LOGDEBUG3(F("h1:myMenuItems["), i, F("]="), myMenuItems[i].pdata ); + } +#endif + + ETM_LOGDEBUG1(F("h:HTML page size:"), result.length()); + ETM_LOGDEBUG1(F("h:HTML="), result); + + server->send(200, WM_HTTP_HEAD_TEXT_HTML, result); + + return; + } + + if (number_items_Updated == 0) + { + memset(&Ethernet_Manager_config, 0, sizeof(Ethernet_Manager_config)); + strcpy(Ethernet_Manager_config.header, ETHERNET_BOARD_TYPE); + } + +#if USE_DYNAMIC_PARAMETERS + if (!menuItemUpdated) + { + // Don't need to free + menuItemUpdated = new bool[NUM_MENU_ITEMS]; + + if (menuItemUpdated) + { + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + // To flag item is not yet updated + menuItemUpdated[i] = false; + } + + ETM_LOGDEBUG(F("h: Init menuItemUpdated" )); + } + else + { + ETM_LOGERROR(F("h: Error can't alloc memory for menuItemUpdated" )); + } + } +#endif + + static bool ip_Updated = false; + static bool nm_Updated = false; + + if (!ip_Updated && (key == String("ip"))) + { + ETM_LOGDEBUG(F("h:repl ip")); + ip_Updated = true; + + number_items_Updated++; + + if (strlen(value.c_str()) < sizeof(Ethernet_Manager_config.static_IP) - 1) + strcpy(Ethernet_Manager_config.static_IP, value.c_str()); + else + strncpy(Ethernet_Manager_config.static_IP, value.c_str(), sizeof(Ethernet_Manager_config.static_IP) - 1); + } + else if (!nm_Updated && (key == String("nm"))) + { + ETM_LOGDEBUG(F("h:repl nm")); + nm_Updated = true; + + number_items_Updated++; + + if (strlen(value.c_str()) < sizeof(Ethernet_Manager_config.board_name) - 1) + strcpy(Ethernet_Manager_config.board_name, value.c_str()); + else + strncpy(Ethernet_Manager_config.board_name, value.c_str(), sizeof(Ethernet_Manager_config.board_name) - 1); + } + +#if USE_DYNAMIC_PARAMETERS + else + { + for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++) + { + if ( !menuItemUpdated[i] && (key == myMenuItems[i].id) ) + { + ETM_LOGDEBUG3(F("h:"), myMenuItems[i].id, F("="), value.c_str() ); + + menuItemUpdated[i] = true; + + number_items_Updated++; + + // Actual size of pdata is [maxlen + 1] + memset(myMenuItems[i].pdata, 0, myMenuItems[i].maxlen + 1); + + if ((int) strlen(value.c_str()) < myMenuItems[i].maxlen) + strcpy(myMenuItems[i].pdata, value.c_str()); + else + strncpy(myMenuItems[i].pdata, value.c_str(), myMenuItems[i].maxlen); + + break; + } + } + } +#endif + + ETM_LOGDEBUG1(F("h:items updated ="), number_items_Updated); + ETM_LOGDEBUG3(F("h:key ="), key, ", value =", value); + + server->send(200, WM_HTTP_HEAD_TEXT_HTML, "OK"); + +#if USE_DYNAMIC_PARAMETERS + if (number_items_Updated == NUM_CONFIGURABLE_ITEMS + NUM_MENU_ITEMS) +#else + if (number_items_Updated == NUM_CONFIGURABLE_ITEMS) +#endif + { +#if USE_LITTLEFS + ETM_LOGERROR1(F("h:Updating LittleFS:"), CONFIG_FILENAME); +#elif USE_SPIFFS + ETM_LOGERROR1(F("h:Updating SPIFFS:"), CONFIG_FILENAME); +#else + ETM_LOGERROR(F("h:Updating EEPROM. Please wait for reset")); +#endif + + saveAllConfigData(); + + // Done with CP, Clear CP Flag here if forced + if (isForcedConfigPortal) + clearForcedCP(); + + ETM_LOGWARN(F("h:Rst")); + + // Delay then reset after save data + delay(1000); + resetFunc(); + } + } // if (server) + } + + ////////////////////////////////////////////// + +#ifndef CONFIG_TIMEOUT + #warning Default CONFIG_TIMEOUT = 60s + #define CONFIG_TIMEOUT 60000L +#endif + + void startConfigurationMode() + { + ETM_LOGWARN1(F("CfgIP="), ETH.localIP() ); + + if (!server) + { + //server = new EthernetWebServer; + server = new WebServer; + } + + //See https://stackoverflow.com/questions/39803135/c-unresolved-overloaded-function-type?rq=1 + + if (server) + { + server->on("/", [this]() { handleRequest(); } ); + server->begin(); + } + + // If there is no saved config Data, stay in config mode forever until having config Data. + // or SSID, PW, Server,Token ="nothing" + if (hadConfigData) + { + configTimeout = millis() + CONFIG_TIMEOUT; + + ETM_LOGDEBUG3(F("s:millis() = "), millis(), F(", configTimeout = "), configTimeout); + } + else + { + configTimeout = 0; + ETM_LOGDEBUG(F("s:configTimeout = 0")); + } + + configuration_mode = true; + } + + ////////////////////////////////////////////// + + bool connectEthernet() + { + if (!ethernetConnected) + { + // Check go see if static IP is required + IPAddress staticIP; + + if (staticIP.fromString(Ethernet_Manager_config.static_IP)) + { + // Use static IP + ETM_LOGWARN1(F("Start connectEthernet using Static IP ="), staticIP); + + //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, + // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); + //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); + ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); + + // Static IP, leave without this line to get IP via DHCP + //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); + + IPAddress myGW(192, 168, 2, 1); + myGW[0] = staticIP[0]; + myGW[1] = staticIP[1]; + myGW[2] = staticIP[2]; + + ETM_LOGWARN1(F("myGW IP ="), myGW); + + IPAddress mySN(255, 255, 255, 0); + // DNS is a must for StaticIP + IPAddress myDNS(8, 8, 8, 8); + + ETH.config(staticIP, myGW, mySN, myDNS, myGW); + } + else + { + // If static_IP ="nothing" or NULL, use DHCP dynamic IP + ETM_LOGWARN(F("Start connectEthernet using DHCP")); + + //bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, + // eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE); + //ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE); + ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER); + } + + uint32_t waitingCount = 0; + + while (!ethernetConnected && (waitingCount++ < 50) ) + delay(200); + } + + if (ethernetConnected) + { + ETM_LOGWARN1(F("IP:"), ETH.localIP()); + } + + return ethernetConnected; + } +}; + +#endif // Ethernet_WT32_ETH01_Manager_h diff --git a/src/Ethernet_Manager.h b/src/Ethernet_Manager.h index c1baabdd..f9fac90d 100644 --- a/src/Ethernet_Manager.h +++ b/src/Ethernet_Manager.h @@ -1,14 +1,15 @@ /**************************************************************************************************************************** Ethernet_Manager.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #pragma once @@ -26,7 +28,7 @@ #ifndef Ethernet_Manager_h #define Ethernet_Manager_h -#define ETHERNET_MANAGER_VERSION "Ethernet_Manager v1.4.0" +#define ETHERNET_MANAGER_VERSION "Ethernet_Manager v1.5.0" #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET @@ -78,6 +80,8 @@ #ifndef SHIELD_TYPE #define SHIELD_TYPE "Custom Ethernet using Ethernet_XYZ Library" #endif + #elif ETHERNET_USE_WT32_ETH01 + #warning Using ETHERNET_USE_WT32_ETH01 from Ethernet_Manager.h. #else #ifdef USE_ETHERNET #undef USE_ETHERNET @@ -99,12 +103,14 @@ #if USE_NATIVE_ETHERNET #include + #include +#elif ETHERNET_USE_WT32_ETH01 + #include #else #include + #include #endif -#include - #if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \ || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \ || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(__SAMD21G18A__) \ @@ -164,6 +170,8 @@ #include #elif (ETHERNET_USE_TEENSY) #include +#elif ETHERNET_USE_WT32_ETH01 + #include #elif (ETHERNET_USE_ESP32) #include #elif (ETHERNET_USE_ESP8266) @@ -173,7 +181,7 @@ #elif (ETHERNET_USE_RPIPICO) && !defined(ARDUINO_ARCH_MBED) #include #elif (ETHERNET_USE_RPIPICO) && defined(ARDUINO_ARCH_MBED) - #include + #include #else #error This code for SAMD21, SAMD51, SAM-DUE, Teensy (4.1/4.0, 3.x), ESP8266, ESP32, nRF52, RP2040 boards, not AVR Mega nor STM32! Please check your Tools->Board setting. #endif diff --git a/src/Ethernet_Manager_Debug.h b/src/Ethernet_Manager_Debug.h index 4706a34d..cd0b02fe 100644 --- a/src/Ethernet_Manager_Debug.h +++ b/src/Ethernet_Manager_Debug.h @@ -1,14 +1,15 @@ /**************************************************************************************************************************** Ethernet_Manager_Debug.h - For W5x00 and ENC28J60 Ethernet shields. + For W5x00, LAN8720 and ENC28J60 Ethernet shields. - Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00 or ENC28J60 shields, + Ethernet_Manager is a library for nRF52, Teensy, STM32, SAM DUE and SAMD boards, with Ethernet W5x00, LAN8720 or ENC28J60 shields, to enable easy configuration/reconfiguration of Credentials and autoconnect/autoreconnect of Ethernet. AVR Mega is not supported. Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Manager Licensed under MIT license - Version: 1.4.0 + + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -19,6 +20,7 @@ Add customs HTML header feature. Fix bug. 1.3.0 K Hoang 16/05/2021 Add support to RP2040-based boards such as RASPBERRY_PI_PICO 1.4.0 K Hoang 28/05/2021 Add support to Nano_RP2040_Connect, RASPBERRY_PI_PICO using RP2040 Arduino mbed core + 1.5.0 K Hoang 06/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards *****************************************************************************************************************************/ #pragma once