diff --git a/README.md b/README.md index 62115f55..0d62dfcf 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,15 @@ Donate to my libraries using BuyMeACoffee + + --- --- ## Table of Contents +* [Important Note from v2.3.0](#Important-Note-from-v230) * [Important Note from v2.2.2](#Important-Note-from-v222) * [Important Breaking Change from v2.0.0](#Important-Breaking-Change-from-v200) * [Why do we need this EthernetWebServer library](#why-do-we-need-this-ethernetwebserver-library) @@ -102,6 +105,7 @@ * [22. **serveStaticLoadFile**](examples/serveStaticLoadFile) * [23. **AdvancedWebServer_Ptr**](examples/AdvancedWebServer_Ptr) * [24. multiFileProject](examples/multiFileProject) **New** + * [25. EthernetWebServer_BigData](examples/EthernetWebServer_BigData) **New** * [HTTP and WebSocket Client New Examples](#http-and-websocket-client-new-examples) * [ 1. BasicAuthGet](examples/HTTPClient/BasicAuthGet) * [ 2. CustomHeader](examples/HTTPClient/CustomHeader) @@ -158,6 +162,8 @@ * [23. AdvancedWebServer_RP2040_SPI1 on MBED RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library on SPI1](#23-AdvancedWebServer_RP2040_SPI1-on-MBED-RASPBERRY_PI_PICO-with-W5x00-using-Ethernet_Generic-Library-on-SPI1) * [24. AdvancedWebServer_Teensy4x_SPI1 on TEENSY 4.1 with W5x00 using Ethernet_Generic Library on SPI1](#24-AdvancedWebServer_Teensy4x_SPI1-on-TEENSY-41-with-W5x00-using-Ethernet_Generic-Library-on-SPI1) * [25. AdvancedWebServer on Curiosity AVR_AVR128DA48 with W5x00 using Ethernet_Generic Library on SPI](#25-AdvancedWebServer-on-Curiosity-AVR_AVR128DA48-with-W5x00-using-Ethernet_Generic-Library-on-SPI) + * [26. EthernetWebServer_BigData on NRF52840_FEATHER](#26-EthernetWebServer_BigData-on-NRF52840_FEATHER) + * [27. EthernetWebServer_BigData on RASPBERRY_PI_PICO](#27-EthernetWebServer_BigData-on-RASPBERRY_PI_PICO) * [Debug](#debug) * [Troubleshooting](#troubleshooting) * [Issues](#issues) @@ -172,8 +178,15 @@ --- --- +### Important Note from v2.3.0 + +The new [EthernetWebServer v2.3.0+](https://github.com/khoih-prog/EthernetWebServer/releases/tag/v2.3.0) combined with the new [Ethernet_Generic v2.7.0+](https://github.com/khoih-prog/Ethernet_Generic/releases/tag/v2.7.0) fixes severe limitation to permit sending much larger data than total than **2/4/8/16K** buffer of **W5x00 Ethernet**. + +--- + ### Important Note from v2.2.2 + To be safe for systems using old `W5100` shields, the **examples** are using `optional` conservative values for SPI clock speed of 14MHz and `SPI_MODE0` For `SAMD21 M0`, such as `SAMD Zero`, SPI clock speed of 8MHz and `SPI_MODE0` are used. @@ -328,28 +341,28 @@ This [**EthernetWebServer** library](https://github.com/khoih-prog/EthernetWebSe ## Prerequisites 1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest) - 2. [`Arduino AVR core 1.8.5+`](https://github.com/arduino/ArduinoCore-avr) for Arduino (Use Arduino Board Manager) AVR boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-avr.svg)](https://github.com/arduino/ArduinoCore-avr/releases/latest) + 2. [`Arduino AVR core 1.8.6+`](https://github.com/arduino/ArduinoCore-avr) for Arduino (Use Arduino Board Manager) AVR boards. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-avr.svg)](https://github.com/arduino/ArduinoCore-avr/releases/latest) 3. [`Teensy core v1.57+`](https://www.pjrc.com/teensy/td_download.html) for Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0) boards. 4. [`Arduino SAM DUE core v1.6.12+`](https://github.com/arduino/ArduinoCore-sam) for SAM DUE ARM Cortex-M3 boards. 5. [`Arduino SAMD core 1.8.13+`](https://github.com/arduino/ArduinoCore-samd) 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) - 6. [`Adafruit SAMD core 1.7.10+`](https://github.com/adafruit/ArduinoCore-samd) 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. [`Adafruit SAMD core 1.7.11+`](https://github.com/adafruit/ArduinoCore-samd) 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) 7. [`Seeeduino SAMD core 1.8.3+`](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/) 8. [`Adafruit nRF52 v1.3.0+`](https://github.com/adafruit/Adafruit_nRF52_Arduino) 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) 9. [`ESP32 Core 2.0.5+`](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. [`ESP8266 Core 3.0.2+`](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. 11. [`ArduinoCore-mbed mbed_rp2040, mbed_nano, mbed_portenta core 3.4.1+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) **Portenta_H7, RP2040-based boards, such as Nano_RP2040_Connect, RASPBERRY_PI_PICO**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest) -12. [`Earle Philhower's arduino-pico core v2.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. [`Earle Philhower's arduino-pico core v2.6.3+`](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) 13. [`Arduino megaAVR core 1.8.7+`](https://github.com/arduino/ArduinoCore-megaavr/releases) for Arduino megaAVR boards such as **Arduino UNO WiFi Rev2, AVR_NANO_EVERY, etc.** 14. [`SpenceKonde DxCore core 1.4.10+`](https://github.com/SpenceKonde/DxCore) for Arduino AVRDx boards. [![GitHub release](https://img.shields.io/github/release/SpenceKonde/DxCore.svg)](https://github.com/SpenceKonde/DxCore/releases/latest). Follow [**DxCore Installation**](https://github.com/SpenceKonde/DxCore/blob/master/Installation.md). 15. [`Seeeduino nRF52 core 1.0.0+`](https://github.com/Seeed-Studio/Adafruit_nRF52_Arduino) for Seeed nRF52840-based boards such as **Seeed_XIAO_NRF52840 and Seeed_XIAO_NRF52840_SENSE**. [![GitHub release](https://img.shields.io/github/release/Seeed-Studio/Adafruit_nRF52_Arduino.svg)](https://github.com/Seeed-Studio/Adafruit_nRF52_Arduino/releases/latest) 16. `Seeeduino mbed core 2.7.2+` for Seeed nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE** 17. [`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) 18. Depending on which Ethernet card you're using: - - [`Ethernet_Generic library v2.6.2+`](https://github.com/khoih-prog/Ethernet_Generic) for W5100, W5200 and W5500/WIZ550io/WIZ850io/USR-ES1 with Wiznet W5500 chip. [![GitHub release](https://img.shields.io/github/release/khoih-prog/Ethernet_Generic.svg)](https://github.com/khoih-prog/Ethernet_Generic/releases/latest) + - [`Ethernet_Generic library v2.7.0+`](https://github.com/khoih-prog/Ethernet_Generic) for W5100, W5200 and W5500/WIZ550io/WIZ850io/USR-ES1 with Wiznet W5500 chip. [![GitHub release](https://img.shields.io/github/release/khoih-prog/Ethernet_Generic.svg)](https://github.com/khoih-prog/Ethernet_Generic/releases/latest) - [`EthernetENC library v2.0.3+`](https://github.com/jandrassy/EthernetENC) for ENC28J60. [![GitHub release](https://img.shields.io/github/release/jandrassy/EthernetENC.svg)](https://github.com/jandrassy/EthernetENC/releases/latest). **New and Better** - [`UIPEthernet library v2.0.12+`](https://github.com/UIPEthernet/UIPEthernet) for ENC28J60. [![GitHub release](https://img.shields.io/github/release/UIPEthernet/UIPEthernet.svg)](https://github.com/UIPEthernet/UIPEthernet/releases/latest) - [`NativeEthernet Library version stable111+`](https://github.com/vjmuzik/NativeEthernet) for Teensy 4.1 built-in Ethernet. - - [`QNEthernet Library version v0.15.0+`](https://github.com/ssilverman/QNEthernet) for Teensy 4.1 built-in Ethernet. **New** + - [`QNEthernet Library version v0.16.0+`](https://github.com/ssilverman/QNEthernet) for Teensy 4.1 built-in Ethernet. **New** --- --- @@ -483,13 +496,13 @@ Whenever the above-mentioned compiler error issue is fixed with the new Arduino #### 5. For Adafruit SAMD boards - ***To be able to compile, run and automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards***, you have to copy the whole [Adafruit SAMD Packages_Patches](Packages_Patches/adafruit/hardware/samd/1.7.10) directory into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.7.10). + ***To be able to compile, run and automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards***, you have to copy the whole [Adafruit SAMD Packages_Patches](Packages_Patches/adafruit/hardware/samd/1.7.11) directory into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.7.11). -Supposing the Adafruit SAMD core version is 1.7.10. These files must be copied into the directory: +Supposing the Adafruit SAMD core version is 1.7.11. These files must be copied into the directory: -- `~/.arduino15/packages/adafruit/hardware/samd/1.7.10/platform.txt` -- `~/.arduino15/packages/adafruit/hardware/samd/1.7.10/cores/arduino/Print.h` -- `~/.arduino15/packages/adafruit/hardware/samd/1.7.10/cores/arduino/Print.cpp` +- `~/.arduino15/packages/adafruit/hardware/samd/1.7.11/platform.txt` +- `~/.arduino15/packages/adafruit/hardware/samd/1.7.11/cores/arduino/Print.h` +- `~/.arduino15/packages/adafruit/hardware/samd/1.7.11/cores/arduino/Print.cpp` Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz These files must be copied into the directory: @@ -591,12 +604,12 @@ With core after v1.5.0, this step is not necessary anymore thanks to the PR [Add #### 9. For Portenta_H7 boards using Arduino IDE in Linux - **To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.)**, you have to copy the file [portenta_post_install.sh](Packages_Patches/arduino/hardware/mbed_portenta/3.3.0/portenta_post_install.sh) into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/3.3.0/portenta_post_install.sh). + **To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.)**, you have to copy the file [portenta_post_install.sh](Packages_Patches/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh) into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh). Then run the following command using `sudo` ``` -$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/3.3.0 +$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1 $ chmod 755 portenta_post_install.sh $ sudo ./portenta_post_install.sh ``` @@ -609,9 +622,9 @@ This will create the file `/etc/udev/rules.d/49-portenta_h7.rules` as follows: SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666" ``` -Supposing the ArduinoCore-mbed core version is 3.3.0. Now only one file must be copied into the directory: +Supposing the ArduinoCore-mbed core version is 3.4.1. Now only one file must be copied into the directory: -- `~/.arduino15/packages/arduino/hardware/mbed_portenta/3.3.0/portenta_post_install.sh` +- `~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh` Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz @@ -622,25 +635,25 @@ This file must be copied into the directory: #### 10. For RTL8720DN boards using AmebaD core - To avoid compile error relating to PROGMEM, you have to copy the file [Realtek AmebaD core pgmspace.h](Packages_Patches/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace.h) into Realtek AmebaD directory (~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/arduino/avr/pgmspace.h). + To avoid compile error relating to PROGMEM, you have to copy the file [Realtek AmebaD core pgmspace.h](Packages_Patches/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace.h) into Realtek AmebaD directory (~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace.h). Supposing the Realtek AmebaD core version is 3.1.4. This file must be copied into the directory: -- `~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/arduino/avr/pgmspace.h` +- `~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace.h` Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory: -- `~/.arduino15/packages/realtek/hardware/AmebaD/x.yy.zz/cores/arduino/avr/pgmspace.h` +- `~/.arduino15/packages/realtek/hardware/AmebaD/x.yy.zz/cores/ambd/avr/pgmspace.h` #### 11. For SAMD21 and SAMD51 boards using ArduinoCore-fab-sam core - To avoid compile error relating to SAMD21/SAMD51, you have to copy the file [ArduinoCore-fab-sam core pgmspace.h](Packages_Patches/Fab_SAM_Arduino/hardware/samd/1.7.0/boards.txt) into `ArduinoCore-fab-sam` samd directory (~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.7.0/boards.txt). + To avoid compile error relating to SAMD21/SAMD51, you have to copy the file [ArduinoCore-fab-sam core pgmspace.h](Packages_Patches/Fab_SAM_Arduino/hardware/samd/1.9.0/boards.txt) into `ArduinoCore-fab-sam` samd directory (~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.9.0/boards.txt). -Supposing the `ArduinoCore-fab-sam` samd core version is 1.7.0. This file must be copied into the directory: +Supposing the `ArduinoCore-fab-sam` samd core version is 1.9.0. This file must be copied into the directory: -- `~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.7.0/boards.txt` +- `~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.9.0/boards.txt` Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory: @@ -685,6 +698,7 @@ These files must be copied into the directory: - **`~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/cores/nRF5/Print.cpp`** - **`~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/cores/nRF5/Udp.h`** + --- --- @@ -823,7 +837,6 @@ then select **one and only one** Ethernet library to use as follows: - Standard W5x00 Ethernet_Generic library is used by default, in the sketch, just be sure to comment out or leave these #defines to be false : ```cpp - // Only one if the following to be true #define USE_UIP_ETHERNET false #define USE_ETHERNET_PORTENTA_H7 false @@ -1179,7 +1192,7 @@ For example, to run [Change_Interval example](https://github.com/khoih-prog/Ethe

- +

@@ -1187,7 +1200,7 @@ After drag-and-drop the `Change_Interval.ino.hex` into `CURIOSITY` virtual drive

- +

##### How to connect W5x00 to AVDDx @@ -1195,7 +1208,7 @@ After drag-and-drop the `Change_Interval.ino.hex` into `CURIOSITY` virtual drive This is example to demo how to connect W5x00 to Curiosity `AVR128DA48` or `AVR128DB48`

- +

|W5x00|<--->|AVRDx| @@ -1208,7 +1221,7 @@ This is example to demo how to connect W5x00 to Curiosity `AVR128DA48` or `AVR12 |3.3V|<--->|VCC = 51|

- +

@@ -1402,6 +1415,9 @@ Example: 22. [**serveStaticLoadFile**](examples/serveStaticLoadFile). 23. [**AdvancedWebServer_Ptr**](examples/AdvancedWebServer_Ptr). **New** 24. [**multiFileProject**](examples/multiFileProject). **New** +25. [**EthernetWebServer_BigData**](examples/EthernetWebServer_BigData). **New** + + #### HTTP and WebSocket Client New Examples @@ -1447,14 +1463,14 @@ Example: #### 1. File [AdvancedWebServer.ino](examples/AdvancedWebServer/AdvancedWebServer.ino) -https://github.com/khoih-prog/EthernetWebServer/blob/45cff39b1556be463698a4f632fc5090e80032c6/examples/AdvancedWebServer/AdvancedWebServer.ino#L44-L431 +https://github.com/khoih-prog/EthernetWebServer/blob/537e3d08f3b002cb3953ae609ee8c4f94c36a89a/examples/AdvancedWebServer/AdvancedWebServer.ino#L44-L455 --- #### 2. File [defines.h](examples/AdvancedWebServer/defines.h) -https://github.com/khoih-prog/EthernetWebServer/blob/45cff39b1556be463698a4f632fc5090e80032c6/examples/AdvancedWebServer/defines.h#L10-L580 +https://github.com/khoih-prog/EthernetWebServer/blob/537e3d08f3b002cb3953ae609ee8c4f94c36a89a/examples/AdvancedWebServer/defines.h#L10-L580 --- --- @@ -1466,12 +1482,12 @@ https://github.com/khoih-prog/EthernetWebServer/blob/45cff39b1556be463698a4f632f The following are debug terminal output and screen shot when running example [AdvancedWebServer](examples/AdvancedWebServer) on Adafruit NRF52840_FEATHER_EXPRESS with ENC28J60 using EthernetENC Library

- +

``` Starting AdvancedWebServer on NRF52840_FEATHER with ENC28J60 using EthernetENC Library -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] ========================= [EWS] Default SPI pinout: [EWS] MOSI: 25 @@ -1652,7 +1668,7 @@ The terminal output of **SAM DUE with W5x00 using Ethernet_Generic Library** run ``` Starting SimpleWebSocket on SAM DUE with W5x00 using Ethernet_Generic Library -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 75 @@ -1743,7 +1759,7 @@ The terminal output of **NRF52840_FEATHER with W5x00 using Ethernet_Generic Libr ``` Starting DweetPost on NRF52840_FEATHER with W5x00 using Ethernet_Generic Library -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 25 @@ -1777,7 +1793,7 @@ The terminal output of **ESP32 with W5x00 using Ethernet_Generic Library** runni ``` Starting ESP32_FS_EthernetWebServer on ESP32 using LittleFS With W5x00 using Ethernet_Generic Library on SPI -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 23 @@ -1812,7 +1828,7 @@ handleFileRead: /favicon.ico and the screen shot of the WebServer

- +

--- @@ -1825,7 +1841,7 @@ The terminal output of **ESP8266 with W5x00 using Ethernet_Generic Library** run ``` Starting FS_EthernetWebServer on ESP8266 using LittleFS With W5x00 using Ethernet_Generic Library -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 13 @@ -1866,7 +1882,7 @@ handleFileRead: /favicon.ico and the screen shot of the WebServer

- +

--- @@ -1878,7 +1894,7 @@ The terminal output of **ESP8266 with W5x00 using Ethernet_Generic Library** run ``` Starting serveStatic demoing 'serveStatic' function on ESP8266 using LittleFS With W5x00 using Ethernet_Generic Library -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 13 @@ -1901,7 +1917,7 @@ HTTP server started and the screen shot of the WebServer

- +

--- @@ -1912,13 +1928,13 @@ and the screen shot of the WebServer The following are debug terminal output and screen shot when running example [SimpleWebServer_NativeEthernet](examples/SimpleWebServer_NativeEthernet) on **Teensy 4.1 with NativeEthernet library**

- +

``` SimpleWebServer_NativeEthernet on Teensy 4.1 with NativeEthernet -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 Debug Level = 3 Connected! IP address: 192.168.2.127 [EWS] AdvancedWebServer Teensy 4.1 with NativeEthernet

Hi from EthernetWebServer!

on Teensy 4.1 with NativeEthernet

Uptime: 0 d 00:00:05

@@ -1969,12 +1985,12 @@ Connected! IP address: 192.168.2.127 The following are debug terminal output and screen shot when running example [AdvancedWebServer](examples/AdvancedWebServer) on **RASPBERRY_PI_PICO** with W5x00 using Ethernet_Generic Library and [**Arduino-mbed RP2040** core](https://github.com/arduino/ArduinoCore-mbed)

- +

``` Starting AdvancedWebServer on MBED RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 19 @@ -2006,7 +2022,7 @@ The following are debug terminal output when running example [MQTTClient_Auth](e ``` Start MQTTClient_Auth on MBED RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 19 @@ -2036,12 +2052,12 @@ Message arrived [MQTT_Pub] Hello from MQTTClient_Auth on MBED RASPBERRY_PI_PICO The following are debug terminal output and screen shot when running example [AdvancedWebServer](examples/AdvancedWebServer) on **RASPBERRY_PI_PICO** with W5x00 using Ethernet_Generic Library and [**Earle Philhower's arduino-pico core**](https://github.com/earlephilhower/arduino-pico)

- +

``` Starting AdvancedWebServer on RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 19 @@ -2072,7 +2088,7 @@ The following are debug terminal output and screen shot when running example [Ud ``` Start UdpNTPClient on RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 19 @@ -2109,12 +2125,12 @@ The UTC time is 1:51:06 The following are debug terminal output and screen shot when running example [AdvancedWebServer](examples/QNEthernet/AdvancedWebServer) on **Teensy 4.1** using NativeEthernet Library

- +

``` Starting AdvancedWebServer on TEENSY 4.1 using QNEthernet -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_QN_ETHERNET =========== Initialize Ethernet using static IP => IP Address = 192.168.2.222 HTTP EthernetWebServer is @ IP : 192.168.2.222 @@ -2131,12 +2147,12 @@ HTTP EthernetWebServer is @ IP : 192.168.2.222 The following are debug terminal output and screen shot when running example [AdvancedWebServer](examples/QNEthernet/AdvancedWebServer) on **Teensy 4.1** using QNEthernet Library

- +

``` Starting AdvancedWebServer on TEENSY 4.1 using QNEthernet -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_QN_ETHERNET =========== Initialize Ethernet using static IP => IP Address = 192.168.2.222 HTTP EthernetWebServer is @ IP : 192.168.2.222 @@ -2154,7 +2170,7 @@ The following is the debug terminal output when running example [MQTTClient_Auth ``` Start MQTTClient_Auth on TEENSY 4.1 using QNEthernet -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_QN_ETHERNET =========== Initialize Ethernet using static IP => IP Address = 192.168.2.222 Attempting MQTT connection to broker.emqx.io...connected @@ -2172,12 +2188,12 @@ Message arrived [MQTT_Pub] Hello from MQTTClient_Auth on TEENSY 4.1 using QNEthe The following are debug terminal output and screen shot when running example [AdvancedWebServer](examples/AdvancedWebServer) on **PORTENTA_H7_M7** with Ethernet using Portenta_Ethernet Library

- +

``` Starting AdvancedWebServer on PORTENTA_H7_M7 with Ethernet using Portenta_Ethernet Library -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] ======== USE_PORTENTA_H7_ETHERNET ======== Using mac index = 6 Connected! IP address: 192.168.2.222 @@ -2196,7 +2212,7 @@ The following is the debug terminal output when running example [MQTTClient_Auth ``` Starting SimpleWebSocket on PORTENTA_H7_M7 with Ethernet using Portenta_Ethernet Library -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] ======== USE_PORTENTA_H7_ETHERNET ======== Using mac index = 4 Connected! IP address: 192.168.2.132 @@ -2244,7 +2260,7 @@ The following is the debug terminal output when running example [MQTTClient_Auth ``` Start MQTTClient_Auth on PORTENTA_H7_M7 with Ethernet using Portenta_Ethernet Library -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] ======== USE_PORTENTA_H7_ETHERNET ======== Using mac index = 7 Connected! IP address: 192.168.2.132 @@ -2319,12 +2335,12 @@ HTTP WiFiWebServer is @ IP : 192.168.2.109 The following are debug terminal output and screen shot when running example [AdvancedWebServer_ESP32_SPI2](examples/AdvancedWebServer_ESP32_SPI2) on ESP32_DEV with W5500 using Ethernet_Generic Library on SPI2

- +

``` Starting AdvancedWebServer_ESP32_SPI2 on ESP32_DEV with W5x00 using Ethernet_Generic Library on SPI2 -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 ========================= Currently Used SPI pinout: MOSI:13 @@ -2347,13 +2363,13 @@ HTTP EthernetWebServer is @ IP : 192.168.2.102 The following are debug terminal output and screen shot when running example [AdvancedWebServer](examples/AdvancedWebServer) on RASPBERRY_PI_PICO with W5500 using Ethernet_Generic Library on SPI1 and [arduino-pico core](https://github.com/earlephilhower/arduino-pico)

- +

``` Starting AdvancedWebServer on RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library on SPI1 -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 15 @@ -2384,13 +2400,13 @@ HTTP EthernetWebServer is @ IP : 192.168.2.104 The following are debug terminal output and screen shot when running example [AdvancedWebServer_RP2040_SPI1](examples/AdvancedWebServer_RP2040_SPI1) on **MBED RASPBERRY_PI_PICO** with W5500 using Ethernet_Generic Library on `SPI1` and [ArduinoCore-mbed](https://github.com/arduino/ArduinoCore-mbed)

- +

``` Starting AdvancedWebServer_RP2040_SPI1 on MBED RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library with Large Buffer -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 15 @@ -2419,16 +2435,16 @@ HTTP EthernetWebServer is @ IP : 192.168.2.97 The following are debug terminal output and screen shot when running example [AdvancedWebServer_Teensy4x_SPI1](examples/AdvancedWebServer_Teensy4x_SPI1) on **Teensy 4.1** with W5500 using Ethernet_Generic Library on SPI1

- +

- +

``` Starting AdvancedWebServer_Teensy4x_SPI1 on TEENSY 4.1 with W5x00 using Ethernet_Generic Library with Large Buffer -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 26 @@ -2459,13 +2475,13 @@ HTTP EthernetWebServer is @ IP : 192.168.2.101 The following are debug terminal output and screen shot when running example [AdvancedWebServer](examples/AdvancedWebServer) on **Curiosity AVR_AVR128DA48** with W5500 using Ethernet_Generic Library on SPI

- +

``` Starting AdvancedWebServer on Curiosity AVR_AVR128DA48 with W5x00 using Ethernet_Generic Library on SPI0/SPI -EthernetWebServer v2.2.4 +EthernetWebServer v2.3.0 [EWS] =========== USE_ETHERNET_GENERIC =========== [EWS] Default SPI pinout: [EWS] MOSI: 4 @@ -2492,6 +2508,106 @@ HTTP EthernetWebServer is @ IP : 192.168.2.105 ``` +--- + +#### 26. [EthernetWebServer_BigData](examples/EthernetWebServer_BigData) on NRF52840_FEATHER + +The following is debug terminal output when running example [EthernetWebServer_BigData](examples/EthernetWebServer_BigData) on `NRF52840_FEATHER` board, using W5500 Ethernet with [Ethernet_Generic Library](https://github.com/khoih-prog/Ethernet_Generic), to demo how to send much larger data than total 8K + +##### MULTIPLY_FACTOR = 3.0f + +``` +Start EthernetWebServer_BigData on NRF52840_FEATHER with W5x00 using Ethernet_Generic Library on SPI0/SPI +EthernetWebServer v2.3.0 +[ETG] W5100 init, using W5100Class::ss_pin = 5 , whereas new ss_pin = 10 , SS_PIN_DEFAULT = 10 +[ETG] Chip is W5500 +[ETG] W5100::init: W5500, SSIZE = 8192 +Using mac index = 14 +Connected! IP address: 192.168.2.135 +String Len = 23712 +[ETG] EthernetClient::write: To write, size = 86 +[ETG] EthernetClient::write: written = 86 , totalBytesSent = 86 +[ETG] EthernetClient::write: Done, written = 86 , totalBytesSent = 86 +[ETG] EthernetClient::write: To write, size = 23712 +[ETG] EthernetClient::write: written = 8192 , totalBytesSent = 8192 +[ETG] EthernetClient::write: Partially Done, written = 8192 , bytesRemaining = 15520 +[ETG] EthernetClient::write: written = 8192 , totalBytesSent = 16384 +[ETG] EthernetClient::write: Partially Done, written = 8192 , bytesRemaining = 7328 +[ETG] EthernetClient::write: written = 7328 , totalBytesSent = 23712 +[ETG] EthernetClient::write: Done, written = 7328 , totalBytesSent = 23712 +[ETG] EthernetClient::write: To write, size = 91 +[ETG] EthernetClient::write: written = 91 , totalBytesSent = 91 +[ETG] EthernetClient::write: Done, written = 91 , totalBytesSent = 91 +[ETG] EthernetClient::write: To write, size = 59 +[ETG] EthernetClient::write: written = 59 , totalBytesSent = 59 +[ETG] EthernetClient::write: Done, written = 59 , totalBytesSent = 59 +String Len = 23712 +[ETG] EthernetClient::write: To write, size = 86 +[ETG] EthernetClient::write: written = 86 , totalBytesSent = 86 +[ETG] EthernetClient::write: Done, written = 86 , totalBytesSent = 86 +[ETG] EthernetClient::write: To write, size = 23712 +[ETG] EthernetClient::write: written = 8192 , totalBytesSent = 8192 +[ETG] EthernetClient::write: Partially Done, written = 8192 , bytesRemaining = 15520 +[ETG] EthernetClient::write: written = 8192 , totalBytesSent = 16384 +[ETG] EthernetClient::write: Partially Done, written = 8192 , bytesRemaining = 7328 +[ETG] EthernetClient::write: written = 7328 , totalBytesSent = 23712 +[ETG] EthernetClient::write: Done, written = 7328 , totalBytesSent = 23712 +``` + +--- + +#### 27. [EthernetWebServer_BigData](examples/EthernetWebServer_BigData) on RASPBERRY_PI_PICO + +The following is debug terminal output when running example [EthernetWebServer_BigData](examples/EthernetWebServer_BigData) on `RASPBERRY_PI_PICO` board, using W5500 Ethernet with [Ethernet_Generic Library](https://github.com/khoih-prog/Ethernet_Generic), to demo how to send much larger data than total 8K + +##### MULTIPLY_FACTOR = 3.0f + + +``` +Start EthernetWebServer_BigData on RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library on SPI0/SPI +EthernetWebServer v2.3.0 +[ETG] W5100 init, using W5100Class::ss_pin = 17 , whereas new ss_pin = 10 , SS_PIN_DEFAULT = 17 +[ETG] Chip is W5100S +[ETG] W5100::init: W5100S, SSIZE = 4096 +Using mac index = 7 +Connected! IP address: 192.168.2.111 +String Len = 23714 +[ETG] EthernetClient::write: To write, size = 86 +[ETG] EthernetClient::write: written = 86 , totalBytesSent = 86 +[ETG] EthernetClient::write: Done, written = 86 , totalBytesSent = 86 +[ETG] EthernetClient::write: To write, size = 23714 +[ETG] EthernetClient::write: written = 4096 , totalBytesSent = 4096 +[ETG] EthernetClient::write: Partially Done, written = 4096 , bytesRemaining = 19618 +[ETG] EthernetClient::write: written = 4096 , totalBytesSent = 8192 +[ETG] EthernetClient::write: Partially Done, written = 4096 , bytesRemaining = 15522 +[ETG] EthernetClient::write: written = 4096 , totalBytesSent = 12288 +[ETG] EthernetClient::write: Partially Done, written = 4096 , bytesRemaining = 11426 +[ETG] EthernetClient::write: written = 4096 , totalBytesSent = 16384 +[ETG] EthernetClient::write: Partially Done, written = 4096 , bytesRemaining = 7330 +[ETG] EthernetClient::write: written = 4096 , totalBytesSent = 20480 +[ETG] EthernetClient::write: Partially Done, written = 4096 , bytesRemaining = 3234 +[ETG] EthernetClient::write: written = 3234 , totalBytesSent = 23714 +[ETG] EthernetClient::write: Done, written = 3234 , totalBytesSent = 23714 +String Len = 23714 +[ETG] EthernetClient::write: To write, size = 86 +[ETG] EthernetClient::write: written = 86 , totalBytesSent = 86 +[ETG] EthernetClient::write: Done, written = 86 , totalBytesSent = 86 +[ETG] EthernetClient::write: To write, size = 23714 +[ETG] EthernetClient::write: written = 4096 , totalBytesSent = 4096 +[ETG] EthernetClient::write: Partially Done, written = 4096 , bytesRemaining = 19618 +[ETG] EthernetClient::write: written = 4096 , totalBytesSent = 8192 +[ETG] EthernetClient::write: Partially Done, written = 4096 , bytesRemaining = 15522 +[ETG] EthernetClient::write: written = 4096 , totalBytesSent = 12288 +[ETG] EthernetClient::write: Partially Done, written = 4096 , bytesRemaining = 11426 +[ETG] EthernetClient::write: written = 4096 , totalBytesSent = 16384 +[ETG] EthernetClient::write: Partially Done, written = 4096 , bytesRemaining = 7330 +[ETG] EthernetClient::write: written = 4096 , totalBytesSent = 20480 +[ETG] EthernetClient::write: Partially Done, written = 4096 , bytesRemaining = 3234 +[ETG] EthernetClient::write: written = 3234 , totalBytesSent = 23714 +[ETG] EthernetClient::write: Done, written = 3234 , totalBytesSent = 23714 +``` + + --- --- @@ -2571,6 +2687,10 @@ Submit issues to: [EthernetWebServer issues](https://github.com/khoih-prog/Ether 37. Add support to Seeeduino nRF52840-based boards such as **SEEED_XIAO_NRF52840 and SEEED_XIAO_NRF52840_SENSE**, etc. using Seeed `mbed` or `nRF52` core 38. Add astyle using `allman` style. Restyle the library 39. Update `Packages' Patches` to add Seeeduino `nRF52` core +40. Add examples [EthernetWebServer_BigData](https://github.com/khoih-prog/EthernetWebServer/tree/master/examples/EthernetWebServer_BigData) to demo how to send larger data than **2/4/8/16K** buffer +41. Modify example [AdvancedWebServer](https://github.com/khoih-prog/EthernetWebServer/tree/master/examples/AdvancedWebServer) to demo how to send larger data than `2/4/8/16K` buffer + + --- --- @@ -2632,6 +2752,6 @@ If you want to contribute to this project: ## Copyright -Copyright 2020- Khoi Hoang +Copyright (C) 2020- Khoi Hoang diff --git a/changelog.md b/changelog.md index f7351c49..47618f24 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,11 @@ [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/EthernetWebServer.svg)](http://github.com/khoih-prog/EthernetWebServer/issues) +Donate to my libraries using BuyMeACoffee + + + + --- --- @@ -13,6 +18,7 @@ * [Changelog](#changelog) + * [Releases v2.3.0](#releases-v230) * [Releases v2.2.4](#releases-v224) * [Releases v2.2.3](#releases-v223) * [Releases v2.2.2](#releases-v222) @@ -58,6 +64,14 @@ ## Changelog +### Releases v2.3.0 + +1. Add new features, such as `CORS`, etc. +2. Add example [EthernetWebServer_BigData](https://github.com/khoih-prog/EthernetWebServer/tree/master/examples/EthernetWebServer_BigData) to demo how to send larger data than `2/4/8/16K` buffer +3. Modify example [AdvancedWebServer](https://github.com/khoih-prog/EthernetWebServer/tree/master/examples/AdvancedWebServer) to demo how to send larger data than `2/4/8/16K` buffer +4. Update code +5. Update `Packages' Patches` + ### Releases v2.2.4 1. Add support to Seeeduino nRF52840-based boards such as **Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE**, etc. using Seeed `mbed` or `nRF52` core diff --git a/library.json b/library.json index 28d57c72..280d51fd 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "EthernetWebServer", - "version": "2.2.4", + "version": "2.3.0", "keywords": "WebServer, Ethernet, Ethernet2, Ethernet3, EthernetLarge, EthernetENC, UIPEthernet, NativeEthernet, QNEthernet, Portenta-H7, Teensy, SAMD21, SAMD51, SAM DUE, nRF52, ESP32, ESP8266, rpi-pico, rp2040, W5x00, W5500, ENC28J60, HTTP-Client, WebSocket-Client, server, client, websocket, LittleFS, SPIFFS, Arduino, Mega, AVR, AVR-Dx", "description": "Simple Ethernet WebServer, HTTP Client and WebSocket Client library for AVR, AVR Dx, Portenta_H7, Teensy, SAM DUE, SAMD21, SAMD51, ESP, nRF52, ESP32, ESP8266 and RASPBERRY_PI_PICO boards using Ethernet shields W5100, W5200, W5500, ENC28J60 or Teensy 4.1 NativeEthernet/QNEthernet. The WebServer supports HTTP GET and POST requests, provides argument parsing, handles one client at a time. It now provides HTTP Client and WebSocket Client. It supports Arduino boards (Atmel AVR-s, AVR-Dx, SAM DUE, Atmel SAM3X8E ARM Cortex-M3, SAMD21, SAMD51, ESP8266, ESP32, Adafruit nRF52, Teensy boards, Realtek Ameba(RTL8195A,RTL8710)) using Wiznet W5x00 or ENC28J60 network shields. It now supports WebServer serving from LittleFS/SPIFFS for ESP8266/ESP32. Ethernet_Generic library is used as default for W5x00 with custom SPI.", "authors": @@ -32,12 +32,12 @@ { "owner": "khoih-prog", "name": "Ethernet_Generic", - "version": "^2.6.0" + "version": "^2.7.0" }, { "owner": "ssilverman", "name": "QNEthernet", - "version": ">=0.15.0", + "version": ">=0.16.0", "platforms": ["teensy"] } ], diff --git a/library.properties b/library.properties index 9687a252..df420e6f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=EthernetWebServer -version=2.2.4 +version=2.3.0 author=Khoi Hoang license=MIT maintainer=Khoi Hoang diff --git a/platformio/platformio.ini b/platformio/platformio.ini index 835473ce..a958868f 100644 --- a/platformio/platformio.ini +++ b/platformio/platformio.ini @@ -49,17 +49,17 @@ lib_ldf_mode = chain+ lib_deps = ; PlatformIO 4.x ; Functional-Vlpp@~1.0.2 -; Ethernet_Generic@>=2.6.2 +; Ethernet_Generic@>=2.7.0 ; EthernetENC@~2.0.3 ; UIPEthernet@~2.0.12 -; QNEthernet@>=0.15.0 +; QNEthernet@>=0.16.0 ; PlatformIO 5.x khoih-prog/Functional-Vlpp@~1.0.2 - khoih-prog/Ethernet_Generic@~2.6.2 + khoih-prog/Ethernet_Generic@~2.7.0 jandrassy/EthernetENC@~2.0.3 uipethernet/UIPEthernet@~2.0.12 - ssilverman/QNEthernet@>=0.15.0 + ssilverman/QNEthernet@>=0.16.0 build_flags = ; set your debug output (default=Serial) diff --git a/src/EthernetHttpClient.h b/src/EthernetHttpClient.h index 92a18046..9cd3bc5e 100644 --- a/src/EthernetHttpClient.h +++ b/src/EthernetHttpClient.h @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ // Library to simplify HTTP fetching on Arduino diff --git a/src/EthernetWebServer-impl.h b/src/EthernetWebServer-impl.h index 2a0d0e72..4c8c36b9 100644 --- a/src/EthernetWebServer-impl.h +++ b/src/EthernetWebServer-impl.h @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ #pragma once @@ -48,39 +49,40 @@ const char * ETHERNET_AUTHORIZATION_HEADER = "Authorization"; // New to use EWString -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// EWString fromString(const String& str) { return str.c_str(); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// EWString fromString(const String&& str) { return str.c_str(); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// String fromEWString(const EWString& str) { return str.c_str(); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// String fromEWString(const EWString&& str) { return str.c_str(); } -///////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// +//////////////////////////////////////// EthernetWebServer::EthernetWebServer(int port) - : _server(port) + : _corsEnabled(false) + , _server(port) , _currentMethod(HTTP_ANY) , _currentVersion(0) , _currentHandler(0) @@ -91,11 +93,12 @@ EthernetWebServer::EthernetWebServer(int port) , _headerKeysCount(0) , _currentHeaders(0) , _contentLength(0) + , _clientContentLength(0) , _chunked(false) { } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// EthernetWebServer::~EthernetWebServer() { @@ -115,7 +118,7 @@ EthernetWebServer::~EthernetWebServer() close(); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::begin() { @@ -126,7 +129,7 @@ void EthernetWebServer::begin() collectHeaders(0, 0); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// bool EthernetWebServer::authenticate(const char * username, const char * password) { @@ -153,6 +156,7 @@ bool EthernetWebServer::authenticate(const char * username, const char * passwor { authReq = String(); delete[] toencode; + return false; } @@ -163,6 +167,7 @@ bool EthernetWebServer::authenticate(const char * username, const char * passwor authReq = String(); delete[] toencode; delete[] encoded; + return true; } @@ -176,7 +181,7 @@ bool EthernetWebServer::authenticate(const char * username, const char * passwor return false; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::requestAuthentication() { @@ -184,21 +189,21 @@ void EthernetWebServer::requestAuthentication() send(401); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::on(const String &uri, EthernetWebServer::THandlerFunction handler) { on(uri, HTTP_ANY, handler); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::on(const String &uri, HTTPMethod method, EthernetWebServer::THandlerFunction fn) { on(uri, method, fn, _fileUploadHandler); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::on(const String &uri, HTTPMethod method, EthernetWebServer::THandlerFunction fn, EthernetWebServer::THandlerFunction ufn) @@ -206,14 +211,14 @@ void EthernetWebServer::on(const String &uri, HTTPMethod method, EthernetWebServ _addRequestHandler(new ethernetFunctionRequestHandler(fn, ufn, uri, method)); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::addHandler(ethernetRequestHandler* handler) { _addRequestHandler(handler); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::_addRequestHandler(ethernetRequestHandler* handler) { @@ -229,12 +234,12 @@ void EthernetWebServer::_addRequestHandler(ethernetRequestHandler* handler) } } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// //KH #if USE_NEW_WEBSERVER_VERSION -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::handleClient() { @@ -244,7 +249,6 @@ void EthernetWebServer::handleClient() if (!client) { - //ET_LOGDEBUG(F("handleClient: No Client")); return; } @@ -277,12 +281,17 @@ void EthernetWebServer::handleClient() _contentLength = CONTENT_LENGTH_NOT_SET; _handleRequest(); +#if 0 + + // Fix for issue with Chrome based browsers: https://github.com/espressif/arduino-esp32/issues/3652 if (_currentClient.connected()) { _currentStatus = HC_WAIT_CLOSE; _statusChange = millis(); keepCurrentClient = true; } + +#endif } } else @@ -328,11 +337,11 @@ void EthernetWebServer::handleClient() //ET_LOGDEBUG(F("handleClient: Client disconnected")); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// #else // USE_NEW_WEBSERVER_VERSION -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// // KH, rewritten for Portenta H7 from v1.7.0 @@ -368,12 +377,8 @@ void EthernetWebServer::handleClient() // Wait for data from client to become available if (_currentStatus == HC_WAIT_READ) { - //ET_LOGDEBUG(F("handleClient: _currentStatus = HC_WAIT_READ")); - if (!_currentClient.available()) { - //ET_LOGDEBUG(F("handleClient: Client not available")); - if (millis() - _statusChange > HTTP_MAX_DATA_WAIT) { ET_LOGDEBUG(F("handleClient: HTTP_MAX_DATA_WAIT Timeout")); @@ -385,6 +390,7 @@ void EthernetWebServer::handleClient() } yield(); + return; } @@ -421,6 +427,7 @@ void EthernetWebServer::handleClient() { _currentStatus = HC_WAIT_CLOSE; _statusChange = millis(); + return; } } @@ -439,6 +446,7 @@ void EthernetWebServer::handleClient() else { yield(); + return; } } @@ -450,26 +458,34 @@ void EthernetWebServer::handleClient() ET_LOGDEBUG(F("handleClient: Client disconnected")); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// #endif // USE_NEW_WEBSERVER_VERSION -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::close() { // TODO: Write close method for Ethernet library and uncomment this //_server.close(); + + // KH, New v2.3.0 + _currentStatus = HC_NONE; + + if (!_headerKeysCount) + collectHeaders(0, 0); + + ////// } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::stop() { close(); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::sendHeader(const String& name, const String& value, bool first) { @@ -489,14 +505,14 @@ void EthernetWebServer::sendHeader(const String& name, const String& value, bool } } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::setContentLength(size_t contentLength) { _contentLength = contentLength; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::_prepareHeader(String& response, int code, const char* content_type, size_t contentLength) { @@ -534,6 +550,13 @@ void EthernetWebServer::_prepareHeader(String& response, int code, const char* c sendHeader("Transfer-Encoding", "chunked"); } + if (_corsEnabled) + { + sendHeader("Access-Control-Allow-Origin", "*"); + sendHeader("Access-Control-Allow-Methods", "*"); + sendHeader("Access-Control-Allow-Headers", "*"); + } + ET_LOGDEBUG(F("_prepareHeader sendHeader Conn close")); sendHeader("Connection", "close"); @@ -546,7 +569,7 @@ void EthernetWebServer::_prepareHeader(String& response, int code, const char* c _responseHeaders = String(""); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// #if ! ( ETHERNET_USE_AVR_MEGA || ETHERNET_USE_MEGA_AVR || ETHERNET_USE_DXCORE ) void EthernetWebServer::_prepareHeader(EWString& response, int code, const char* content_type, size_t contentLength) @@ -557,7 +580,7 @@ void EthernetWebServer::_prepareHeader(EWString& response, int code, const char* response += fromString(_responseCodeToString(code)); response += RETURN_NEWLINE; - ET_LOGDEBUG1(F("_prepareHeader response ="), fromEWString(response)); + //ET_LOGDEBUG1(F("_prepareHeader response ="), fromEWString(response)); using namespace mime; @@ -583,6 +606,13 @@ void EthernetWebServer::_prepareHeader(EWString& response, int code, const char* sendHeader("Transfer-Encoding", "chunked"); } + if (_corsEnabled) + { + sendHeader("Access-Control-Allow-Origin", "*"); + sendHeader("Access-Control-Allow-Methods", "*"); + sendHeader("Access-Control-Allow-Headers", "*"); + } + ET_LOGDEBUG(F("_prepareHeader sendHeader Conn close")); sendHeader("Connection", "close"); @@ -594,48 +624,33 @@ void EthernetWebServer::_prepareHeader(EWString& response, int code, const char* } #endif -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::send(int code, const char* content_type, const String& content) { EWString header; - // Can we asume the following? - //if(code == 200 && content.length() == 0 && _contentLength == CONTENT_LENGTH_NOT_SET) - // _contentLength = CONTENT_LENGTH_UNKNOWN; - - ET_LOGDEBUG1(F("send1: len = "), content.length()); - ET_LOGDEBUG1(F("content = "), content); - _prepareHeader(header, code, content_type, content.length()); _currentClient.write((const uint8_t *)header.c_str(), header.length()); if (content.length()) { - ET_LOGDEBUG1(F("send1: write header = "), fromEWString(header)); - //sendContent(content); sendContent(content, content.length()); } } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::send(int code, char* content_type, const String& content, size_t contentLength) { EWString header; - ET_LOGDEBUG1(F("send2: len = "), contentLength); - ET_LOGDEBUG1(F("content = "), content); - char type[64]; memccpy((void*)type, content_type, 0, sizeof(type)); _prepareHeader(header, code, (const char* )type, contentLength); - ET_LOGDEBUG1(F("send2: hdrlen = "), header.length()); - ET_LOGDEBUG1(F("header = "), fromEWString(header)); - _currentClient.write((const uint8_t *) header.c_str(), header.length()); if (contentLength) @@ -644,78 +659,89 @@ void EthernetWebServer::send(int code, char* content_type, const String& content } } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::send(int code, char* content_type, const String& content) { send(code, (const char*)content_type, content); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::send(int code, const String& content_type, const String& content) { send(code, (const char*)content_type.c_str(), content); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// -void EthernetWebServer::sendContent(const String& content) +// KH New + +void EthernetWebServer::send(int code, const char* content_type, const char* content) { - const char * footer = RETURN_NEWLINE; - size_t len = content.length(); + send(code, content_type, content, content ? strlen(content) : 0); +} - if (_chunked) - { - char * chunkSize = (char *) malloc(11); +//////////////////////////////////////// - if (chunkSize) - { - sprintf(chunkSize, "%x%s", len, footer); - _currentClient.write(chunkSize, strlen(chunkSize)); - free(chunkSize); - } - } +void EthernetWebServer::send(int code, const char* content_type, const char* content, size_t contentLength) +{ + String header; - _currentClient.write(content.c_str(), len); + _prepareHeader(header, code, content_type, contentLength); - if (_chunked) + _currentClient.write((const uint8_t *) header.c_str(), header.length()); + + if (contentLength) { - _currentClient.write(footer, 2); + sendContent(content, contentLength); } } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// -void EthernetWebServer::sendContent(const String& content, size_t size) +void EthernetWebServer::sendContent(const char* content, size_t contentLength) { const char * footer = RETURN_NEWLINE; if (_chunked) { - char * chunkSize = (char *) malloc(11); + char chunkSize[11]; - if (chunkSize) - { - ET_LOGDEBUG(F("sendContent: _chunked")); + ET_LOGDEBUG1(F("sendContent_char: _chunked, _currentVersion ="), _currentVersion); - sprintf(chunkSize, "%x%s", size, footer); - _currentClient.write(chunkSize, strlen(chunkSize)); - free(chunkSize); - } + sprintf(chunkSize, "%x%s", contentLength, footer); + _currentClient.write(chunkSize, strlen(chunkSize)); } - ET_LOGDEBUG1(F("sendContent: Client.write content: "), content); - - _currentClient.write(content.c_str(), size); + _currentClient.write(content, contentLength); if (_chunked) { _currentClient.write(footer, 2); + + if (contentLength == 0) + { + _chunked = false; + } } } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// + +void EthernetWebServer::sendContent(const String& content) +{ + sendContent(content.c_str(), content.length()); +} + +//////////////////////////////////////// + +void EthernetWebServer::sendContent(const String& content, size_t contentLength) +{ + sendContent(content.c_str(), contentLength); +} + +//////////////////////////////////////// // KH, Restore PROGMEM commands void EthernetWebServer::send_P(int code, PGM_P content_type, PGM_P content) @@ -746,7 +772,7 @@ void EthernetWebServer::send_P(int code, PGM_P content_type, PGM_P content) } } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength) { @@ -770,74 +796,81 @@ void EthernetWebServer::send_P(int code, PGM_P content_type, PGM_P content, size } } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::sendContent_P(PGM_P content) { sendContent_P(content, strlen_P(content)); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// -void EthernetWebServer::sendContent_P(PGM_P content, size_t size) +void EthernetWebServer::sendContent_P(PGM_P content, size_t contentLength) { const char * footer = RETURN_NEWLINE; if (_chunked) { - char * chunkSize = (char *) malloc(11); + char chunkSize[11]; - if (chunkSize) - { - sprintf(chunkSize, "%x%s", size, footer); - _currentClient.write(chunkSize, strlen(chunkSize)); - free(chunkSize); - } + ET_LOGDEBUG1(F("sendContent_P: _chunked, _currentVersion ="), _currentVersion); + + sprintf(chunkSize, "%x%s", contentLength, footer); + _currentClient.write(chunkSize, strlen(chunkSize)); } - uint8_t* buffer = new uint8_t[SENDCONTENT_P_BUFFER_SZ]; + uint8_t* _sendContentBuffer = new uint8_t[SENDCONTENT_P_BUFFER_SZ]; - if (buffer) + if (_sendContentBuffer) { - uint16_t count = size / SENDCONTENT_P_BUFFER_SZ; - uint16_t remainder = size % SENDCONTENT_P_BUFFER_SZ; + uint16_t count = contentLength / SENDCONTENT_P_BUFFER_SZ; + uint16_t remainder = contentLength % SENDCONTENT_P_BUFFER_SZ; uint16_t i = 0; for (i = 0; i < count; i++) { /* code */ - memcpy_P(buffer, &content[i * SENDCONTENT_P_BUFFER_SZ], SENDCONTENT_P_BUFFER_SZ); - _currentClient.write(buffer, SENDCONTENT_P_BUFFER_SZ); + memcpy_P(_sendContentBuffer, &content[i * SENDCONTENT_P_BUFFER_SZ], SENDCONTENT_P_BUFFER_SZ); + _currentClient.write(_sendContentBuffer, SENDCONTENT_P_BUFFER_SZ); } - memcpy_P(buffer, &content[i * SENDCONTENT_P_BUFFER_SZ], remainder); - _currentClient.write(buffer, remainder); + memcpy_P(_sendContentBuffer, &content[i * SENDCONTENT_P_BUFFER_SZ], remainder); + _currentClient.write(_sendContentBuffer, remainder); - delete [] buffer; + delete [] _sendContentBuffer; } else { - ET_LOGERROR1(F("sendContent_P: Error, can't allocate buffer, Sz ="), SENDCONTENT_P_BUFFER_SZ); + ET_LOGERROR1(F("sendContent_P: Error, can't allocate _sendContentBuffer, Sz ="), SENDCONTENT_P_BUFFER_SZ); + return; } if (_chunked) { _currentClient.write(footer, 2); + + _chunked = false; } } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// #if (defined(ESP32) || defined(ESP8266)) #include "FS.h" + +//////////////////////////////////////// + void EthernetWebServer::serveStatic(const char* uri, FS& fs, const char* path, const char* cache_header) { _addRequestHandler(new StaticFileRequestHandler(fs, path, uri, cache_header)); } -void EthernetWebServer::_streamFileCore(const size_t fileSize, const String &fileName, const String &contentType) +//////////////////////////////////////// + +void EthernetWebServer::_streamFileCore(const size_t fileSize, const String &fileName, const String &contentType, + const int code) { using namespace mime; @@ -850,11 +883,11 @@ void EthernetWebServer::_streamFileCore(const size_t fileSize, const String &fil sendHeader(F("Content-Encoding"), F("gzip")); } - send(200, contentType, emptyString); + send(code, contentType, emptyString); } #endif -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// String EthernetWebServer::arg(const String& name) { @@ -867,7 +900,7 @@ String EthernetWebServer::arg(const String& name) return String(); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// String EthernetWebServer::arg(int i) { @@ -877,7 +910,7 @@ String EthernetWebServer::arg(int i) return String(); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// String EthernetWebServer::argName(int i) { @@ -887,12 +920,14 @@ String EthernetWebServer::argName(int i) return String(); } +//////////////////////////////////////// + int EthernetWebServer::args() { return _currentArgCount; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// bool EthernetWebServer::hasArg(const String& name) { @@ -905,7 +940,7 @@ bool EthernetWebServer::hasArg(const String& name) return false; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// String EthernetWebServer::header(const String& name) { @@ -918,7 +953,7 @@ String EthernetWebServer::header(const String& name) return String(); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::collectHeaders(const char* headerKeys[], const size_t headerKeysCount) { @@ -936,7 +971,7 @@ void EthernetWebServer::collectHeaders(const char* headerKeys[], const size_t he } } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// String EthernetWebServer::header(int i) { @@ -946,7 +981,7 @@ String EthernetWebServer::header(int i) return String(); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// String EthernetWebServer::headerName(int i) { @@ -956,14 +991,14 @@ String EthernetWebServer::headerName(int i) return String(); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// int EthernetWebServer::headers() { return _headerKeysCount; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// bool EthernetWebServer::hasHeader(const String& name) { @@ -976,28 +1011,28 @@ bool EthernetWebServer::hasHeader(const String& name) return false; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// String EthernetWebServer::hostHeader() { return _hostHeader; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::onFileUpload(THandlerFunction fn) { _fileUploadHandler = fn; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::onNotFound(THandlerFunction fn) { _notFoundHandler = fn; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::_handleRequest() { @@ -1051,7 +1086,7 @@ void EthernetWebServer::_handleRequest() #endif } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::_finalizeResponse() { @@ -1061,7 +1096,7 @@ void EthernetWebServer::_finalizeResponse() } } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// String EthernetWebServer::_responseCodeToString(int code) { @@ -1192,7 +1227,7 @@ String EthernetWebServer::_responseCodeToString(int code) } } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// #endif // ETHERNET_WEBSERVER_IMPL_H diff --git a/src/EthernetWebServer.h b/src/EthernetWebServer.h index a0e44b44..41241339 100644 --- a/src/EthernetWebServer.h +++ b/src/EthernetWebServer.h @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ #pragma once @@ -39,13 +40,13 @@ ///////////////////////////////////////////////////////////////////////// -#define ETHERNET_WEBSERVER_VERSION "EthernetWebServer v2.2.4" +#define ETHERNET_WEBSERVER_VERSION "EthernetWebServer v2.3.0" #define ETHERNET_WEBSERVER_VERSION_MAJOR 2 -#define ETHERNET_WEBSERVER_VERSION_MINOR 2 -#define ETHERNET_WEBSERVER_VERSION_PATCH 4 +#define ETHERNET_WEBSERVER_VERSION_MINOR 3 +#define ETHERNET_WEBSERVER_VERSION_PATCH 0 -#define ETHERNET_WEBSERVER_VERSION_INT 2002004 +#define ETHERNET_WEBSERVER_VERSION_INT 2003000 ///////////////////////////////////////////////////////////////////////// diff --git a/src/EthernetWebServer.hpp b/src/EthernetWebServer.hpp index 1dc0279f..e447993e 100644 --- a/src/EthernetWebServer.hpp +++ b/src/EthernetWebServer.hpp @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ #pragma once @@ -416,15 +417,44 @@ class EthernetWebServer void send(int code, const char* content_type = NULL, const String& content = String("")); void send(int code, char* content_type, const String& content); void send(int code, const String& content_type, const String& content); - //KH - void send(int code, char* content_type, const String& content, size_t contentLength); + void send(int code, char* content_type, const String& content, size_t contentLength); + void send(int code, const char* content_type, const char* content); + void send(int code, const char* content_type, const char* content, size_t contentLength); + + //////////////////////////////////////// + + inline void enableDelay(bool value) + { + _nullDelay = value; + } + + //////////////////////////////////////// + + inline void enableCORS(bool value = true) + { + _corsEnabled = value; + } + + //////////////////////////////////////// + + inline void enableCrossOrigin(bool value = true) + { + enableCORS(value); + } + + //////////////////////////////////////// + void setContentLength(size_t contentLength); void sendHeader(const String& name, const String& value, bool first = false); //void sendHeader(const EWString& name, const EWString& value, bool first = false); void sendContent(const String& content); void sendContent(const String& content, size_t size); + // New + void sendContent(const char* content, size_t contentLength); + ////// + // KH, Restore PROGMEM commands void send_P(int code, PGM_P content_type, PGM_P content); void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength); @@ -451,32 +481,48 @@ class EthernetWebServer return _currentClient.write(file); } + + //////////////////////////////////////// + #else - void serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_header = NULL ); // serve static pages from file system + + //////////////////////////////////////// + + // serve static pages from file system + void serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_header = NULL ); // Handle a GET request by sending a response header and stream file content to response body - template size_t streamFile(T &file, const String& contentType) - { - return streamFile(file, contentType, HTTP_GET); - } + //template + //size_t streamFile(T &file, const String& contentType) + //{ + // return streamFile(file, contentType, HTTP_GET); + //} // Implement GET and HEAD requests for files. // Stream body on HTTP_GET but not on HTTP_HEAD requests. - template size_t streamFile(T &file, const String& contentType, HTTPMethod requestMethod) - { - size_t contentLength = 0; - _streamFileCore(file.size(), file.name(), contentType); - - if (requestMethod == HTTP_GET) + template + size_t streamFile(T &file, const String& contentType, const int code = 200) { - contentLength = _customClientWrite(file); + _streamFileCore(file.size(), file.name(), contentType, code); + + return _currentClient.write(file); } - return contentLength; - } + //////////////////////////////////////// + #endif protected: + + //////////////////////////////////////// + + virtual size_t _currentClientWrite(const char* buffer, size_t length) + { + return _currentClient.write( buffer, length ); + } + + //////////////////////////////////////// + void _addRequestHandler(ethernetRequestHandler* handler); void _handleRequest(); void _finalizeResponse(); @@ -504,7 +550,7 @@ class EthernetWebServer bool _collectHeader(const char* headerName, const char* headerValue); #if (defined(ESP32) || defined(ESP8266)) - void _streamFileCore(const size_t fileSize, const String & fileName, const String & contentType); + void _streamFileCore(const size_t fileSize, const String & fileName, const String & contentType, const int code = 200); template size_t _customClientWrite(T &file) @@ -529,8 +575,10 @@ class EthernetWebServer String key; String value; }; + + bool _corsEnabled; - EthernetServer _server; + EthernetServer _server; EthernetClient _currentClient; HTTPMethod _currentMethod; @@ -538,31 +586,32 @@ class EthernetWebServer uint8_t _currentVersion; HTTPClientStatus _currentStatus; unsigned long _statusChange; + + bool _nullDelay; - ethernetRequestHandler* _currentHandler; - ethernetRequestHandler* _firstHandler; - ethernetRequestHandler* _lastHandler; - THandlerFunction _notFoundHandler; - THandlerFunction _fileUploadHandler; + ethernetRequestHandler* _currentHandler = nullptr; + ethernetRequestHandler* _firstHandler = nullptr; + ethernetRequestHandler* _lastHandler = nullptr; + THandlerFunction _notFoundHandler; + THandlerFunction _fileUploadHandler; int _currentArgCount; - RequestArgument* _currentArgs; + RequestArgument* _currentArgs = nullptr; //KH #if USE_NEW_WEBSERVER_VERSION - ethernetHTTPUpload* _currentUpload; + ethernetHTTPUpload* _currentUpload = nullptr; int _postArgsLen; - RequestArgument* _postArgs; - + RequestArgument* _postArgs = nullptr; #else ethernetHTTPUpload _currentUpload; #endif int _headerKeysCount; - RequestArgument* _currentHeaders; + RequestArgument* _currentHeaders = nullptr; size_t _contentLength; + int _clientContentLength; // "Content-Length" from header of incoming POST or GET request String _responseHeaders; - String _hostHeader; bool _chunked; }; diff --git a/src/Ethernet_HTTPClient/Ethernet_HttpClient.cpp b/src/Ethernet_HTTPClient/Ethernet_HttpClient.cpp index e1b997e8..c4269a0e 100644 --- a/src/Ethernet_HTTPClient/Ethernet_HttpClient.cpp +++ b/src/Ethernet_HTTPClient/Ethernet_HttpClient.cpp @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ // Class to simplify HTTP fetching on Arduino diff --git a/src/Ethernet_HTTPClient/Ethernet_HttpClient.h b/src/Ethernet_HTTPClient/Ethernet_HttpClient.h index f945854f..989228fc 100644 --- a/src/Ethernet_HTTPClient/Ethernet_HttpClient.h +++ b/src/Ethernet_HTTPClient/Ethernet_HttpClient.h @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ // Class to simplify HTTP fetching on Arduino diff --git a/src/Ethernet_HTTPClient/Ethernet_URLEncoder.cpp b/src/Ethernet_HTTPClient/Ethernet_URLEncoder.cpp index 779ca7da..a01a05a1 100644 --- a/src/Ethernet_HTTPClient/Ethernet_URLEncoder.cpp +++ b/src/Ethernet_HTTPClient/Ethernet_URLEncoder.cpp @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ // Library to simplify HTTP fetching on Arduino diff --git a/src/Ethernet_HTTPClient/Ethernet_URLEncoder.h b/src/Ethernet_HTTPClient/Ethernet_URLEncoder.h index 04b4e5d9..56fab585 100644 --- a/src/Ethernet_HTTPClient/Ethernet_URLEncoder.h +++ b/src/Ethernet_HTTPClient/Ethernet_URLEncoder.h @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ // Library to simplify HTTP fetching on Arduino diff --git a/src/Ethernet_HTTPClient/Ethernet_WebSocketClient.cpp b/src/Ethernet_HTTPClient/Ethernet_WebSocketClient.cpp index 2a2023b4..14ad665d 100644 --- a/src/Ethernet_HTTPClient/Ethernet_WebSocketClient.cpp +++ b/src/Ethernet_HTTPClient/Ethernet_WebSocketClient.cpp @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ // (c) Copyright Arduino. 2016 diff --git a/src/Ethernet_HTTPClient/Ethernet_WebSocketClient.h b/src/Ethernet_HTTPClient/Ethernet_WebSocketClient.h index 33250039..ec535a0a 100644 --- a/src/Ethernet_HTTPClient/Ethernet_WebSocketClient.h +++ b/src/Ethernet_HTTPClient/Ethernet_WebSocketClient.h @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ // (c) Copyright Arduino. 2016 diff --git a/src/Parsing-impl.h b/src/Parsing-impl.h index 34e4270c..1b946b05 100644 --- a/src/Parsing-impl.h +++ b/src/Parsing-impl.h @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data **********************************************************************************************************************************/ #pragma once @@ -44,12 +45,12 @@ #define WEBSERVER_MAX_POST_ARGS 32 #endif -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// // KH #if USE_NEW_WEBSERVER_VERSION -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// static bool readBytesWithTimeout(EthernetClient& client, size_t maxLength, String& data, int timeout_ms) { @@ -79,15 +80,15 @@ static bool readBytesWithTimeout(EthernetClient& client, size_t maxLength, Strin return data.length() == maxLength; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// #else -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// #if !(ETHERNET_USE_PORTENTA_H7) -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// static char* readBytesWithTimeout(EthernetClient& client, size_t maxLength, size_t& dataLength, int timeout_ms) { @@ -123,6 +124,7 @@ static char* readBytesWithTimeout(EthernetClient& client, size_t maxLength, size if (!newBuf) { free(buf); + return nullptr; } @@ -139,11 +141,11 @@ static char* readBytesWithTimeout(EthernetClient& client, size_t maxLength, size #endif // #if !(ETHERNET_USE_PORTENTA_H7) -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// #endif // #if USE_NEW_WEBSERVER_VERSION -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// bool EthernetWebServer::_parseRequest(EthernetClient& client) { @@ -165,6 +167,7 @@ bool EthernetWebServer::_parseRequest(EthernetClient& client) if (addr_start == -1 || addr_end == -1) { ET_LOGDEBUG1(F("_parseRequest: Invalid request: "), req); + return false; } @@ -214,7 +217,7 @@ bool EthernetWebServer::_parseRequest(EthernetClient& client) method = HTTP_PATCH; } -#else +#else // #if USE_NEW_WEBSERVER_VERSION if (methodStr == "POST") { @@ -238,7 +241,7 @@ bool EthernetWebServer::_parseRequest(EthernetClient& client) method = HTTP_PATCH; } -#endif +#endif // #if USE_NEW_WEBSERVER_VERSION _currentMethod = method; @@ -271,7 +274,6 @@ bool EthernetWebServer::_parseRequest(EthernetClient& client) #endif bool isForm = false; - uint32_t contentLength = 0; //parse headers @@ -299,7 +301,6 @@ bool EthernetWebServer::_parseRequest(EthernetClient& client) ET_LOGDEBUG1(F("headerName: "), headerName); ET_LOGDEBUG1(F("headerValue: "), headerValue); - //KH if (headerName.equalsIgnoreCase("Content-Type")) { using namespace mime; @@ -318,18 +319,14 @@ bool EthernetWebServer::_parseRequest(EthernetClient& client) else if (headerValue.startsWith("multipart/")) { boundaryStr = headerValue.substring(headerValue.indexOf('=') + 1); - // KH boundaryStr.replace("\"", ""); - // isForm = true; } } - //KH else if (headerName.equalsIgnoreCase("Content-Length")) { - contentLength = headerValue.toInt(); + _clientContentLength = contentLength = headerValue.toInt(); } - //KH else if (headerName.equalsIgnoreCase("Host")) { _hostHeader = headerValue; @@ -338,6 +335,9 @@ bool EthernetWebServer::_parseRequest(EthernetClient& client) //KH #if USE_NEW_WEBSERVER_VERSION + + //////////////////////////////////////// + String plainBuf; if ( !isForm @@ -434,7 +434,11 @@ bool EthernetWebServer::_parseRequest(EthernetClient& client) return true; -#else + //////////////////////////////////////// + +#else // #if USE_NEW_WEBSERVER_VERSION + + //////////////////////////////////////// if (isForm) { @@ -493,16 +497,16 @@ bool EthernetWebServer::_parseRequest(EthernetClient& client) #endif } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// bool EthernetWebServer::_collectHeader(const char* headerName, const char* headerValue) { for (int i = 0; i < _headerKeysCount; i++) { - //KH if (_currentHeaders[i].key.equalsIgnoreCase(headerName)) { _currentHeaders[i].value = headerValue; + return true; } } @@ -510,11 +514,11 @@ bool EthernetWebServer::_collectHeader(const char* headerName, const char* heade return false; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// #if USE_NEW_WEBSERVER_VERSION -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// struct storeArgHandler { @@ -528,91 +532,72 @@ struct storeArgHandler } }; -///////////////////////////////////////////////////////////////////////// - -struct nullArgHandler -{ - void operator() (String& key, String& value, const String& data, int equal_index, int pos, int key_end_pos, - int next_index) - { - (void)key; - (void)value; - (void)data; - (void)equal_index; - (void)pos; - (void)key_end_pos; - (void)next_index; - // do nothing - } -}; - -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::_parseArguments(const String& data) { if (_currentArgs) delete[] _currentArgs; - _currentArgCount = _parseArgumentsPrivate(data, nullArgHandler()); - - // allocate one more, this is needed because {"plain": plainBuf} is always added - _currentArgs = new RequestArgument[_currentArgCount + 1]; - - (void)_parseArgumentsPrivate(data, storeArgHandler()); -} + _currentArgs = 0; -///////////////////////////////////////////////////////////////////////// + if (data.length() == 0) + { + _currentArgCount = 0; + _currentArgs = new RequestArgument[1]; -int EthernetWebServer::_parseArgumentsPrivate(const String& data, - vl::Func handler) -{ - ET_LOGDEBUG1(F("args: "), data); + return; + } - size_t pos = 0; - int arg_total = 0; + _currentArgCount = 1; - while (true) + for (int i = 0; i < (int)data.length(); ) { - // skip empty expression - while (data[pos] == '&' || data[pos] == ';') - if (++pos >= data.length()) - break; + i = data.indexOf('&', i); - // locate separators - int equal_index = data.indexOf('=', pos); - int key_end_pos = equal_index; - int next_index = data.indexOf('&', pos); - int next_index2 = data.indexOf(';', pos); + if (i == -1) + break; + + ++i; + ++_currentArgCount; + } - if ((next_index == -1) || (next_index2 != -1 && next_index2 < next_index)) - next_index = next_index2; + _currentArgs = new RequestArgument[_currentArgCount + 1]; - if ((key_end_pos == -1) || ((key_end_pos > next_index) && (next_index != -1))) - key_end_pos = next_index; + int pos = 0; + int iarg; - if (key_end_pos == -1) - key_end_pos = data.length(); + for (iarg = 0; iarg < _currentArgCount;) + { + int equal_sign_index = data.indexOf('=', pos); + int next_arg_index = data.indexOf('&', pos); - // handle key/value - if ((int)pos < key_end_pos) + if ((equal_sign_index == -1) || ((equal_sign_index > next_arg_index) && (next_arg_index != -1))) { - RequestArgument& arg = _currentArgs[arg_total]; - handler(arg.key, arg.value, data, equal_index, pos, key_end_pos, next_index); + if (next_arg_index == -1) + break; - ++arg_total; - pos = next_index + 1; + pos = next_arg_index + 1; + + continue; } - if (next_index == -1) + RequestArgument& arg = _currentArgs[iarg]; + arg.key = urlDecode(data.substring(pos, equal_sign_index)); + arg.value = urlDecode(data.substring(equal_sign_index + 1, next_arg_index)); + + ++iarg; + + if (next_arg_index == -1) break; - } - ET_LOGDEBUG1(F("args count: "), arg_total); + pos = next_arg_index + 1; + } - return arg_total; + _currentArgCount = iarg; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::_uploadWriteByte(uint8_t b) { @@ -628,7 +613,9 @@ void EthernetWebServer::_uploadWriteByte(uint8_t b) _currentUpload->buf[_currentUpload->currentSize++] = b; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// + +#if 1 uint8_t EthernetWebServer::_uploadReadByte(EthernetClient& client) { @@ -645,11 +632,56 @@ uint8_t EthernetWebServer::_uploadReadByte(EthernetClient& client) return (uint8_t)res; } -///////////////////////////////////////////////////////////////////////// - #else -///////////////////////////////////////////////////////////////////////// +uint8_t EthernetWebServer::_uploadReadByte(EthernetClient& client) +{ + int res = client.read(); + + if (res < 0) + { + // keep trying until you either read a valid byte or timeout + unsigned long startMillis = millis(); + unsigned long timeoutIntervalMillis = client.getTimeout(); + bool timedOut = false; + + for (;;) + { + if (!client.connected()) + return -1; + + // loosely modeled after blinkWithoutDelay pattern + while (!timedOut && !client.available() && client.connected()) + { + delay(2); + timedOut = (millis() - startMillis) >= timeoutIntervalMillis; + } + + res = client.read(); + + if (res >= 0) + { + return res; // exit on a valid read + } + + timedOut = (millis() - startMillis) >= timeoutIntervalMillis; + + if (timedOut) + { + return res; // exit on a timeout + } + } + } + + return res; +} + +#endif +//////////////////////////////////////// + +#else // #if USE_NEW_WEBSERVER_VERSION + +//////////////////////////////////////// void EthernetWebServer::_parseArguments(const String& data) { @@ -697,7 +729,6 @@ void EthernetWebServer::_parseArguments(const String& data) ET_LOGDEBUG1(F("=@ "), equal_sign_index); ET_LOGDEBUG1(F(" &@ "), next_arg_index); - if ((equal_sign_index == -1) || ((equal_sign_index > next_arg_index) && (next_arg_index != -1))) { ET_LOGDEBUG1(F("arg missing value: "), iarg); @@ -731,7 +762,7 @@ void EthernetWebServer::_parseArguments(const String& data) ET_LOGDEBUG1(F("args count: "), _currentArgCount); } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// void EthernetWebServer::_uploadWriteByte(uint8_t b) { @@ -747,7 +778,7 @@ void EthernetWebServer::_uploadWriteByte(uint8_t b) _currentUpload.buf[_currentUpload.currentSize++] = b; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// uint8_t EthernetWebServer::_uploadReadByte(EthernetClient& client) { @@ -764,15 +795,15 @@ uint8_t EthernetWebServer::_uploadReadByte(EthernetClient& client) return (uint8_t)res; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// -#endif +#endif // #if USE_NEW_WEBSERVER_VERSION -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// #if USE_NEW_WEBSERVER_VERSION -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// bool EthernetWebServer::_parseForm(EthernetClient& client, const String& boundary, uint32_t len) { @@ -956,7 +987,9 @@ bool EthernetWebServer::_parseForm(EthernetClient& client, const String& boundar } } + // Better compiler warning than risk of fragmented heap uint8_t endBuf[boundary.length()]; + client.readBytes(endBuf, boundary.length()); if (strstr((const char*)endBuf, boundary.c_str()) != NULL) @@ -980,6 +1013,7 @@ bool EthernetWebServer::_parseForm(EthernetClient& client, const String& boundar if (line == "--") { ET_LOGDEBUG(F("Done Parsing POST")); + break; } @@ -1016,8 +1050,8 @@ bool EthernetWebServer::_parseForm(EthernetClient& client, const String& boundar } int iarg; - int totalArgs = ((WEBSERVER_MAX_POST_ARGS - _postArgsLen) < _currentArgCount) ? (WEBSERVER_MAX_POST_ARGS - _postArgsLen) - : _currentArgCount; + int totalArgs = ((WEBSERVER_MAX_POST_ARGS - _postArgsLen) < _currentArgCount) ? + (WEBSERVER_MAX_POST_ARGS - _postArgsLen) : _currentArgCount; for (iarg = 0; iarg < totalArgs; iarg++) { @@ -1031,6 +1065,13 @@ bool EthernetWebServer::_parseForm(EthernetClient& client, const String& boundar _currentArgs = new RequestArgument[_postArgsLen]; + if (_currentArgs == nullptr) + { + ET_LOGERROR(F("EthernetWebServer::_parseForm: null _currentArgs")); + + return false; + } + for (iarg = 0; iarg < _postArgsLen; iarg++) { RequestArgument& arg = _currentArgs[iarg]; @@ -1055,7 +1096,7 @@ bool EthernetWebServer::_parseForm(EthernetClient& client, const String& boundar return false; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// bool EthernetWebServer::_parseFormUploadAborted() { @@ -1067,11 +1108,11 @@ bool EthernetWebServer::_parseFormUploadAborted() return false; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// -#else +#else // #if USE_NEW_WEBSERVER_VERSION -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// bool EthernetWebServer::_parseForm(EthernetClient& client, const String& boundary, uint32_t len) { @@ -1094,6 +1135,7 @@ bool EthernetWebServer::_parseForm(EthernetClient& client, const String& boundar if (line == ("--" + boundary)) { RequestArgument* postArgs = new RequestArgument[32]; + int postArgsLen = 0; while (1) @@ -1244,7 +1286,9 @@ bool EthernetWebServer::_parseForm(EthernetClient& client, const String& boundar } } + // Better compiler warning than risk of fragmented heap uint8_t endBuf[boundary.length()]; + client.readBytes(endBuf, boundary.length()); if (strstr((const char*)endBuf, boundary.c_str()) != NULL) @@ -1319,6 +1363,13 @@ bool EthernetWebServer::_parseForm(EthernetClient& client, const String& boundar _currentArgs = new RequestArgument[postArgsLen]; + if (_currentArgs == nullptr) + { + ET_LOGERROR(F("EthernetWebServer::_parseForm: null _currentArgs")); + + return false; + } + for (iarg = 0; iarg < postArgsLen; iarg++) { RequestArgument& arg = _currentArgs[iarg]; @@ -1339,7 +1390,7 @@ bool EthernetWebServer::_parseForm(EthernetClient& client, const String& boundar return false; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// bool EthernetWebServer::_parseFormUploadAborted() { @@ -1351,11 +1402,11 @@ bool EthernetWebServer::_parseFormUploadAborted() return false; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// -#endif +#endif // #if USE_NEW_WEBSERVER_VERSION -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// String EthernetWebServer::urlDecode(const String& text) { @@ -1394,6 +1445,6 @@ String EthernetWebServer::urlDecode(const String& text) return decoded; } -///////////////////////////////////////////////////////////////////////// +//////////////////////////////////////// #endif // ETHERNET_WEBSERVER_PARSING_IMPL_H diff --git a/src/detail/Debug.h b/src/detail/Debug.h index c5d2d777..4eb34bc7 100644 --- a/src/detail/Debug.h +++ b/src/detail/Debug.h @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ #pragma once diff --git a/src/detail/ESP_RequestHandlersImpl.h b/src/detail/ESP_RequestHandlersImpl.h index 3cc07fe2..b013f63f 100644 --- a/src/detail/ESP_RequestHandlersImpl.h +++ b/src/detail/ESP_RequestHandlersImpl.h @@ -13,7 +13,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -31,6 +31,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ #pragma once diff --git a/src/detail/RequestHandler.h b/src/detail/RequestHandler.h index 304daf58..16c6bdfb 100644 --- a/src/detail/RequestHandler.h +++ b/src/detail/RequestHandler.h @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ #pragma once diff --git a/src/detail/RequestHandlersImpl.h b/src/detail/RequestHandlersImpl.h index 6a17324a..b36fb642 100644 --- a/src/detail/RequestHandlersImpl.h +++ b/src/detail/RequestHandlersImpl.h @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ #pragma once diff --git a/src/detail/esp_detail/mimetable.cpp b/src/detail/esp_detail/mimetable.cpp index 3a3dbca4..4b31b3af 100644 --- a/src/detail/esp_detail/mimetable.cpp +++ b/src/detail/esp_detail/mimetable.cpp @@ -13,7 +13,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -31,6 +31,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ #if (ESP32 || ESP8266) diff --git a/src/detail/esp_detail/mimetable.h b/src/detail/esp_detail/mimetable.h index 7cb96563..a2942de5 100644 --- a/src/detail/esp_detail/mimetable.h +++ b/src/detail/esp_detail/mimetable.h @@ -13,7 +13,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -31,6 +31,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ #pragma once diff --git a/src/detail/mimetable.h b/src/detail/mimetable.h index 06a19516..22f536b6 100644 --- a/src/detail/mimetable.h +++ b/src/detail/mimetable.h @@ -12,7 +12,7 @@ @file Esp8266WebServer.h @author Ivan Grokhotkov - Version: 2.2.4 + Version: 2.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -30,6 +30,7 @@ 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core + 2.3.0 K Hoang 15/11/2022 Add new features, such as CORS. Update code and examples to send big data *************************************************************************************************************************************/ #pragma once diff --git a/src/libb64/base64.cpp b/src/libb64/base64.cpp index 11a084e4..c2880eba 100644 --- a/src/libb64/base64.cpp +++ b/src/libb64/base64.cpp @@ -10,25 +10,6 @@ Original author: @file Esp8266WebServer.h @author Ivan Grokhotkov - - Version: 2.2.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 13/02/2020 Initial coding for Arduino Mega, Teensy, etc to support Ethernetx libraries - ... - 2.0.0 K Hoang 16/01/2022 To coexist with ESP32 WebServer and ESP8266 ESP8266WebServer - 2.0.1 K Hoang 02/03/2022 Fix decoding error bug - 2.0.2 K Hoang 14/03/2022 Fix bug when using QNEthernet staticIP. Add staticIP option to NativeEthernet - 2.1.0 K Hoang 03/04/2022 Use Ethernet_Generic library as default. Support SPI2 for ESP32 - 2.1.1 K Hoang 04/04/2022 Fix compiler error for Portenta_H7 using Portenta Ethernet - 2.1.2 K Hoang 08/04/2022 Add support to SPI1 for RP2040 using arduino-pico core - 2.1.3 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples - 2.2.0 K Hoang 05/05/2022 Add support to custom SPI for Teensy, Mbed RP2040, Portenta_H7, etc. - 2.2.1 K Hoang 25/08/2022 Auto-select SPI SS/CS pin according to board package - 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 - 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore - 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core *************************************************************************************************************************************/ #include "base64.h" diff --git a/src/libb64/base64.h b/src/libb64/base64.h index a053be74..761e273b 100644 --- a/src/libb64/base64.h +++ b/src/libb64/base64.h @@ -10,25 +10,6 @@ Original author: @file Esp8266WebServer.h @author Ivan Grokhotkov - - Version: 2.2.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 13/02/2020 Initial coding for Arduino Mega, Teensy, etc to support Ethernetx libraries - ... - 2.0.0 K Hoang 16/01/2022 To coexist with ESP32 WebServer and ESP8266 ESP8266WebServer - 2.0.1 K Hoang 02/03/2022 Fix decoding error bug - 2.0.2 K Hoang 14/03/2022 Fix bug when using QNEthernet staticIP. Add staticIP option to NativeEthernet - 2.1.0 K Hoang 03/04/2022 Use Ethernet_Generic library as default. Support SPI2 for ESP32 - 2.1.1 K Hoang 04/04/2022 Fix compiler error for Portenta_H7 using Portenta Ethernet - 2.1.2 K Hoang 08/04/2022 Add support to SPI1 for RP2040 using arduino-pico core - 2.1.3 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples - 2.2.0 K Hoang 05/05/2022 Add support to custom SPI for Teensy, Mbed RP2040, Portenta_H7, etc. - 2.2.1 K Hoang 25/08/2022 Auto-select SPI SS/CS pin according to board package - 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 - 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore - 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core *************************************************************************************************************************************/ #pragma once diff --git a/src/libb64/cdecode.c b/src/libb64/cdecode.c index 247cc689..0ab86d34 100644 --- a/src/libb64/cdecode.c +++ b/src/libb64/cdecode.c @@ -10,25 +10,6 @@ Original author: @file Esp8266WebServer.h @author Ivan Grokhotkov - - Version: 2.2.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 13/02/2020 Initial coding for Arduino Mega, Teensy, etc to support Ethernetx libraries - ... - 2.0.0 K Hoang 16/01/2022 To coexist with ESP32 WebServer and ESP8266 ESP8266WebServer - 2.0.1 K Hoang 02/03/2022 Fix decoding error bug - 2.0.2 K Hoang 14/03/2022 Fix bug when using QNEthernet staticIP. Add staticIP option to NativeEthernet - 2.1.0 K Hoang 03/04/2022 Use Ethernet_Generic library as default. Support SPI2 for ESP32 - 2.1.1 K Hoang 04/04/2022 Fix compiler error for Portenta_H7 using Portenta Ethernet - 2.1.2 K Hoang 08/04/2022 Add support to SPI1 for RP2040 using arduino-pico core - 2.1.3 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples - 2.2.0 K Hoang 05/05/2022 Add support to custom SPI for Teensy, Mbed RP2040, Portenta_H7, etc. - 2.2.1 K Hoang 25/08/2022 Auto-select SPI SS/CS pin according to board package - 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 - 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore - 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core *****************************************************************************************************************************/ #if !( defined(ESP32) || defined(ESP8266) ) diff --git a/src/libb64/cdecode.h b/src/libb64/cdecode.h index ea795fbe..5be45d14 100644 --- a/src/libb64/cdecode.h +++ b/src/libb64/cdecode.h @@ -10,25 +10,6 @@ Original author: @file Esp8266WebServer.h @author Ivan Grokhotkov - - Version: 2.2.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 13/02/2020 Initial coding for Arduino Mega, Teensy, etc to support Ethernetx libraries - ... - 2.0.0 K Hoang 16/01/2022 To coexist with ESP32 WebServer and ESP8266 ESP8266WebServer - 2.0.1 K Hoang 02/03/2022 Fix decoding error bug - 2.0.2 K Hoang 14/03/2022 Fix bug when using QNEthernet staticIP. Add staticIP option to NativeEthernet - 2.1.0 K Hoang 03/04/2022 Use Ethernet_Generic library as default. Support SPI2 for ESP32 - 2.1.1 K Hoang 04/04/2022 Fix compiler error for Portenta_H7 using Portenta Ethernet - 2.1.2 K Hoang 08/04/2022 Add support to SPI1 for RP2040 using arduino-pico core - 2.1.3 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples - 2.2.0 K Hoang 05/05/2022 Add support to custom SPI for Teensy, Mbed RP2040, Portenta_H7, etc. - 2.2.1 K Hoang 25/08/2022 Auto-select SPI SS/CS pin according to board package - 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 - 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore - 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core *****************************************************************************************************************************/ #pragma once diff --git a/src/libb64/cencode.c b/src/libb64/cencode.c index b9dcc604..6d522cd2 100644 --- a/src/libb64/cencode.c +++ b/src/libb64/cencode.c @@ -10,25 +10,6 @@ Original author: @file Esp8266WebServer.h @author Ivan Grokhotkov - - Version: 2.2.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 13/02/2020 Initial coding for Arduino Mega, Teensy, etc to support Ethernetx libraries - ... - 2.0.0 K Hoang 16/01/2022 To coexist with ESP32 WebServer and ESP8266 ESP8266WebServer - 2.0.1 K Hoang 02/03/2022 Fix decoding error bug - 2.0.2 K Hoang 14/03/2022 Fix bug when using QNEthernet staticIP. Add staticIP option to NativeEthernet - 2.1.0 K Hoang 03/04/2022 Use Ethernet_Generic library as default. Support SPI2 for ESP32 - 2.1.1 K Hoang 04/04/2022 Fix compiler error for Portenta_H7 using Portenta Ethernet - 2.1.2 K Hoang 08/04/2022 Add support to SPI1 for RP2040 using arduino-pico core - 2.1.3 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples - 2.2.0 K Hoang 05/05/2022 Add support to custom SPI for Teensy, Mbed RP2040, Portenta_H7, etc. - 2.2.1 K Hoang 25/08/2022 Auto-select SPI SS/CS pin according to board package - 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 - 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore - 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core *****************************************************************************************************************************/ #if !( defined(ESP32) || defined(ESP8266) ) diff --git a/src/libb64/cencode.h b/src/libb64/cencode.h index 904fe633..c88c8f69 100644 --- a/src/libb64/cencode.h +++ b/src/libb64/cencode.h @@ -10,25 +10,6 @@ Original author: @file Esp8266WebServer.h @author Ivan Grokhotkov - - Version: 2.2.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 13/02/2020 Initial coding for Arduino Mega, Teensy, etc to support Ethernetx libraries - ... - 2.0.0 K Hoang 16/01/2022 To coexist with ESP32 WebServer and ESP8266 ESP8266WebServer - 2.0.1 K Hoang 02/03/2022 Fix decoding error bug - 2.0.2 K Hoang 14/03/2022 Fix bug when using QNEthernet staticIP. Add staticIP option to NativeEthernet - 2.1.0 K Hoang 03/04/2022 Use Ethernet_Generic library as default. Support SPI2 for ESP32 - 2.1.1 K Hoang 04/04/2022 Fix compiler error for Portenta_H7 using Portenta Ethernet - 2.1.2 K Hoang 08/04/2022 Add support to SPI1 for RP2040 using arduino-pico core - 2.1.3 K Hoang 27/04/2022 Change from `arduino.cc` to `arduino.tips` in examples - 2.2.0 K Hoang 05/05/2022 Add support to custom SPI for Teensy, Mbed RP2040, Portenta_H7, etc. - 2.2.1 K Hoang 25/08/2022 Auto-select SPI SS/CS pin according to board package - 2.2.2 K Hoang 06/09/2022 Slow SPI clock for old W5100 shield or SAMD Zero. Improve support for SAMD21 - 2.2.3 K Hoang 17/09/2022 Add support to AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore - 2.2.4 K Hoang 26/10/2022 Add support to Seeed XIAO_NRF52840 and XIAO_NRF52840_SENSE using `mbed` or `nRF52` core *****************************************************************************************************************************/ #pragma once