From 9267f4082790bc3a4d34335d12a3a4ecdc0b005a Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Sun, 23 Jan 2022 19:16:33 -0500 Subject: [PATCH] v1.6.0 to reduce v1.5.0 breaking effect ### Releases v1.6.0 1. Reduce the breaking effect of v1.5.0 by enabling compatibility with old code to include only `AsyncHTTPRequest_Generic.h` 2. Update `Packages' Patches` --- README.md | 160 +++---- changelog.md | 6 + .../AsyncCustomHeader_STM32.ino | 8 +- .../AsyncDweetGet_STM32.ino | 4 +- .../AsyncDweetPost_STM32.ino | 8 +- .../AsyncHTTPMultiRequests_ESP.ino | 9 +- .../AsyncHTTPRequest_ESP.ino | 10 +- .../AsyncHTTPRequest_ESP_WiFiManager.ino | 8 +- .../AsyncHTTPRequest_STM32.ino | 8 +- .../AsyncSimpleGET_STM32.ino | 8 +- .../AsyncWebClientRepeating_STM32.ino | 8 +- .../AsyncCustomHeader_STM32_LAN8720.ino | 8 +- .../AsyncDweetGet_STM32_LAN8720.ino | 8 +- .../AsyncDweetPost_STM32_LAN8720.ino | 8 +- .../AsyncHTTPRequest_STM32_LAN8720.ino | 8 +- .../AsyncSimpleGET_STM32_LAN8720.ino | 8 +- .../AsyncWebClientRepeating_STM32_LAN8720.ino | 8 +- .../AsyncHTTPMultiRequests_WT32_ETH01.ino | 8 +- .../AsyncHTTPRequest_WT32_ETH01.ino | 8 +- .../multiFileProject/multiFileProject.cpp | 15 + examples/multiFileProject/multiFileProject.h | 18 + .../multiFileProject/multiFileProject.ino | 47 ++ platformio/platformio.ini | 4 +- src/AsyncHTTPRequest_Debug_Generic.h | 3 +- src/AsyncHTTPRequest_Generic.h | 383 +--------------- src/AsyncHTTPRequest_Generic.hpp | 426 ++++++++++++++++++ src/AsyncHTTPRequest_Impl_Generic.h | 3 +- 27 files changed, 650 insertions(+), 550 deletions(-) create mode 100644 examples/multiFileProject/multiFileProject.cpp create mode 100644 examples/multiFileProject/multiFileProject.h create mode 100644 examples/multiFileProject/multiFileProject.ino create mode 100644 src/AsyncHTTPRequest_Generic.hpp diff --git a/README.md b/README.md index 096224c..8af31f0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ ## Table of Contents -* [Important Breaking Change from v1.5.0](#Important-Breaking-Change-from-v150) +* [Important Change from v1.6.0](#Important-Change-from-v160) * [Why do we need the new Async AsyncHTTPRequest_Generic library](#why-do-we-need-this-async-asynchttprequest_generic-library) * [Features](#features) * [Supports](#supports) @@ -59,6 +59,8 @@ * [For WT32_ETH01](#for-wt32_eth01) * [1. AsyncHTTPRequest_WT32_ETH01](examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01) * [2. AsyncHTTPMultiRequests_WT32_ETH01](examples/WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01) + * [For ESP or STM32](#For-ESP-or-STM32) + * [1. **multiFileProject**](examples/multiFileProject) **New** * [Example AsyncHTTPRequest_STM32](#example-asynchttprequest_stm32) * [1. File AsyncHTTPRequest_STM32.ino](#1-file-asynchttprequest_stm32ino) * [2. File defines.h](#2-file-definesh) @@ -84,26 +86,10 @@ --- --- -### Important Breaking Change from v1.5.0 +### Important Change from v1.6.0 Please have a look at [HOWTO Fix `Multiple Definitions` Linker Error](#howto-fix-multiple-definitions-linker-error) -From v1.5.0, you must use - -``` -#include //https://github.com/khoih-prog/AsyncHTTPRequest_Generic - -// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic -``` - -instead of only - -``` -#include //https://github.com/khoih-prog/AsyncHTTPRequest_Generic -``` - - --- --- @@ -181,7 +167,7 @@ This library is based on, modified from: 8. [`STM32Ethernet library v1.2.0+`](https://github.com/stm32duino/STM32Ethernet) for STM32 using built-in Ethernet LAN8742A on (Nucleo-144, Discovery). [![GitHub release](https://img.shields.io/github/release/stm32duino/STM32Ethernet.svg)](https://github.com/stm32duino/STM32Ethernet/releases/latest) 9. [`LwIP library v2.1.2+`](https://github.com/stm32duino/LwIP) for STM32 using built-in Ethernet LAN8742A on (Nucleo-144, Discovery). [![GitHub release](https://img.shields.io/github/release/stm32duino/LwIP.svg)](https://github.com/stm32duino/LwIP/releases/latest) 10. [`STM32AsyncTCP library v1.0.1+`](https://github.com/khoih-prog/STM32AsyncTCP) for built-in Ethernet on (Nucleo-144, Discovery). To install manually for Arduino IDE. -11. [`ESPAsync_WiFiManager library v1.10.0+`](https://github.com/khoih-prog/ESPAsync_WiFiManager) for ESP32/ESP8266 using some examples. [![GitHub release](https://img.shields.io/github/release/khoih-prog/ESPAsync_WiFiManager.svg)](https://github.com/khoih-prog/ESPAsync_WiFiManager/releases) +11. [`ESPAsync_WiFiManager library v1.11.0+`](https://github.com/khoih-prog/ESPAsync_WiFiManager) for ESP32/ESP8266 using some examples. [![GitHub release](https://img.shields.io/github/release/khoih-prog/ESPAsync_WiFiManager.svg)](https://github.com/khoih-prog/ESPAsync_WiFiManager/releases) 12. [`LittleFS_esp32 v1.0.6+`](https://github.com/lorol/LITTLEFS) for ESP32-based boards using LittleFS. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/LittleFS_esp32.svg?)](https://www.ardu-badge.com/LittleFS_esp32). 13. [`WebServer_WT32_ETH01 library v1.4.1+`](https://github.com/khoih-prog/WebServer_WT32_ETH01) if necessary to use WT32_ETH01 boards. To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/WebServer_WT32_ETH01.svg?)](https://www.ardu-badge.com/WebServer_WT32_ETH01) @@ -219,12 +205,12 @@ To use LAN8720 on some STM32 boards - **Discovery (DISCO_F746NG)** - **STM32F4 boards (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE_Mini, DIYMORE_F407VGT, FK407M1)** -you have to copy the files [stm32f4xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.1.0/system/STM32F4xx) and [stm32f7xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.1.0/system/STM32F7xx) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.1.0/system) to overwrite the old files. +you have to copy the files [stm32f4xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.2.0/system/STM32F4xx) and [stm32f7xx_hal_conf_default.h](Packages_Patches/STM32/hardware/stm32/2.2.0/system/STM32F7xx) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system) to overwrite the old files. -Supposing the STM32 stm32 core version is 2.1.0. These files must be copied into the directory: +Supposing the STM32 stm32 core version is 2.2.0. These files must be copied into the directory: -- `~/.arduino15/packages/STM32/hardware/stm32/2.1.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h` for STM32F4. -- `~/.arduino15/packages/STM32/hardware/stm32/2.1.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h` for Nucleo-144 STM32F7. +- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h` for STM32F4. +- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h` for Nucleo-144 STM32F7. Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, theses files must be copied into the corresponding directory: @@ -235,12 +221,12 @@ theses files must be copied into the corresponding directory: #### 2. For STM32 boards to use Serial1 -**To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards**, you have to copy the files [STM32 variant.h](Packages_Patches/STM32/hardware/stm32/2.1.0) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.1.0). You have to modify the files corresponding to your boards, this is just an illustration how to do. +**To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards**, you have to copy the files [STM32 variant.h](Packages_Patches/STM32/hardware/stm32/2.2.0) into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.2.0). You have to modify the files corresponding to your boards, this is just an illustration how to do. -Supposing the STM32 stm32 core version is 2.1.0. These files must be copied into the directory: +Supposing the STM32 stm32 core version is 2.2.0. These files must be copied into the directory: -- `~/.arduino15/packages/STM32/hardware/stm32/2.1.0/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h` for Nucleo-144 NUCLEO_F767ZI. -- `~/.arduino15/packages/STM32/hardware/stm32/2.1.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h` for Nucleo-64 NUCLEO_L053R8. +- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h` for Nucleo-144 NUCLEO_F767ZI. +- `~/.arduino15/packages/STM32/hardware/stm32/2.2.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h` for Nucleo-64 NUCLEO_L053R8. Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, theses files must be copied into the corresponding directory: @@ -279,19 +265,22 @@ Thanks to [Roshan](https://github.com/solroshan) to report the issue in [Error e The current library implementation, using `xyz-Impl.h` instead of standard `xyz.cpp`, possibly creates certain `Multiple Definitions` Linker error in certain use cases. -You can use +You can include this `.hpp` file ``` -#include //https://github.com/khoih-prog/AsyncHTTPRequest_Generic +// Can be included as many times as necessary, without `Multiple Definitions` Linker Error +#include "AsyncHTTPRequest_Generic.hpp" //https://github.com/khoih-prog/AsyncHTTPRequest_Generic ``` -in many files. But be sure to use the following `#include ` **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error +in many files. But be sure to use the following `.h` file **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error ``` // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include "AsyncHTTPRequest_Generic.h" //https://github.com/khoih-prog/AsyncHTTPRequest_Generic ``` +Check the new [**multiFileProject** example](examples/multiFileProject) for a `HOWTO` demo. + Have a look at the discussion in [Different behaviour using the src_cpp or src_h lib #80](https://github.com/khoih-prog/ESPAsync_WiFiManager/discussions/80) --- @@ -450,6 +439,11 @@ Connect FDTI (USB to Serial) as follows: 1. [AsyncHTTPRequest_WT32_ETH01](examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01) 2. [AsyncHTTPMultiRequests_WT32_ETH01](examples/WT32_ETH01/AsyncHTTPMultiRequests_ESP) +#### For ESP or STM32 + + 1. [**multiFileProject**](examples/multiFileProject) **New** + + --- ### Example [AsyncHTTPRequest_STM32](examples/AsyncHTTPRequest_STM32) @@ -461,16 +455,14 @@ Please take a look at other examples, as well. ```cpp #include "defines.h" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic - // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include // https://github.com/sstaub/Ticker @@ -694,47 +686,44 @@ IPAddress ip(192, 168, 2, 232); #### 1. [AsyncHTTPRequest_STM32](examples/AsyncHTTPRequest_STM32) running on STM32F7 Nucleo-144 NUCLEO_F767ZI using built-in LAN8742A ``` - Start AsyncHTTPRequest_STM32 on NUCLEO_F767ZI -AsyncHTTPRequest_Generic v1.5.0 -Warning. Must use this example on Version equal or later than : AsyncHTTPRequest_Generic v1.5.0 +AsyncHTTPRequest_Generic v1.6.0 AsyncHTTPRequest @ IP : 192.168.2.178 ************************************** abbreviation: EST client_ip: aaa.bbb.ccc.ddd -datetime: 2021-12-30T13:53:51.012921-05:00 -day_of_week: 4 -day_of_year: 364 +datetime: 2022-01-23T19:06:29.846071-05:00 +day_of_week: 0 +day_of_year: 23 dst: false dst_from: dst_offset: 0 dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1640890431 -utc_datetime: 2021-12-30T18:53:51.012921+00:00 +unixtime: 1642982789 +utc_datetime: 2022-01-24T00:06:29.846071+00:00 utc_offset: -05:00 -week_number: 52 -************************************** +week_number: 3 +********************* ************************************** abbreviation: EST client_ip: aaa.bbb.ccc.ddd -datetime: 2021-12-30T13:54:50.320646-05:00 -day_of_week: 4 -day_of_year: 364 +datetime: 2022-01-23T19:08:29.871390-05:00 +day_of_week: 0 +day_of_year: 23 dst: false dst_from: dst_offset: 0 dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1640890490 -utc_datetime: 2021-12-30T18:54:50.320646+00:00 +unixtime: 1642982909 +utc_datetime: 2022-01-24T00:08:29.871390+00:00 utc_offset: -05:00 -week_number: 52 - +week_number: 3 ``` --- @@ -743,7 +732,7 @@ week_number: 52 ``` Starting AsyncHTTPRequest_ESP_WiFiManager using LittleFS on ESP8266_NODEMCU -AsyncHTTPRequest_Generic v1.5.0 +AsyncHTTPRequest_Generic v1.6.0 Stored: SSID = HueNet1, Pass = 12345678 Got stored Credentials. Timeout 120s ConnectMultiWiFi in setup @@ -752,19 +741,19 @@ H ************************************** abbreviation: EST client_ip: aaa.bbb.ccc.ddd -datetime: 2021-12-30T13:54:50.320646-05:00 -day_of_week: 4 -day_of_year: 364 +datetime: 2022-01-23T19:08:29.871390-05:00 +day_of_week: 0 +day_of_year: 23 dst: false dst_from: dst_offset: 0 dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1640890490 -utc_datetime: 2021-12-30T18:54:50.320646+00:00 +unixtime: 1642982909 +utc_datetime: 2022-01-24T00:08:29.871390+00:00 utc_offset: -05:00 -week_number: 52 +week_number: 3 ************************************** HHHHHH @@ -776,7 +765,7 @@ HHHHHH ``` Starting AsyncHTTPRequest_ESP_WiFiManager using SPIFFS on ESP32_DEV -AsyncHTTPRequest_Generic v1.5.0 +AsyncHTTPRequest_Generic v1.6.0 Stored: SSID = HueNet1, Pass = 12345678 Got stored Credentials. Timeout 120s ConnectMultiWiFi in setup @@ -785,37 +774,37 @@ H ************************************** abbreviation: EST client_ip: aaa.bbb.ccc.ddd -datetime: 2021-12-30T13:54:50.320646-05:00 -day_of_week: 4 -day_of_year: 364 +datetime: 2022-01-23T19:06:29.846071-05:00 +day_of_week: 0 +day_of_year: 23 dst: false dst_from: dst_offset: 0 dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1640890490 -utc_datetime: 2021-12-30T18:54:50.320646+00:00 +unixtime: 1642982789 +utc_datetime: 2022-01-24T00:06:29.846071+00:00 utc_offset: -05:00 -week_number: 52 +week_number: 3 ************************************** HHHHHHHHH HHHHHHHHHH HHHHHHHHHH H ************************************** abbreviation: EST client_ip: aaa.bbb.ccc.ddd -datetime: 2021-12-30T13:56:49.026396-05:00 -day_of_week: 4 -day_of_year: 364 +datetime: 2022-01-23T19:08:29.871390-05:00 +day_of_week: 0 +day_of_year: 23 dst: false dst_from: dst_offset: 0 dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1640890609 -utc_datetime: 2021-12-30T18:56:49.026396+00:00 +unixtime: 1642982909 +utc_datetime: 2022-01-24T00:08:29.871390+00:00 utc_offset: -05:00 -week_number: 52 +week_number: 3 ************************************** HHHHHHHHH HHHHHHHHHH HHHHHHHHHH @@ -827,7 +816,7 @@ HHHHHHHHH HHHHHHHHHH HHHHHHHHHH ``` Starting AsyncHTTPRequest_ESP using ESP8266_NODEMCU -AsyncHTTPRequest_Generic v1.5.0 +AsyncHTTPRequest_Generic v1.6.0 Connecting to WiFi SSID: HueNet1 ........... HTTP WebServer is @ IP : 192.168.2.81 @@ -835,20 +824,20 @@ HTTP WebServer is @ IP : 192.168.2.81 ************************************** abbreviation: EST client_ip: aaa.bbb.ccc.ddd -datetime: 2021-12-30T14:02:45.199491-05:00 -day_of_week: 4 -day_of_year: 364 + +datetime: 2022-01-23T19:08:29.871390-05:00 +day_of_week: 0 +day_of_year: 23 dst: false dst_from: dst_offset: 0 dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1640890965 -utc_datetime: 2021-12-30T19:02:45.199491+00:00 +unixtime: 1642982909 +utc_datetime: 2022-01-24T00:08:29.871390+00:00 utc_offset: -05:00 -week_number: 52 - +week_number: 3 ************************************** HHHHHHHHH HHHHHHHHHH HHHHHHHHHH H ``` @@ -860,7 +849,7 @@ HHHHHHHHH HHHHHHHHHH HHHHHHHHHH H ``` Start AsyncWebClientRepeating_STM32 on NUCLEO_F767ZI -AsyncHTTPRequest_Generic v1.5.0 +AsyncHTTPRequest_Generic v1.6.0 AsyncHTTPRequest @ IP : 192.168.2.72 ************************************** @@ -915,7 +904,7 @@ AsyncHTTPRequest @ IP : 192.168.2.72 ``` Start AsyncWebClientRepeating_STM32_LAN8720 on BLACK_F407VE -AsyncHTTPRequest_Generic v1.5.0 +AsyncHTTPRequest_Generic v1.6.0 AsyncHTTPRequest @ IP : 192.168.2.150 @@ -971,7 +960,7 @@ AsyncHTTPRequest @ IP : 192.168.2.150 ``` Starting AsyncHTTPRequest_WT32_ETH01 on ESP32_DEV with ETH_PHY_LAN8720 WebServer_WT32_ETH01 v1.4.1 -AsyncHTTPRequest_Generic v1.5.0 +AsyncHTTPRequest_Generic v1.6.0 ETH MAC: A8:03:2A:A1:61:73, IPv4: 192.168.2.232, FULL_DUPLEX, 100Mbps AsyncHTTPRequest @ IP : 192.168.2.232 @@ -997,7 +986,7 @@ H ``` Starting AsyncHTTPRequest_WT32_ETH01 on ESP32_DEV with ETH_PHY_LAN8720 WebServer_WT32_ETH01 v1.4.1 -AsyncHTTPRequest_Generic v1.5.0 +AsyncHTTPRequest_Generic v1.6.0 ETH MAC: A8:03:2A:A1:61:73, IPv4: 192.168.2.232, FULL_DUPLEX, 100Mbps AsyncHTTPRequest @ IP : 192.168.2.232 @@ -1074,6 +1063,7 @@ Submit issues to: [AsyncHTTPRequest_Generic issues](https://github.com/khoih-pro 8. Fix bug in WT32_ETH01 examples to reduce connection time 9. Fix `multiple-definitions` linker error and weird bug related to `src_cpp`. 10. Optimize library code by using `reference-passing` instead of `value-passing` +11. Enable compatibility with old code to include only `AsyncHTTPRequest_Generic.h` --- --- diff --git a/changelog.md b/changelog.md index 02cc341..77aff63 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ ## Table of Contents * [Changelog](#changelog) + * [Releases v1.6.0](#releases-v160) * [Releases v1.5.0](#releases-v150) * [Releases v1.4.1](#releases-v141) * [Releases v1.4.0](#releases-v140) @@ -33,6 +34,11 @@ ## Changelog +### Releases v1.6.0 + +1. Reduce the breaking effect of v1.5.0 by enabling compatibility with old code to include only `AsyncHTTPRequest_Generic.h` +2. Update `Packages' Patches` + ### Releases v1.5.0 1. Fix `multiple-definitions` linker error and weird bug related to `src_cpp`. Check [Different behaviour using the src_cpp or src_h lib #80](https://github.com/khoih-prog/ESPAsync_WiFiManager/discussions/80) diff --git a/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino b/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino index 19e9d94..f4733b7 100644 --- a/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino +++ b/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino @@ -24,16 +24,14 @@ //char GET_ServerAddress[] = "192.168.2.110/"; char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt"; -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic - // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include // https://github.com/sstaub/Ticker diff --git a/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino b/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino index fe7d848..c731e19 100644 --- a/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino +++ b/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino @@ -35,8 +35,8 @@ const char GET_ServerAddress[] = "dweet.io"; // use your own thing name here String dweetName = "/dweet/for/currentSecond?second="; -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 diff --git a/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino b/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino index 1fd09fa..6866ef2 100644 --- a/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino +++ b/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino @@ -29,16 +29,14 @@ const char POST_ServerAddress[] = "dweet.io"; // use your own thing name here String dweetName = "/dweet/for/pinA0-Read?"; -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic - // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include // https://github.com/sstaub/Ticker diff --git a/examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino b/examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino index 62efc63..27ffa35 100644 --- a/examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino +++ b/examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino @@ -44,12 +44,11 @@ #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. #endif -#define ESP_WIFIMANAGER_VERSION_MIN_TARGET "ESP_WiFiManager v1.8.0" -#define ESP_WIFIMANAGER_VERSION_MIN 1008000 - -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ESP_WIFIMANAGER_VERSION_MIN_TARGET "ESP_WiFiManager v1.9.0" +#define ESP_WIFIMANAGER_VERSION_MIN 1009000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // Level from 0-4 #define ASYNC_HTTP_DEBUG_PORT Serial #define _ASYNC_HTTP_LOGLEVEL_ 1 diff --git a/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino b/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino index 359f581..a392184 100644 --- a/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino +++ b/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino @@ -65,13 +65,11 @@ const char* password = "your_pass"; #include #endif -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 - -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include @@ -159,7 +157,7 @@ void setup() Serial.print("."); } - Serial.print(F("AsyncHTTPRequest @ IP : ")); + Serial.print(F("\nAsyncHTTPRequest @ IP : ")); Serial.println(WiFi.localIP()); request.setDebug(false); diff --git a/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino b/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino index b3272b2..d498fb4 100644 --- a/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino +++ b/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino @@ -46,11 +46,11 @@ #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. #endif -#define ESP_ASYNC_WIFIMANAGER_VERSION_MIN_TARGET "ESPAsync_WiFiManager v1.10.0" -#define ESP_ASYNC_WIFIMANAGER_VERSION_MIN 1010000 +#define ESP_ASYNC_WIFIMANAGER_VERSION_MIN_TARGET "ESPAsync_WiFiManager v1.11.0" +#define ESP_ASYNC_WIFIMANAGER_VERSION_MIN 1011000 -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // Level from 0-4 #define ASYNC_HTTP_DEBUG_PORT Serial diff --git a/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino b/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino index 05df4ab..b3730da 100644 --- a/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino +++ b/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino @@ -42,16 +42,14 @@ #include "defines.h" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic - // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include // https://github.com/sstaub/Ticker diff --git a/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino b/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino index ad6f27f..c408714 100644 --- a/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino +++ b/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino @@ -24,16 +24,14 @@ //char GET_ServerAddress[] = "ipv4bot.whatismyipaddress.com/"; char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt"; -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic - // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include // https://github.com/sstaub/Ticker diff --git a/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino b/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino index 3b74ef5..7bc1481 100644 --- a/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino +++ b/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino @@ -26,16 +26,14 @@ const char GET_ServerAddress[] = "arduino.cc"; // GET location String GET_Location = "/asciilogo.txt"; -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic - // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include // https://github.com/sstaub/Ticker diff --git a/examples/STM32_LAN8720/AsyncCustomHeader_STM32_LAN8720/AsyncCustomHeader_STM32_LAN8720.ino b/examples/STM32_LAN8720/AsyncCustomHeader_STM32_LAN8720/AsyncCustomHeader_STM32_LAN8720.ino index 65cafca..c88a3a0 100644 --- a/examples/STM32_LAN8720/AsyncCustomHeader_STM32_LAN8720/AsyncCustomHeader_STM32_LAN8720.ino +++ b/examples/STM32_LAN8720/AsyncCustomHeader_STM32_LAN8720/AsyncCustomHeader_STM32_LAN8720.ino @@ -24,16 +24,14 @@ //char GET_ServerAddress[] = "192.168.2.110/"; char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt"; -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic - // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include // https://github.com/sstaub/Ticker diff --git a/examples/STM32_LAN8720/AsyncDweetGet_STM32_LAN8720/AsyncDweetGet_STM32_LAN8720.ino b/examples/STM32_LAN8720/AsyncDweetGet_STM32_LAN8720/AsyncDweetGet_STM32_LAN8720.ino index b1ecc86..37e66d9 100644 --- a/examples/STM32_LAN8720/AsyncDweetGet_STM32_LAN8720/AsyncDweetGet_STM32_LAN8720.ino +++ b/examples/STM32_LAN8720/AsyncDweetGet_STM32_LAN8720/AsyncDweetGet_STM32_LAN8720.ino @@ -35,16 +35,14 @@ const char GET_ServerAddress[] = "dweet.io"; // use your own thing name here String dweetName = "/dweet/for/currentSecond?second="; -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic - // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include // https://github.com/sstaub/Ticker diff --git a/examples/STM32_LAN8720/AsyncDweetPost_STM32_LAN8720/AsyncDweetPost_STM32_LAN8720.ino b/examples/STM32_LAN8720/AsyncDweetPost_STM32_LAN8720/AsyncDweetPost_STM32_LAN8720.ino index f07e660..78af6f6 100644 --- a/examples/STM32_LAN8720/AsyncDweetPost_STM32_LAN8720/AsyncDweetPost_STM32_LAN8720.ino +++ b/examples/STM32_LAN8720/AsyncDweetPost_STM32_LAN8720/AsyncDweetPost_STM32_LAN8720.ino @@ -29,16 +29,14 @@ const char POST_ServerAddress[] = "dweet.io"; // use your own thing name here String dweetName = "/dweet/for/pinA0-Read?"; -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic - // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include // https://github.com/sstaub/Ticker diff --git a/examples/STM32_LAN8720/AsyncHTTPRequest_STM32_LAN8720/AsyncHTTPRequest_STM32_LAN8720.ino b/examples/STM32_LAN8720/AsyncHTTPRequest_STM32_LAN8720/AsyncHTTPRequest_STM32_LAN8720.ino index 6626cac..c4d8450 100644 --- a/examples/STM32_LAN8720/AsyncHTTPRequest_STM32_LAN8720/AsyncHTTPRequest_STM32_LAN8720.ino +++ b/examples/STM32_LAN8720/AsyncHTTPRequest_STM32_LAN8720/AsyncHTTPRequest_STM32_LAN8720.ino @@ -42,16 +42,14 @@ #include "defines.h" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic - // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include // https://github.com/sstaub/Ticker diff --git a/examples/STM32_LAN8720/AsyncSimpleGET_STM32_LAN8720/AsyncSimpleGET_STM32_LAN8720.ino b/examples/STM32_LAN8720/AsyncSimpleGET_STM32_LAN8720/AsyncSimpleGET_STM32_LAN8720.ino index 22d0ca6..ca5292c 100644 --- a/examples/STM32_LAN8720/AsyncSimpleGET_STM32_LAN8720/AsyncSimpleGET_STM32_LAN8720.ino +++ b/examples/STM32_LAN8720/AsyncSimpleGET_STM32_LAN8720/AsyncSimpleGET_STM32_LAN8720.ino @@ -24,16 +24,14 @@ //char GET_ServerAddress[] = "ipv4bot.whatismyipaddress.com/"; char GET_ServerAddress[] = "http://worldtimeapi.org/api/timezone/America/Toronto.txt"; -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic - // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include // https://github.com/sstaub/Ticker diff --git a/examples/STM32_LAN8720/AsyncWebClientRepeating_STM32_LAN8720/AsyncWebClientRepeating_STM32_LAN8720.ino b/examples/STM32_LAN8720/AsyncWebClientRepeating_STM32_LAN8720/AsyncWebClientRepeating_STM32_LAN8720.ino index 7613e34..0e3f299 100644 --- a/examples/STM32_LAN8720/AsyncWebClientRepeating_STM32_LAN8720/AsyncWebClientRepeating_STM32_LAN8720.ino +++ b/examples/STM32_LAN8720/AsyncWebClientRepeating_STM32_LAN8720/AsyncWebClientRepeating_STM32_LAN8720.ino @@ -26,16 +26,14 @@ const char GET_ServerAddress[] = "arduino.cc"; // GET location String GET_Location = "/asciilogo.txt"; -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic - // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include // https://github.com/sstaub/Ticker diff --git a/examples/WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01.ino b/examples/WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01.ino index 147cff4..68cd0a4 100644 --- a/examples/WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01.ino +++ b/examples/WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01.ino @@ -57,13 +57,11 @@ #include // https://github.com/khoih-prog/WebServer_WT32_ETH01 -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 - -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include diff --git a/examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01/AsyncHTTPRequest_WT32_ETH01.ino b/examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01/AsyncHTTPRequest_WT32_ETH01.ino index 68afe63..dbc2a7c 100644 --- a/examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01/AsyncHTTPRequest_WT32_ETH01.ino +++ b/examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01/AsyncHTTPRequest_WT32_ETH01.ino @@ -57,13 +57,11 @@ #include // https://github.com/khoih-prog/WebServer_WT32_ETH01 -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 - -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.6.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1006000 // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic #include diff --git a/examples/multiFileProject/multiFileProject.cpp b/examples/multiFileProject/multiFileProject.cpp new file mode 100644 index 0000000..cc53c7c --- /dev/null +++ b/examples/multiFileProject/multiFileProject.cpp @@ -0,0 +1,15 @@ +/**************************************************************************************************************************** + multiFileProject.cpp + For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc) + + AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer + + Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest) + + Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#include "multiFileProject.h" diff --git a/examples/multiFileProject/multiFileProject.h b/examples/multiFileProject/multiFileProject.h new file mode 100644 index 0000000..8658a5f --- /dev/null +++ b/examples/multiFileProject/multiFileProject.h @@ -0,0 +1,18 @@ +/**************************************************************************************************************************** + multiFileProject.h + For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc) + + AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer + + Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest) + + Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#pragma once + +// Can be included as many times as necessary, without `Multiple Definitions` Linker Error +#include "AsyncHTTPRequest_Generic.hpp" diff --git a/examples/multiFileProject/multiFileProject.ino b/examples/multiFileProject/multiFileProject.ino new file mode 100644 index 0000000..4936ee1 --- /dev/null +++ b/examples/multiFileProject/multiFileProject.ino @@ -0,0 +1,47 @@ +/**************************************************************************************************************************** + multiFileProject.ino + For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc) + + AsyncHTTPRequest_Generic is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer + + Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest) + + Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#if !( defined(ESP8266) || defined(ESP32) || \ + ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \ + defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \ + defined(STM32WB) || defined(STM32MP1) ) ) + #error This code is intended to run on the ESP8266, ESP32 or STM32 platform! Please check your Tools->Board setting. +#endif + +#include "multiFileProject.h" + +// Can be included as many times as necessary, without `Multiple Definitions` Linker Error +#include "AsyncHTTPRequest_Generic.h" + +void setup() +{ + Serial.begin(115200); + while (!Serial); + + Serial.println("\nStart multiFileProject"); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); + +#if defined(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + if (ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT < ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET); + } +#endif +} + +void loop() +{ + // put your main code here, to run repeatedly: +} diff --git a/platformio/platformio.ini b/platformio/platformio.ini index 10c9b19..390f397 100644 --- a/platformio/platformio.ini +++ b/platformio/platformio.ini @@ -43,7 +43,7 @@ lib_deps = ; https://github.com/khoih-prog/STM32AsyncTCP.git ; STM32duino LwIP@>=2.1.2 ; STM32duino STM32Ethernet@>=1.2.0 -; ESPAsync_WiFiManager@>=1.10.0 +; ESPAsync_WiFiManager@>=1.11.0 ; LittleFS_esp32@>=1.0.6 ; WebServer_WT32_ETH01@>=1.4.1 ; PlatformIO 5.x @@ -53,7 +53,7 @@ lib_deps = ; https://github.com/khoih-prog/STM32AsyncTCP.git ; stm32duino/STM32duino LwIP@>=2.1.2 ; stm32duino/STM32duino STM32Ethernet@>=1.2.0 - khoih-prog/ESPAsync_WiFiManager@>=1.10.0 + khoih-prog/ESPAsync_WiFiManager@>=1.11.0 lorol/LittleFS_esp32@>=1.0.6 ; khoih-prog/WebServer_WT32_ETH01@>=1.4.1 diff --git a/src/AsyncHTTPRequest_Debug_Generic.h b/src/AsyncHTTPRequest_Debug_Generic.h index beefe8f..a6f498d 100644 --- a/src/AsyncHTTPRequest_Debug_Generic.h +++ b/src/AsyncHTTPRequest_Debug_Generic.h @@ -17,7 +17,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . - Version: 1.5.0 + Version: 1.6.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -36,6 +36,7 @@ 1.4.0 K Hoang 23/11/2021 Fix crashing bug when request a non-existing IP 1.4.1 K Hoang 29/11/2021 Auto detect ESP32 core version and improve connection time for WT32_ETH01 1.5.0 K Hoang 30/12/2021 Fix `multiple-definitions` linker error + 1.6.0 K Hoang 23/01/2022 Enable compatibility with old code to include only AsyncHTTPRequest_Generic.h *****************************************************************************************************************************/ #pragma once diff --git a/src/AsyncHTTPRequest_Generic.h b/src/AsyncHTTPRequest_Generic.h index 844c349..38c9351 100644 --- a/src/AsyncHTTPRequest_Generic.h +++ b/src/AsyncHTTPRequest_Generic.h @@ -17,7 +17,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . - Version: 1.5.0 + Version: 1.6.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -36,6 +36,7 @@ 1.4.0 K Hoang 23/11/2021 Fix crashing bug when request a non-existing IP 1.4.1 K Hoang 29/11/2021 Auto detect ESP32 core version and improve connection time for WT32_ETH01 1.5.0 K Hoang 30/12/2021 Fix `multiple-definitions` linker error + 1.6.0 K Hoang 23/01/2022 Enable compatibility with old code to include only AsyncHTTPRequest_Generic.h *****************************************************************************************************************************/ #pragma once @@ -43,383 +44,7 @@ #ifndef ASYNC_HTTP_REQUEST_GENERIC_H #define ASYNC_HTTP_REQUEST_GENERIC_H -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.5.0" - -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MAJOR 1 -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MINOR 5 -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_PATCH 0 - -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT 1005000 - -#include - -#include "AsyncHTTPRequest_Debug_Generic.h" - -#ifndef DEBUG_IOTA_PORT - #define DEBUG_IOTA_PORT Serial -#endif - -#ifdef DEBUG_IOTA_HTTP - #define DEBUG_IOTA_HTTP_SET true -#else - #define DEBUG_IOTA_HTTP_SET false -#endif - - -// KH add -#define SAFE_DELETE(object) if (object) { delete object;} -#define SAFE_DELETE_ARRAY(object) if (object) { delete[] object;} - -#if ESP32 - - #include - - // KH mod - #define MUTEX_LOCK_NR if (xSemaphoreTakeRecursive(threadLock,portMAX_DELAY) != pdTRUE) { return;} - #define MUTEX_LOCK(returnVal) if (xSemaphoreTakeRecursive(threadLock,portMAX_DELAY) != pdTRUE) { return returnVal;} - - #define _AHTTP_lock xSemaphoreTakeRecursive(threadLock,portMAX_DELAY) - #define _AHTTP_unlock xSemaphoreGiveRecursive(threadLock) - -#elif ESP8266 - - #include - - #define MUTEX_LOCK_NR - #define MUTEX_LOCK(returnVal) - - #define _AHTTP_lock - #define _AHTTP_unlock - -#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \ - defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \ - defined(STM32WB) || defined(STM32MP1) ) - - #include "STM32AsyncTCP.h" - - #define MUTEX_LOCK_NR - #define MUTEX_LOCK(returnVal) - #define _AHTTP_lock - #define _AHTTP_unlock - -#endif - -#include - -// Merge xbuf -//////////////////////////////////////////////////////////////////////////// - -struct xseg -{ - xseg *next; - uint8_t data[]; -}; - -class xbuf: public Print -{ - public: - - xbuf(const uint16_t segSize = 64); - virtual ~xbuf(); - - size_t write(const uint8_t); - size_t write(const char*); - size_t write(const uint8_t*, const size_t); - size_t write(xbuf*, const size_t); - size_t write(const String& string); - size_t available(); - int indexOf(const char, const size_t begin = 0); - int indexOf(const char*, const size_t begin = 0); - uint8_t read(); - size_t read(uint8_t*, size_t); - String readStringUntil(const char); - String readStringUntil(const char*); - String readString(int); - - String readString() - { - return readString(available()); - } - - void flush(); - - uint8_t peek(); - size_t peek(uint8_t*, const size_t); - - String peekStringUntil(const char target) - { - return peekString(indexOf(target, 0)); - } - - String peekStringUntil(const char* target) - { - return peekString(indexOf(target, 0)); - } - - String peekString() - { - return peekString(_used); - } - - String peekString(int); - - /* In addition to the above functions, - the following inherited functions from the Print class are available. - - size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3))); - size_t printf_P(PGM_P format, ...) __attribute__((format(printf, 2, 3))); - size_t print(const __FlashStringHelper *); - size_t print(const String &); - size_t print(const char[]); - size_t print(char); - size_t print(unsigned char, int = DEC); - size_t print(int, int = DEC); - size_t print(unsigned int, int = DEC); - size_t print(long, int = DEC); - size_t print(unsigned long, int = DEC); - size_t print(double, int = 2); - size_t print(const Printable&); - - size_t println(const __FlashStringHelper *); - size_t println(const String &s); - size_t println(const char[]); - size_t println(char); - size_t println(unsigned char, int = DEC); - size_t println(int, int = DEC); - size_t println(unsigned int, int = DEC); - size_t println(long, int = DEC); - size_t println(unsigned long, int = DEC); - size_t println(double, int = 2); - size_t println(const Printable&); - size_t println(void); - */ - - protected: - - xseg *_head; - xseg *_tail; - uint16_t _used; - uint16_t _free; - uint16_t _offset; - uint16_t _segSize; - - void addSeg(); - void remSeg(); - -}; - -//////////////////////////////////////////////////////////////////////////// - -#define DEBUG_HTTP(format,...) if(_debug){\ - DEBUG_IOTA_PORT.printf("Debug(%3ld): ", millis()-_requestStartTime);\ - DEBUG_IOTA_PORT.printf_P(PSTR(format),##__VA_ARGS__);} - -#define DEFAULT_RX_TIMEOUT 3 // Seconds for timeout - -#define HTTPCODE_CONNECTION_REFUSED (-1) -#define HTTPCODE_SEND_HEADER_FAILED (-2) -#define HTTPCODE_SEND_PAYLOAD_FAILED (-3) -#define HTTPCODE_NOT_CONNECTED (-4) -#define HTTPCODE_CONNECTION_LOST (-5) -#define HTTPCODE_NO_STREAM (-6) -#define HTTPCODE_NO_HTTP_SERVER (-7) -#define HTTPCODE_TOO_LESS_RAM (-8) -#define HTTPCODE_ENCODING (-9) -#define HTTPCODE_STREAM_WRITE (-10) -#define HTTPCODE_TIMEOUT (-11) - -typedef enum -{ - readyStateUnsent = 0, // Client created, open not yet called - readyStateOpened = 1, // open() has been called, connected - readyStateHdrsRecvd = 2, // send() called, response headers available - readyStateLoading = 3, // receiving, partial data available - readyStateDone = 4 // Request complete, all data available. -} reqStates; - -class AsyncHTTPRequest -{ - struct header - { - header* next; - char* name; - char* value; - - header(): next(nullptr), name(nullptr), value(nullptr) - {}; - - ~header() - { - SAFE_DELETE_ARRAY(name) - SAFE_DELETE_ARRAY(value) - SAFE_DELETE(next) - //delete[] name; - //delete[] value; - //delete next; - } - }; - - struct URL - { - char* scheme; - char* user; - char* pwd; - char* host; - int port; - char* path; - char* query; - char* fragment; - - URL(): scheme(nullptr), user(nullptr), pwd(nullptr), host(nullptr), - port(80), path(nullptr), query(nullptr), fragment(nullptr) - {}; - - ~URL() - { - SAFE_DELETE_ARRAY(scheme) - SAFE_DELETE_ARRAY(user) - SAFE_DELETE_ARRAY(pwd) - SAFE_DELETE_ARRAY(host) - SAFE_DELETE_ARRAY(path) - SAFE_DELETE_ARRAY(query) - SAFE_DELETE_ARRAY(fragment) - } - }; - - typedef std::function readyStateChangeCB; - typedef std::function onDataCB; - - public: - AsyncHTTPRequest(); - ~AsyncHTTPRequest(); - - - //External functions in typical order of use: - //__________________________________________________________________________________________________________*/ - void setDebug(bool); // Turn debug message on/off - bool debug(); // is debug on or off? - - bool open(const char* /*GET/POST*/, const char* URL); // Initiate a request - void onReadyStateChange(readyStateChangeCB, void* arg = 0); // Optional event handler for ready state change - // or you can simply poll readyState() - void setTimeout(int); // overide default timeout (seconds) - - void setReqHeader(const char* name, const char* value); // add a request header - void setReqHeader(const char* name, int32_t value); // overload to use integer value - -#if (ESP32 || ESP8266) - void setReqHeader(const char* name, const __FlashStringHelper* value); - void setReqHeader(const __FlashStringHelper *name, const char* value); - void setReqHeader(const __FlashStringHelper *name, const __FlashStringHelper* value); - void setReqHeader(const __FlashStringHelper *name, int32_t value); -#endif - - bool send(); // Send the request (GET) - bool send(const String& body); // Send the request (POST) - bool send(const char* body); // Send the request (POST) - bool send(const uint8_t* buffer, size_t len); // Send the request (POST) (binary data?) - bool send(xbuf* body, size_t len); // Send the request (POST) data in an xbuf - void abort(); // Abort the current operation - - reqStates readyState(); // Return the ready state - - int respHeaderCount(); // Retrieve count of response headers - char* respHeaderName(int index); // Return header name by index - char* respHeaderValue(int index); // Return header value by index - char* respHeaderValue(const char* name); // Return header value by name - - bool respHeaderExists(const char* name); // Does header exist by name? - -#if (ESP32 || ESP8266) - char* respHeaderValue(const __FlashStringHelper *name); - bool respHeaderExists(const __FlashStringHelper *name); -#endif - - String headers(); // Return all headers as String - - void onData(onDataCB, void* arg = 0); // Notify when min data is available - size_t available(); // response available - size_t responseLength(); // indicated response length or sum of chunks to date - int responseHTTPcode(); // HTTP response code or (negative) error code - String responseText(); // response (whole* or partial* as string) - - char* responseLongText(); // response long (whole* or partial* as string) - - size_t responseRead(uint8_t* buffer, size_t len); // Read response into buffer - uint32_t elapsedTime(); // Elapsed time of in progress transaction or last completed (ms) - String version(); // Version of AsyncHTTPRequest - //___________________________________________________________________________________________________________________________________ - - private: - - // New in v1.1.1 - bool _requestReadyToSend; - ////// - - // New in v1.1.0 - typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod; - - HTTPmethod _HTTPmethod; - - const char* _HTTPmethodStringwithSpace[HTTPmethodMAX] = {"GET ", "POST ", "PUT ", "PATCH ", "DELETE ", "HEAD "}; - ////// - - reqStates _readyState; - - int16_t _HTTPcode; // HTTP response code or (negative) exception code - bool _chunked; // Processing chunked response - bool _debug; // Debug state - uint32_t _timeout; // Default or user overide RxTimeout in seconds - uint32_t _lastActivity; // Time of last activity - uint32_t _requestStartTime; // Time last open() issued - uint32_t _requestEndTime; // Time of last disconnect - URL* _URL; // -> URL data structure - char* _connectedHost; // Host when connected - int _connectedPort; // Port when connected - AsyncClient* _client; // ESPAsyncTCP AsyncClient instance - size_t _contentLength; // content-length header value or sum of chunk headers - size_t _contentRead; // number of bytes retrieved by user since last open() - readyStateChangeCB _readyStateChangeCB; // optional callback for readyState change - void* _readyStateChangeCBarg; // associated user argument - onDataCB _onDataCB; // optional callback when data received - void* _onDataCBarg; // associated user argument - -#ifdef ESP32 - SemaphoreHandle_t threadLock; -#endif - - // request and response String buffers and header list (same queue for request and response). - - xbuf* _request; // Tx data buffer - xbuf* _response; // Rx data buffer for headers - xbuf* _chunks; // First stage for chunked response - header* _headers; // request or (readyState > readyStateHdrsRcvd) response headers - - // Protected functions - - header* _addHeader(const char*, const char*); - header* _getHeader(const char*); - header* _getHeader(int); - bool _buildRequest(); - bool _parseURL(const char*); - bool _parseURL(const String& url); - void _processChunks(); - bool _connect(); - size_t _send(); - void _setReadyState(reqStates); - -#if (ESP32 || ESP8266) - char* _charstar(const __FlashStringHelper *str); -#endif - - // callbacks - - void _onConnect(AsyncClient*); - void _onDisconnect(AsyncClient*); - void _onData(void*, size_t); - void _onError(AsyncClient*, int8_t); - void _onPoll(AsyncClient*); - bool _collectHeaders(); -}; +#include "AsyncHTTPRequest_Generic.hpp" +#include "AsyncHTTPRequest_Impl_Generic.h" #endif // ASYNC_HTTP_REQUEST_GENERIC_H diff --git a/src/AsyncHTTPRequest_Generic.hpp b/src/AsyncHTTPRequest_Generic.hpp new file mode 100644 index 0000000..318dac2 --- /dev/null +++ b/src/AsyncHTTPRequest_Generic.hpp @@ -0,0 +1,426 @@ +/**************************************************************************************************************************** + AsyncHTTPRequest_Generic.hpp - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet + + For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc) + + AsyncHTTPRequest_STM32 is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer + + Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest) + + Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic + Licensed under MIT license + + Copyright (C) <2018> + This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License + as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with this program. If not, see . + + Version: 1.6.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc). + 1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code. + 1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof + 1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods + 1.1.1 K Hoang 24/12/2020 Prevent crash if request and/or method not correct. + 1.1.2 K Hoang 11/02/2021 Rename _lock and _unlock to avoid conflict with AsyncWebServer library + 1.1.3 K Hoang 25/02/2021 Fix non-persistent Connection header bug + 1.1.4 K Hoang 21/03/2021 Fix `library.properties` dependency + 1.1.5 K Hoang 22/03/2021 Fix dependency on STM32AsyncTCP Library + 1.2.0 K Hoang 11/04/2021 Add support to LAN8720 using STM32F4 or STM32F7 + 1.3.0 K Hoang 09/07/2021 Add support to WT32_ETH01 (ESP32 + LAN8720) boards + 1.3.1 K Hoang 09/10/2021 Update `platform.ini` and `library.json` + 1.4.0 K Hoang 23/11/2021 Fix crashing bug when request a non-existing IP + 1.4.1 K Hoang 29/11/2021 Auto detect ESP32 core version and improve connection time for WT32_ETH01 + 1.5.0 K Hoang 30/12/2021 Fix `multiple-definitions` linker error + 1.6.0 K Hoang 23/01/2022 Enable compatibility with old code to include only AsyncHTTPRequest_Generic.h + *****************************************************************************************************************************/ + +#pragma once + +#ifndef ASYNC_HTTP_REQUEST_GENERIC_HPP +#define ASYNC_HTTP_REQUEST_GENERIC_HPP + +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.6.0" + +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MAJOR 1 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MINOR 6 +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_PATCH 0 + +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT 1006000 + +#include + +#include "AsyncHTTPRequest_Debug_Generic.h" + +#ifndef DEBUG_IOTA_PORT + #define DEBUG_IOTA_PORT Serial +#endif + +#ifdef DEBUG_IOTA_HTTP + #define DEBUG_IOTA_HTTP_SET true +#else + #define DEBUG_IOTA_HTTP_SET false +#endif + + +// KH add +#define SAFE_DELETE(object) if (object) { delete object;} +#define SAFE_DELETE_ARRAY(object) if (object) { delete[] object;} + +#if ESP32 + + #include + + // KH mod + #define MUTEX_LOCK_NR if (xSemaphoreTakeRecursive(threadLock,portMAX_DELAY) != pdTRUE) { return;} + #define MUTEX_LOCK(returnVal) if (xSemaphoreTakeRecursive(threadLock,portMAX_DELAY) != pdTRUE) { return returnVal;} + + #define _AHTTP_lock xSemaphoreTakeRecursive(threadLock,portMAX_DELAY) + #define _AHTTP_unlock xSemaphoreGiveRecursive(threadLock) + +#elif ESP8266 + + #include + + #define MUTEX_LOCK_NR + #define MUTEX_LOCK(returnVal) + + #define _AHTTP_lock + #define _AHTTP_unlock + +#elif ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \ + defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \ + defined(STM32WB) || defined(STM32MP1) ) + + #include "STM32AsyncTCP.h" + + #define MUTEX_LOCK_NR + #define MUTEX_LOCK(returnVal) + #define _AHTTP_lock + #define _AHTTP_unlock + +#endif + +#include + +// Merge xbuf +//////////////////////////////////////////////////////////////////////////// + +struct xseg +{ + xseg *next; + uint8_t data[]; +}; + +class xbuf: public Print +{ + public: + + xbuf(const uint16_t segSize = 64); + virtual ~xbuf(); + + size_t write(const uint8_t); + size_t write(const char*); + size_t write(const uint8_t*, const size_t); + size_t write(xbuf*, const size_t); + size_t write(const String& string); + size_t available(); + int indexOf(const char, const size_t begin = 0); + int indexOf(const char*, const size_t begin = 0); + uint8_t read(); + size_t read(uint8_t*, size_t); + String readStringUntil(const char); + String readStringUntil(const char*); + String readString(int); + + String readString() + { + return readString(available()); + } + + void flush(); + + uint8_t peek(); + size_t peek(uint8_t*, const size_t); + + String peekStringUntil(const char target) + { + return peekString(indexOf(target, 0)); + } + + String peekStringUntil(const char* target) + { + return peekString(indexOf(target, 0)); + } + + String peekString() + { + return peekString(_used); + } + + String peekString(int); + + /* In addition to the above functions, + the following inherited functions from the Print class are available. + + size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3))); + size_t printf_P(PGM_P format, ...) __attribute__((format(printf, 2, 3))); + size_t print(const __FlashStringHelper *); + size_t print(const String &); + size_t print(const char[]); + size_t print(char); + size_t print(unsigned char, int = DEC); + size_t print(int, int = DEC); + size_t print(unsigned int, int = DEC); + size_t print(long, int = DEC); + size_t print(unsigned long, int = DEC); + size_t print(double, int = 2); + size_t print(const Printable&); + + size_t println(const __FlashStringHelper *); + size_t println(const String &s); + size_t println(const char[]); + size_t println(char); + size_t println(unsigned char, int = DEC); + size_t println(int, int = DEC); + size_t println(unsigned int, int = DEC); + size_t println(long, int = DEC); + size_t println(unsigned long, int = DEC); + size_t println(double, int = 2); + size_t println(const Printable&); + size_t println(void); + */ + + protected: + + xseg *_head; + xseg *_tail; + uint16_t _used; + uint16_t _free; + uint16_t _offset; + uint16_t _segSize; + + void addSeg(); + void remSeg(); + +}; + +//////////////////////////////////////////////////////////////////////////// + +#define DEBUG_HTTP(format,...) if(_debug){\ + DEBUG_IOTA_PORT.printf("Debug(%3ld): ", millis()-_requestStartTime);\ + DEBUG_IOTA_PORT.printf_P(PSTR(format),##__VA_ARGS__);} + +#define DEFAULT_RX_TIMEOUT 3 // Seconds for timeout + +#define HTTPCODE_CONNECTION_REFUSED (-1) +#define HTTPCODE_SEND_HEADER_FAILED (-2) +#define HTTPCODE_SEND_PAYLOAD_FAILED (-3) +#define HTTPCODE_NOT_CONNECTED (-4) +#define HTTPCODE_CONNECTION_LOST (-5) +#define HTTPCODE_NO_STREAM (-6) +#define HTTPCODE_NO_HTTP_SERVER (-7) +#define HTTPCODE_TOO_LESS_RAM (-8) +#define HTTPCODE_ENCODING (-9) +#define HTTPCODE_STREAM_WRITE (-10) +#define HTTPCODE_TIMEOUT (-11) + +typedef enum +{ + readyStateUnsent = 0, // Client created, open not yet called + readyStateOpened = 1, // open() has been called, connected + readyStateHdrsRecvd = 2, // send() called, response headers available + readyStateLoading = 3, // receiving, partial data available + readyStateDone = 4 // Request complete, all data available. +} reqStates; + +class AsyncHTTPRequest +{ + struct header + { + header* next; + char* name; + char* value; + + header(): next(nullptr), name(nullptr), value(nullptr) + {}; + + ~header() + { + SAFE_DELETE_ARRAY(name) + SAFE_DELETE_ARRAY(value) + SAFE_DELETE(next) + //delete[] name; + //delete[] value; + //delete next; + } + }; + + struct URL + { + char* scheme; + char* user; + char* pwd; + char* host; + int port; + char* path; + char* query; + char* fragment; + + URL(): scheme(nullptr), user(nullptr), pwd(nullptr), host(nullptr), + port(80), path(nullptr), query(nullptr), fragment(nullptr) + {}; + + ~URL() + { + SAFE_DELETE_ARRAY(scheme) + SAFE_DELETE_ARRAY(user) + SAFE_DELETE_ARRAY(pwd) + SAFE_DELETE_ARRAY(host) + SAFE_DELETE_ARRAY(path) + SAFE_DELETE_ARRAY(query) + SAFE_DELETE_ARRAY(fragment) + } + }; + + typedef std::function readyStateChangeCB; + typedef std::function onDataCB; + + public: + AsyncHTTPRequest(); + ~AsyncHTTPRequest(); + + + //External functions in typical order of use: + //__________________________________________________________________________________________________________*/ + void setDebug(bool); // Turn debug message on/off + bool debug(); // is debug on or off? + + bool open(const char* /*GET/POST*/, const char* URL); // Initiate a request + void onReadyStateChange(readyStateChangeCB, void* arg = 0); // Optional event handler for ready state change + // or you can simply poll readyState() + void setTimeout(int); // overide default timeout (seconds) + + void setReqHeader(const char* name, const char* value); // add a request header + void setReqHeader(const char* name, int32_t value); // overload to use integer value + +#if (ESP32 || ESP8266) + void setReqHeader(const char* name, const __FlashStringHelper* value); + void setReqHeader(const __FlashStringHelper *name, const char* value); + void setReqHeader(const __FlashStringHelper *name, const __FlashStringHelper* value); + void setReqHeader(const __FlashStringHelper *name, int32_t value); +#endif + + bool send(); // Send the request (GET) + bool send(const String& body); // Send the request (POST) + bool send(const char* body); // Send the request (POST) + bool send(const uint8_t* buffer, size_t len); // Send the request (POST) (binary data?) + bool send(xbuf* body, size_t len); // Send the request (POST) data in an xbuf + void abort(); // Abort the current operation + + reqStates readyState(); // Return the ready state + + int respHeaderCount(); // Retrieve count of response headers + char* respHeaderName(int index); // Return header name by index + char* respHeaderValue(int index); // Return header value by index + char* respHeaderValue(const char* name); // Return header value by name + + bool respHeaderExists(const char* name); // Does header exist by name? + +#if (ESP32 || ESP8266) + char* respHeaderValue(const __FlashStringHelper *name); + bool respHeaderExists(const __FlashStringHelper *name); +#endif + + String headers(); // Return all headers as String + + void onData(onDataCB, void* arg = 0); // Notify when min data is available + size_t available(); // response available + size_t responseLength(); // indicated response length or sum of chunks to date + int responseHTTPcode(); // HTTP response code or (negative) error code + String responseText(); // response (whole* or partial* as string) + + char* responseLongText(); // response long (whole* or partial* as string) + + size_t responseRead(uint8_t* buffer, size_t len); // Read response into buffer + uint32_t elapsedTime(); // Elapsed time of in progress transaction or last completed (ms) + String version(); // Version of AsyncHTTPRequest + //___________________________________________________________________________________________________________________________________ + + private: + + // New in v1.1.1 + bool _requestReadyToSend; + ////// + + // New in v1.1.0 + typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod; + + HTTPmethod _HTTPmethod; + + const char* _HTTPmethodStringwithSpace[HTTPmethodMAX] = {"GET ", "POST ", "PUT ", "PATCH ", "DELETE ", "HEAD "}; + ////// + + reqStates _readyState; + + int16_t _HTTPcode; // HTTP response code or (negative) exception code + bool _chunked; // Processing chunked response + bool _debug; // Debug state + uint32_t _timeout; // Default or user overide RxTimeout in seconds + uint32_t _lastActivity; // Time of last activity + uint32_t _requestStartTime; // Time last open() issued + uint32_t _requestEndTime; // Time of last disconnect + URL* _URL; // -> URL data structure + char* _connectedHost; // Host when connected + int _connectedPort; // Port when connected + AsyncClient* _client; // ESPAsyncTCP AsyncClient instance + size_t _contentLength; // content-length header value or sum of chunk headers + size_t _contentRead; // number of bytes retrieved by user since last open() + readyStateChangeCB _readyStateChangeCB; // optional callback for readyState change + void* _readyStateChangeCBarg; // associated user argument + onDataCB _onDataCB; // optional callback when data received + void* _onDataCBarg; // associated user argument + +#ifdef ESP32 + SemaphoreHandle_t threadLock; +#endif + + // request and response String buffers and header list (same queue for request and response). + + xbuf* _request; // Tx data buffer + xbuf* _response; // Rx data buffer for headers + xbuf* _chunks; // First stage for chunked response + header* _headers; // request or (readyState > readyStateHdrsRcvd) response headers + + // Protected functions + + header* _addHeader(const char*, const char*); + header* _getHeader(const char*); + header* _getHeader(int); + bool _buildRequest(); + bool _parseURL(const char*); + bool _parseURL(const String& url); + void _processChunks(); + bool _connect(); + size_t _send(); + void _setReadyState(reqStates); + +#if (ESP32 || ESP8266) + char* _charstar(const __FlashStringHelper *str); +#endif + + // callbacks + + void _onConnect(AsyncClient*); + void _onDisconnect(AsyncClient*); + void _onData(void*, size_t); + void _onError(AsyncClient*, int8_t); + void _onPoll(AsyncClient*); + bool _collectHeaders(); +}; + +#endif // ASYNC_HTTP_REQUEST_GENERIC_HPP diff --git a/src/AsyncHTTPRequest_Impl_Generic.h b/src/AsyncHTTPRequest_Impl_Generic.h index 3ae9aa6..3771142 100644 --- a/src/AsyncHTTPRequest_Impl_Generic.h +++ b/src/AsyncHTTPRequest_Impl_Generic.h @@ -17,7 +17,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . - Version: 1.5.0 + Version: 1.6.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -36,6 +36,7 @@ 1.4.0 K Hoang 23/11/2021 Fix crashing bug when request a non-existing IP 1.4.1 K Hoang 29/11/2021 Auto detect ESP32 core version and improve connection time for WT32_ETH01 1.5.0 K Hoang 30/12/2021 Fix `multiple-definitions` linker error + 1.6.0 K Hoang 23/01/2022 Enable compatibility with old code to include only AsyncHTTPRequest_Generic.h *****************************************************************************************************************************/ #pragma once