From 9bf7a201c91637aadebbede3e2afdfeb509b329b Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Thu, 30 Dec 2021 16:40:14 -0500 Subject: [PATCH] v1.5.0 to fix multiple-definitions linker error ### 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) 2. Optimize library code by using `reference-passing` instead of `value-passing` 3. Update all examples --- CONTRIBUTING.md | 10 +- README.md | 240 ++++++----- changelog.md | 7 + .../AsyncCustomHeader_STM32.ino | 16 +- .../AsyncDweetGet_STM32.ino | 20 +- .../AsyncDweetPost_STM32.ino | 20 +- .../AsyncHTTPMultiRequests_ESP.ino | 20 +- .../AsyncHTTPRequest_ESP.ino | 9 +- .../AsyncHTTPRequest_ESP_WiFiManager.ino | 28 +- .../AsyncHTTPRequest_STM32.ino | 16 +- .../AsyncSimpleGET_STM32.ino | 16 +- .../AsyncWebClientRepeating_STM32.ino | 19 +- .../AsyncCustomHeader_STM32_LAN8720.ino | 16 +- .../AsyncDweetGet_STM32_LAN8720.ino | 20 +- .../AsyncDweetPost_STM32_LAN8720.ino | 20 +- .../AsyncHTTPRequest_STM32_LAN8720.ino | 16 +- .../AsyncSimpleGET_STM32_LAN8720.ino | 16 +- .../AsyncWebClientRepeating_STM32_LAN8720.ino | 20 +- .../AsyncHTTPMultiRequests_WT32_ETH01.ino | 17 +- .../AsyncHTTPRequest_WT32_ETH01.ino | 17 +- keywords.txt | 6 + library.json | 2 +- library.properties | 2 +- platformio/platformio.ini | 4 +- src/AsyncHTTPRequest_Debug_Generic.h | 3 +- src/AsyncHTTPRequest_Generic.h | 122 +++++- src/AsyncHTTPRequest_Impl_Generic.h | 395 +++++++++++++++++- 27 files changed, 943 insertions(+), 154 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0ca85aa..f57b4cd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,8 +14,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p Please ensure to specify the following: -* Arduino IDE version (e.g. 1.8.16) or Platform.io version -* `ESP8266`,`ESP32` or `STM32` Core Version (e.g. ESP8266 core v3.0.2, ESP32 v2.0.1 or STM32 v2.1.0) +* Arduino IDE version (e.g. 1.8.19) or Platform.io version +* `ESP8266`,`ESP32` or `STM32` Core Version (e.g. ESP8266 core v3.0.2, ESP32 v2.0.2 or STM32 v2.2.0) * Contextual information (e.g. what you were trying to achieve) * Simplest possible steps to reproduce * Anything that might be relevant in your opinion, such as: @@ -26,10 +26,10 @@ Please ensure to specify the following: ### Example ``` -Arduino IDE version: 1.8.16 -ESP32 Core Version 2.0.1 +Arduino IDE version: 1.8.19 +ESP32 Core Version 2.0.2 OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux +Linux xy-Inspiron-3593 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux Context: I encountered an endless loop while trying to connect to Local WiFi. diff --git a/README.md b/README.md index 898b767..d29198c 100644 --- a/README.md +++ b/README.md @@ -149,16 +149,16 @@ This library is based on, modified from: ## Prerequisites - 1. [`Arduino IDE 1.8.16+` for Arduino](https://www.arduino.cc/en/Main/Software) + 1. [`Arduino IDE 1.8.19+` for Arduino](https://www.arduino.cc/en/Main/Software) 2. [`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/) - 3. [`ESP32 Core 2.0.1+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [Latest stable release ![Release Version](https://img.shields.io/github/release/espressif/arduino-esp32.svg?style=plastic) - 5. [`Arduino Core for STM32 2.1.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for for STM32 using built-in Ethernet LAN8742A. [![GitHub release](https://img.shields.io/github/release/stm32duino/Arduino_Core_STM32.svg)](https://github.com/stm32duino/Arduino_Core_STM32/releases/latest) + 3. [`ESP32 Core 2.0.2+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [Latest stable release ![Release Version](https://img.shields.io/github/release/espressif/arduino-esp32.svg?style=plastic) + 5. [`Arduino Core for STM32 2.2.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for for STM32 using built-in Ethernet LAN8742A. [![GitHub release](https://img.shields.io/github/release/stm32duino/Arduino_Core_STM32.svg)](https://github.com/stm32duino/Arduino_Core_STM32/releases/latest) 6. [`ESPAsyncTCP v1.2.2+`](https://github.com/me-no-dev/ESPAsyncTCP) for ESP8266. 7. [`AsyncTCP v1.1.1+`](https://github.com/me-no-dev/AsyncTCP) for ESP32. 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.9.6+`](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.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) 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) @@ -254,13 +254,22 @@ Thanks to [Roshan](https://github.com/solroshan) to report the issue in [Error e ### HOWTO Fix `Multiple Definitions` Linker Error -The current library implementation, using xyz-Impl.h instead of standard xyz.cpp, possibly creates certain `Multiple Definitions` Linker error in certain use cases. Although it's simple to just modify several lines of code, either in the library or in the application, the library is adding a separate source directory, named src_cpp, besides the standard src directory. +The current library implementation, using `xyz-Impl.h` instead of standard `xyz.cpp`, possibly creates certain `Multiple Definitions` Linker error in certain use cases. -To use the old standard cpp way, just +You can use -1. **Rename the h-only src directory into src_h.** -2. **Then rename the cpp src_cpp directory into src.** -3. Close then reopen the application code in Arduino IDE, etc. to recompile from scratch. +``` +#include //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 + +``` +// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error +#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +``` + +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) --- --- @@ -429,10 +438,16 @@ 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 + // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#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/sstaub/Ticker @@ -490,6 +505,14 @@ void setup(void) Serial.println("\nStart AsyncHTTPRequest_STM32 on " + String(BOARD_NAME)); 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 + // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; @@ -648,44 +671,47 @@ 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.4.1 -AsyncHTTPRequest @ IP : 192.168.2.72 +AsyncHTTPRequest_Generic v1.5.0 +Warning. Must use this example on Version equal or later than : AsyncHTTPRequest_Generic v1.5.0 +AsyncHTTPRequest @ IP : 192.168.2.178 ************************************** -abbreviation: EDT +abbreviation: EST client_ip: aaa.bbb.ccc.ddd -datetime: 2020-09-13T18:22:59.555816-04:00 -day_of_week: 0 -day_of_year: 257 -dst: true -dst_from: 2020-03-08T07:00:00+00:00 -dst_offset: 3600 -dst_until: 2020-11-01T06:00:00+00:00 +datetime: 2021-12-30T13:53:51.012921-05:00 +day_of_week: 4 +day_of_year: 364 +dst: false +dst_from: +dst_offset: 0 +dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1600035779 -utc_datetime: 2020-09-13T22:22:59.555816+00:00 -utc_offset: -04:00 -week_number: 37 +unixtime: 1640890431 +utc_datetime: 2021-12-30T18:53:51.012921+00:00 +utc_offset: -05:00 +week_number: 52 +************************************** ************************************** -abbreviation: EDT +abbreviation: EST client_ip: aaa.bbb.ccc.ddd -datetime: 2020-09-13T18:27:57.586325-04:00 -day_of_week: 0 -day_of_year: 257 -dst: true -dst_from: 2020-03-08T07:00:00+00:00 -dst_offset: 3600 -dst_until: 2020-11-01T06:00:00+00:00 +datetime: 2021-12-30T13:54:50.320646-05:00 +day_of_week: 4 +day_of_year: 364 +dst: false +dst_from: +dst_offset: 0 +dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1600036077 -utc_datetime: 2020-09-13T22:27:57.586325+00:00 -utc_offset: -04:00 -week_number: 37 -************************************** +unixtime: 1640890490 +utc_datetime: 2021-12-30T18:54:50.320646+00:00 +utc_offset: -05:00 +week_number: 52 + ``` --- @@ -694,28 +720,28 @@ week_number: 37 ``` Starting AsyncHTTPRequest_ESP_WiFiManager using LittleFS on ESP8266_NODEMCU -AsyncHTTPRequest_Generic v1.4.1 +AsyncHTTPRequest_Generic v1.5.0 Stored: SSID = HueNet1, Pass = 12345678 Got stored Credentials. Timeout 120s ConnectMultiWiFi in setup After waiting 3.43 secs more in setup(), connection result is connected. Local IP: 192.168.2.186 H ************************************** -abbreviation: EDT +abbreviation: EST client_ip: aaa.bbb.ccc.ddd -datetime: 2020-09-13T19:35:37.951609-04:00 -day_of_week: 0 -day_of_year: 257 -dst: true -dst_from: 2020-03-08T07:00:00+00:00 -dst_offset: 3600 -dst_until: 2020-11-01T06:00:00+00:00 +datetime: 2021-12-30T13:54:50.320646-05:00 +day_of_week: 4 +day_of_year: 364 +dst: false +dst_from: +dst_offset: 0 +dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1600040137 -utc_datetime: 2020-09-13T23:35:37.951609+00:00 -utc_offset: -04:00 -week_number: 37 +unixtime: 1640890490 +utc_datetime: 2021-12-30T18:54:50.320646+00:00 +utc_offset: -05:00 +week_number: 52 ************************************** HHHHHH @@ -727,46 +753,46 @@ HHHHHH ``` Starting AsyncHTTPRequest_ESP_WiFiManager using SPIFFS on ESP32_DEV -AsyncHTTPRequest_Generic v1.4.1 +AsyncHTTPRequest_Generic v1.5.0 Stored: SSID = HueNet1, Pass = 12345678 Got stored Credentials. Timeout 120s ConnectMultiWiFi in setup After waiting 2.35 secs more in setup(), connection result is connected. Local IP: 192.168.2.232 H ************************************** -abbreviation: EDT +abbreviation: EST client_ip: aaa.bbb.ccc.ddd -datetime: 2020-09-13T19:37:02.118166-04:00 -day_of_week: 0 -day_of_year: 257 -dst: true -dst_from: 2020-03-08T07:00:00+00:00 -dst_offset: 3600 -dst_until: 2020-11-01T06:00:00+00:00 +datetime: 2021-12-30T13:54:50.320646-05:00 +day_of_week: 4 +day_of_year: 364 +dst: false +dst_from: +dst_offset: 0 +dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1600040222 -utc_datetime: 2020-09-13T23:37:02.118166+00:00 -utc_offset: -04:00 -week_number: 37 +unixtime: 1640890490 +utc_datetime: 2021-12-30T18:54:50.320646+00:00 +utc_offset: -05:00 +week_number: 52 ************************************** HHHHHHHHH HHHHHHHHHH HHHHHHHHHH H ************************************** -abbreviation: EDT +abbreviation: EST client_ip: aaa.bbb.ccc.ddd -datetime: 2020-09-13T19:42:01.507586-04:00 -day_of_week: 0 -day_of_year: 257 -dst: true -dst_from: 2020-03-08T07:00:00+00:00 -dst_offset: 3600 -dst_until: 2020-11-01T06:00:00+00:00 +datetime: 2021-12-30T13:56:49.026396-05:00 +day_of_week: 4 +day_of_year: 364 +dst: false +dst_from: +dst_offset: 0 +dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1600040521 -utc_datetime: 2020-09-13T23:42:01.507586+00:00 -utc_offset: -04:00 -week_number: 37 +unixtime: 1640890609 +utc_datetime: 2021-12-30T18:56:49.026396+00:00 +utc_offset: -05:00 +week_number: 52 ************************************** HHHHHHHHH HHHHHHHHHH HHHHHHHHHH @@ -778,27 +804,28 @@ HHHHHHHHH HHHHHHHHHH HHHHHHHHHH ``` Starting AsyncHTTPRequest_ESP using ESP8266_NODEMCU -AsyncHTTPRequest_Generic v1.4.1 +AsyncHTTPRequest_Generic v1.5.0 Connecting to WiFi SSID: HueNet1 ........... HTTP WebServer is @ IP : 192.168.2.81 ************************************** -abbreviation: EDT +abbreviation: EST client_ip: aaa.bbb.ccc.ddd -datetime: 2020-09-13T19:56:28.295033-04:00 -day_of_week: 0 -day_of_year: 257 -dst: true -dst_from: 2020-03-08T07:00:00+00:00 -dst_offset: 3600 -dst_until: 2020-11-01T06:00:00+00:00 +datetime: 2021-12-30T14:02:45.199491-05:00 +day_of_week: 4 +day_of_year: 364 +dst: false +dst_from: +dst_offset: 0 +dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1600041388 -utc_datetime: 2020-09-13T23:56:28.295033+00:00 -utc_offset: -04:00 -week_number: 37 +unixtime: 1640890965 +utc_datetime: 2021-12-30T19:02:45.199491+00:00 +utc_offset: -05:00 +week_number: 52 + ************************************** HHHHHHHHH HHHHHHHHHH HHHHHHHHHH H ``` @@ -810,7 +837,7 @@ HHHHHHHHH HHHHHHHHHH HHHHHHHHHH H ``` Start AsyncWebClientRepeating_STM32 on NUCLEO_F767ZI -AsyncHTTPRequest_Generic v1.4.1 +AsyncHTTPRequest_Generic v1.5.0 AsyncHTTPRequest @ IP : 192.168.2.72 ************************************** @@ -865,7 +892,7 @@ AsyncHTTPRequest @ IP : 192.168.2.72 ``` Start AsyncWebClientRepeating_STM32_LAN8720 on BLACK_F407VE -AsyncHTTPRequest_Generic v1.4.1 +AsyncHTTPRequest_Generic v1.5.0 AsyncHTTPRequest @ IP : 192.168.2.150 @@ -921,7 +948,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.4.1 +AsyncHTTPRequest_Generic v1.5.0 ETH MAC: A8:03:2A:A1:61:73, IPv4: 192.168.2.232, FULL_DUPLEX, 100Mbps AsyncHTTPRequest @ IP : 192.168.2.232 @@ -947,26 +974,27 @@ H ``` Starting AsyncHTTPRequest_WT32_ETH01 on ESP32_DEV with ETH_PHY_LAN8720 WebServer_WT32_ETH01 v1.4.1 -AsyncHTTPRequest_Generic v1.4.1 +AsyncHTTPRequest_Generic v1.5.0 ETH MAC: A8:03:2A:A1:61:73, IPv4: 192.168.2.232, FULL_DUPLEX, 100Mbps AsyncHTTPRequest @ IP : 192.168.2.232 ************************************** -abbreviation: EDT -client_ip: 45.72.193.56 -datetime: 2021-07-09T23:16:50.506413-04:00 -day_of_week: 5 -day_of_year: 190 -dst: true -dst_from: 2021-03-14T07:00:00+00:00 -dst_offset: 3600 -dst_until: 2021-11-07T06:00:00+00:00 +abbreviation: EST +client_ip: aaa.bbb.ccc.ddd +datetime: 2021-12-30T14:08:41.290808-05:00 +day_of_week: 4 +day_of_year: 364 +dst: false +dst_from: +dst_offset: 0 +dst_until: raw_offset: -18000 timezone: America/Toronto -unixtime: 1625887010 -utc_datetime: 2021-07-10T03:16:50.506413+00:00 -utc_offset: -04:00 -week_number: 27 +unixtime: 1640891321 +utc_datetime: 2021-12-30T19:08:41.290808+00:00 +utc_offset: -05:00 +week_number: 52 + ************************************** ``` @@ -1021,6 +1049,8 @@ Submit issues to: [AsyncHTTPRequest_Generic issues](https://github.com/khoih-pro 6. Add support to **WT32_ETH01** using ESP32-based boards and LAN8720 Ethernet 7. Auto detect ESP32 core to use for WT32_ETH01 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` --- --- diff --git a/changelog.md b/changelog.md index c985213..02cc341 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ ## Table of Contents * [Changelog](#changelog) + * [Releases v1.5.0](#releases-v150) * [Releases v1.4.1](#releases-v141) * [Releases v1.4.0](#releases-v140) * [Releases v1.3.1](#releases-v131) @@ -32,6 +33,12 @@ ## Changelog +### 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) +2. Optimize library code by using `reference-passing` instead of `value-passing` +3. Update all examples + #### Releases v1.4.1 ##### Warning: Releases v1.4.1+ can be used and autodetect ESP32 core v2.0.0+ or v1.0.6- for WT32_ETH01 diff --git a/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino b/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino index 3e3899c..19e9d94 100644 --- a/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino +++ b/examples/AsyncCustomHeader_STM32/AsyncCustomHeader_STM32.ino @@ -24,10 +24,16 @@ //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 + // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#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/sstaub/Ticker @@ -86,6 +92,14 @@ void setup(void) Serial.println("\nStart AsyncCustomHeader_STM32 on " + String(BOARD_NAME)); 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 + // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; diff --git a/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino b/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino index 80f1358..fe7d848 100644 --- a/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino +++ b/examples/AsyncDweetGet_STM32/AsyncDweetGet_STM32.ino @@ -35,10 +35,16 @@ const char GET_ServerAddress[] = "dweet.io"; // use your own thing name here String dweetName = "/dweet/for/currentSecond?second="; -// 60s = 60 seconds to not flooding the server -#define HTTP_REQUEST_INTERVAL_MS 60000 +#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 +// 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/sstaub/Ticker @@ -134,6 +140,14 @@ void setup(void) Serial.println("\nStart AsyncDweetGET_STM32 on " + String(BOARD_NAME)); 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 + // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; diff --git a/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino b/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino index 4d7bf79..1fd09fa 100644 --- a/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino +++ b/examples/AsyncDweetPost_STM32/AsyncDweetPost_STM32.ino @@ -29,10 +29,16 @@ const char POST_ServerAddress[] = "dweet.io"; // use your own thing name here String dweetName = "/dweet/for/pinA0-Read?"; -// 60s = 60 seconds to not flooding the server -#define HTTP_REQUEST_INTERVAL_MS 10000 +#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 +// 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/sstaub/Ticker @@ -133,6 +139,14 @@ void setup(void) Serial.println("\nStart AsyncDweetPOST_STM32 on " + String(BOARD_NAME)); 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 + // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; diff --git a/examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino b/examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino index 338ebeb..62efc63 100644 --- a/examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino +++ b/examples/AsyncHTTPMultiRequests_ESP/AsyncHTTPMultiRequests_ESP.ino @@ -44,6 +44,12 @@ #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 + // Level from 0-4 #define ASYNC_HTTP_DEBUG_PORT Serial #define _ASYNC_HTTP_LOGLEVEL_ 1 @@ -65,7 +71,11 @@ const char* password = "your_pass"; #include #endif -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#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 AsyncHTTPRequest request; @@ -172,6 +182,14 @@ void setup() Serial.println("\nStarting AsyncHTTPMultiRequests using " + String(ARDUINO_BOARD)); 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 WiFi.mode(WIFI_STA); diff --git a/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino b/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino index ab41301..359f581 100644 --- a/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino +++ b/examples/AsyncHTTPRequest_ESP/AsyncHTTPRequest_ESP.ino @@ -65,7 +65,14 @@ const char* password = "your_pass"; #include #endif -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#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 + +// 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 request; diff --git a/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino b/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino index e91c9eb..99140a0 100644 --- a/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino +++ b/examples/AsyncHTTPRequest_ESP_WiFiManager/AsyncHTTPRequest_ESP_WiFiManager.ino @@ -46,6 +46,9 @@ #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. #endif +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 + // Level from 0-4 #define ASYNC_HTTP_DEBUG_PORT Serial @@ -238,12 +241,19 @@ IPAddress APStaticSN = IPAddress(255, 255, 255, 0); #include //https://github.com/khoih-prog/ESPAsync_WiFiManager +// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error +#include //https://github.com/khoih-prog/ESPAsync_WiFiManager + #define HTTP_PORT 80 AsyncWebServer webServer(HTTP_PORT); DNSServer dnsServer; -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#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 AsyncHTTPRequest request; @@ -549,6 +559,22 @@ void setup() Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION); Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION); +#if defined(ESP_WIFIMANAGER_VERSION_MIN) + if (ESP_WIFIMANAGER_VERSION_INT < ESP_WIFIMANAGER_VERSION_MIN) + { + Serial.print("Warning. Must use this example on Version equal or later than : "); + Serial.println(ESP_WIFIMANAGER_VERSION_MIN_TARGET); + } +#endif + +#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 + if (FORMAT_FILESYSTEM) FileFS.format(); diff --git a/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino b/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino index 47ab244..05df4ab 100644 --- a/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino +++ b/examples/AsyncHTTPRequest_STM32/AsyncHTTPRequest_STM32.ino @@ -42,10 +42,16 @@ #include "defines.h" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 + // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#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/sstaub/Ticker @@ -103,6 +109,14 @@ void setup(void) Serial.println("\nStart AsyncHTTPRequest_STM32 on " + String(BOARD_NAME)); 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 + // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; diff --git a/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino b/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino index 76b2e27..ad6f27f 100644 --- a/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino +++ b/examples/AsyncSimpleGET_STM32/AsyncSimpleGET_STM32.ino @@ -24,10 +24,16 @@ //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 + // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#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/sstaub/Ticker @@ -84,6 +90,14 @@ void setup(void) Serial.println("\nStart AsyncSimpleGET_STM32 on " + String(BOARD_NAME)); 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 + // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; diff --git a/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino b/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino index f65c000..3b74ef5 100644 --- a/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino +++ b/examples/AsyncWebClientRepeating_STM32/AsyncWebClientRepeating_STM32.ino @@ -26,10 +26,16 @@ const char GET_ServerAddress[] = "arduino.cc"; // GET location String GET_Location = "/asciilogo.txt"; -// 60s = 60 seconds to not flooding the server -#define HTTP_REQUEST_INTERVAL_MS 60000 +#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 +// 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/sstaub/Ticker @@ -86,6 +92,13 @@ void setup(void) Serial.println("\nStart AsyncWebClientRepeating_STM32 on " + String(BOARD_NAME)); 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 // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; 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 87598b1..65cafca 100644 --- a/examples/STM32_LAN8720/AsyncCustomHeader_STM32_LAN8720/AsyncCustomHeader_STM32_LAN8720.ino +++ b/examples/STM32_LAN8720/AsyncCustomHeader_STM32_LAN8720/AsyncCustomHeader_STM32_LAN8720.ino @@ -24,10 +24,16 @@ //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 + // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#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/sstaub/Ticker @@ -86,6 +92,14 @@ void setup(void) Serial.println("\nStart AsyncCustomHeader_STM32_LAN8720 on " + String(BOARD_NAME)); 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 + // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; 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 704266e..b1ecc86 100644 --- a/examples/STM32_LAN8720/AsyncDweetGet_STM32_LAN8720/AsyncDweetGet_STM32_LAN8720.ino +++ b/examples/STM32_LAN8720/AsyncDweetGet_STM32_LAN8720/AsyncDweetGet_STM32_LAN8720.ino @@ -35,10 +35,16 @@ const char GET_ServerAddress[] = "dweet.io"; // use your own thing name here String dweetName = "/dweet/for/currentSecond?second="; -// 60s = 60 seconds to not flooding the server -#define HTTP_REQUEST_INTERVAL_MS 60000 +#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 +// 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/sstaub/Ticker @@ -134,6 +140,14 @@ void setup(void) Serial.println("\nStart AsyncDweetGET_STM32_LAN8720 on " + String(BOARD_NAME)); 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 + // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; 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 908e7cd..f07e660 100644 --- a/examples/STM32_LAN8720/AsyncDweetPost_STM32_LAN8720/AsyncDweetPost_STM32_LAN8720.ino +++ b/examples/STM32_LAN8720/AsyncDweetPost_STM32_LAN8720/AsyncDweetPost_STM32_LAN8720.ino @@ -29,10 +29,16 @@ const char POST_ServerAddress[] = "dweet.io"; // use your own thing name here String dweetName = "/dweet/for/pinA0-Read?"; -// 60s = 60 seconds to not flooding the server -#define HTTP_REQUEST_INTERVAL_MS 10000 +#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 +// 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/sstaub/Ticker @@ -133,6 +139,14 @@ void setup(void) Serial.println("\nStart AsyncDweetPOST_STM32_LAN8720 on " + String(BOARD_NAME)); 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 + // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; 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 e3dba63..6626cac 100644 --- a/examples/STM32_LAN8720/AsyncHTTPRequest_STM32_LAN8720/AsyncHTTPRequest_STM32_LAN8720.ino +++ b/examples/STM32_LAN8720/AsyncHTTPRequest_STM32_LAN8720/AsyncHTTPRequest_STM32_LAN8720.ino @@ -42,10 +42,16 @@ #include "defines.h" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN_TARGET "AsyncHTTPRequest_Generic v1.5.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION_MIN 1005000 + // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#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/sstaub/Ticker @@ -103,6 +109,14 @@ void setup(void) Serial.println("\nStart AsyncHTTPRequest_STM32_LAN8720 on " + String(BOARD_NAME)); 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 + // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; 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 bbf014c..22d0ca6 100644 --- a/examples/STM32_LAN8720/AsyncSimpleGET_STM32_LAN8720/AsyncSimpleGET_STM32_LAN8720.ino +++ b/examples/STM32_LAN8720/AsyncSimpleGET_STM32_LAN8720/AsyncSimpleGET_STM32_LAN8720.ino @@ -24,10 +24,16 @@ //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 + // 600s = 10 minutes to not flooding, 60s in testing #define HTTP_REQUEST_INTERVAL_MS 60000 //600000 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#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/sstaub/Ticker @@ -84,6 +90,14 @@ void setup(void) Serial.println("\nStart AsyncSimpleGET_STM32_LAN8720 on " + String(BOARD_NAME)); 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 + // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; 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 0d211e1..7613e34 100644 --- a/examples/STM32_LAN8720/AsyncWebClientRepeating_STM32_LAN8720/AsyncWebClientRepeating_STM32_LAN8720.ino +++ b/examples/STM32_LAN8720/AsyncWebClientRepeating_STM32_LAN8720/AsyncWebClientRepeating_STM32_LAN8720.ino @@ -26,10 +26,16 @@ const char GET_ServerAddress[] = "arduino.cc"; // GET location String GET_Location = "/asciilogo.txt"; -// 60s = 60 seconds to not flooding the server -#define HTTP_REQUEST_INTERVAL_MS 60000 +#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 +// 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/sstaub/Ticker @@ -86,6 +92,14 @@ void setup(void) Serial.println("\nStart AsyncWebClientRepeating_STM32_LAN8720 on " + String(BOARD_NAME)); 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 + // start the ethernet connection and the server // Use random mac uint16_t index = millis() % NUMBER_OF_MAC; 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 56fae77..147cff4 100644 --- a/examples/WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01.ino +++ b/examples/WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01/AsyncHTTPMultiRequests_WT32_ETH01.ino @@ -57,7 +57,14 @@ #include // https://github.com/khoih-prog/WebServer_WT32_ETH01 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#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 + +// 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 request; @@ -184,6 +191,14 @@ void setup() Serial.setDebugOutput(true); +#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 + // To be called before ETH.begin() WT32_ETH01_onEvent(); 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 6ff3ef0..68afe63 100644 --- a/examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01/AsyncHTTPRequest_WT32_ETH01.ino +++ b/examples/WT32_ETH01/AsyncHTTPRequest_WT32_ETH01/AsyncHTTPRequest_WT32_ETH01.ino @@ -57,7 +57,14 @@ #include // https://github.com/khoih-prog/WebServer_WT32_ETH01 -#include // https://github.com/khoih-prog/AsyncHTTPRequest_Generic +#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 + +// 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 request; @@ -150,6 +157,14 @@ void setup() Serial.setDebugOutput(true); +#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 + // To be called before ETH.begin() WT32_ETH01_onEvent(); diff --git a/keywords.txt b/keywords.txt index 4d2c00b..a8b0325 100644 --- a/keywords.txt +++ b/keywords.txt @@ -40,6 +40,12 @@ version KEYWORD2 # Constants (LITERAL1) ####################################### +ASYNC_HTTP_REQUEST_GENERIC_VERSION LITERAL1 +ASYNC_HTTP_REQUEST_GENERIC_VERSION_MAJOR LITERAL1 +ASYNC_HTTP_REQUEST_GENERIC_VERSION_MINOR LITERAL1 +ASYNC_HTTP_REQUEST_GENERIC_VERSION_PATCH LITERAL1 +ASYNC_HTTP_REQUEST_GENERIC_VERSION_INT LITERAL1 + HTTPCODE_CONNECTION_REFUSED LITERAL1 HTTPCODE_SEND_HEADER_FAILED LITERAL1 HTTPCODE_SEND_PAYLOAD_FAILED LITERAL1 diff --git a/library.json b/library.json index 9c8a4ce..4a1ea18 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name":"AsyncHTTPRequest_Generic", - "version": "1.4.1", + "version": "1.5.0", "description":"Simple Async HTTP Request library, supporting GET, POST, PUT, PATCH, DELETE and HEAD, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, AsyncTCP_STM32, etc.. for ESP32 (including ESP32-S2), WT32_ETH01 (ESP32 + LAN8720), ESP8266 and currently STM32 with LAN8720 or built-in LAN8742A Ethernet.", "keywords":"communication, async, tcp, http, ESP8266, ESP32, ESP32-S2, wt32-eth01, ESPAsyncTCP, AsyncTCP, stm32, ethernet, wifi, lan8742a, lan8720, f407ve, nucleo, nucleo-144, stm32f7, stm32f4", "authors": [ diff --git a/library.properties b/library.properties index 030e987..10080bc 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AsyncHTTPRequest_Generic -version=1.4.1 +version=1.5.0 author=Bob Lemaire,Khoi Hoang maintainer=Khoi Hoang license=MIT diff --git a/platformio/platformio.ini b/platformio/platformio.ini index fbaa67d..10c9b19 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.9.6 +; ESPAsync_WiFiManager@>=1.10.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.9.6 + khoih-prog/ESPAsync_WiFiManager@>=1.10.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 8cace28..beefe8f 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.4.1 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -35,6 +35,7 @@ 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 *****************************************************************************************************************************/ #pragma once diff --git a/src/AsyncHTTPRequest_Generic.h b/src/AsyncHTTPRequest_Generic.h index b68d55c..844c349 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.4.1 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -35,6 +35,7 @@ 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 *****************************************************************************************************************************/ #pragma once @@ -42,7 +43,13 @@ #ifndef ASYNC_HTTP_REQUEST_GENERIC_H #define ASYNC_HTTP_REQUEST_GENERIC_H -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.4.1" +#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 @@ -98,7 +105,110 @@ #endif #include -#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);\ @@ -205,7 +315,7 @@ class AsyncHTTPRequest #endif bool send(); // Send the request (GET) - bool send(String body); // Send the request (POST) + 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 @@ -292,7 +402,7 @@ class AsyncHTTPRequest header* _getHeader(int); bool _buildRequest(); bool _parseURL(const char*); - bool _parseURL(String); + bool _parseURL(const String& url); void _processChunks(); bool _connect(); size_t _send(); @@ -312,6 +422,4 @@ class AsyncHTTPRequest bool _collectHeaders(); }; -#include "AsyncHTTPRequest_Impl_Generic.h" - #endif // ASYNC_HTTP_REQUEST_GENERIC_H diff --git a/src/AsyncHTTPRequest_Impl_Generic.h b/src/AsyncHTTPRequest_Impl_Generic.h index fac0b24..3ae9aa6 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.4.1 + Version: 1.5.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -35,6 +35,7 @@ 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 *****************************************************************************************************************************/ #pragma once @@ -44,6 +45,394 @@ #define CANT_SEND_BAD_REQUEST F("Can't send() bad request") +// Merge xbuf +//////////////////////////////////////////////////////////////////////////// + +xbuf::xbuf(const uint16_t segSize) : _head(nullptr), _tail(nullptr), _used(0), _free(0), _offset(0) +{ + _segSize = (segSize + 3) & -4;//((segSize + 3) >> 2) << 2; +} + +//******************************************************************************************************************* +xbuf::~xbuf() +{ + flush(); +} + +//******************************************************************************************************************* +size_t xbuf::write(const uint8_t byte) +{ + return write((uint8_t*) &byte, 1); +} + +//******************************************************************************************************************* +size_t xbuf::write(const char* buf) +{ + return write((uint8_t*)buf, strlen(buf)); +} + +//******************************************************************************************************************* +size_t xbuf::write(const String& string) +{ + return write((uint8_t*)string.c_str(), string.length()); +} + +//******************************************************************************************************************* +size_t xbuf::write(const uint8_t* buf, const size_t len) +{ + size_t supply = len; + + while (supply) + { + if (!_free) + { + addSeg(); + } + + size_t demand = _free < supply ? _free : supply; + memcpy(_tail->data + ((_offset + _used) % _segSize), buf + (len - supply), demand); + _free -= demand; + _used += demand; + supply -= demand; + } + + return len; +} + +//******************************************************************************************************************* +size_t xbuf::write(xbuf* buf, const size_t len) +{ + size_t supply = len; + + if (supply > buf->available()) + { + supply = buf->available(); + } + + size_t read = 0; + + while (supply) + { + if (!_free) + { + addSeg(); + } + + size_t demand = _free < supply ? _free : supply; + read += buf->read(_tail->data + ((_offset + _used) % _segSize), demand); + _free -= demand; + _used += demand; + supply -= demand; + } + + return read; +} + +//******************************************************************************************************************* +uint8_t xbuf::read() +{ + uint8_t byte = 0; + read((uint8_t*) &byte, 1); + + return byte; +} + +//******************************************************************************************************************* +uint8_t xbuf::peek() +{ + uint8_t byte = 0; + peek((uint8_t*) &byte, 1); + + return byte; +} + +//******************************************************************************************************************* +size_t xbuf::read(uint8_t* buf, const size_t len) +{ + size_t read = 0; + + while (read < len && _used) + { + size_t supply = (_offset + _used) > _segSize ? _segSize - _offset : _used; + size_t demand = len - read; + size_t chunk = supply < demand ? supply : demand; + memcpy(buf + read, _head->data + _offset, chunk); + _offset += chunk; + _used -= chunk; + read += chunk; + + if (_offset == _segSize) + { + remSeg(); + _offset = 0; + } + } + + if ( ! _used) + { + flush(); + } + + return read; +} + +//******************************************************************************************************************* +size_t xbuf::peek(uint8_t* buf, const size_t len) +{ + size_t read = 0; + xseg* seg = _head; + size_t offset = _offset; + size_t used = _used; + + while (read < len && used) + { + size_t supply = (offset + used) > _segSize ? _segSize - offset : used; + size_t demand = len - read; + size_t chunk = supply < demand ? supply : demand; + + memcpy(buf + read, seg->data + offset, chunk); + + offset += chunk; + used -= chunk; + read += chunk; + + if (offset == _segSize) + { + seg = seg->next; + offset = 0; + } + } + + return read; +} + +//******************************************************************************************************************* +size_t xbuf::available() +{ + return _used; +} + +//******************************************************************************************************************* +int xbuf::indexOf(const char target, const size_t begin) +{ + char targetstr[2] = " "; + targetstr[0] = target; + + return indexOf(targetstr, begin); +} + +//******************************************************************************************************************* +int xbuf::indexOf(const char* target, const size_t begin) +{ + size_t targetLen = strlen(target); + + if (targetLen > _segSize || targetLen > _used) + return -1; + + size_t searchPos = _offset + begin; + size_t searchEnd = _offset + _used - targetLen; + + if (searchPos > searchEnd) + return -1; + + size_t searchSeg = searchPos / _segSize; + xseg* seg = _head; + + while (searchSeg) + { + seg = seg->next; + searchSeg --; + } + + size_t segPos = searchPos % _segSize; + + while (searchPos <= searchEnd) + { + size_t compLen = targetLen; + + if (compLen <= (_segSize - segPos)) + { + if (memcmp(target, seg->data + segPos, compLen) == 0) + { + return searchPos - _offset; + } + } + else + { + size_t compLen = _segSize - segPos; + + if (memcmp(target, seg->data + segPos, compLen) == 0) + { + compLen = targetLen - compLen; + + if (memcmp(target + targetLen - compLen, seg->next->data, compLen) == 0) + { + return searchPos - _offset; + } + } + } + + searchPos++; + segPos++; + + if (segPos == _segSize) + { + seg = seg->next; + segPos = 0; + } + } + + return -1; +} + +//******************************************************************************************************************* +String xbuf::readStringUntil(const char target) +{ + return readString(indexOf(target) + 1); +} + +//******************************************************************************************************************* +String xbuf::readStringUntil(const char* target) +{ + int index = indexOf(target); + + if (index < 0) + return String(); + + return readString(index + strlen(target)); +} + +//******************************************************************************************************************* +String xbuf::readString(int endPos) +{ + String result; + + if ( ! result.reserve(endPos + 1)) + { + // KH, to remove + AHTTP_LOGDEBUG1("xbuf::readString: can't reserve size = ", endPos + 1); + /////// + + return result; + } + + // KH, to remove + AHTTP_LOGDEBUG1("xbuf::readString: Reserved size = ", endPos + 1); + /////// + + if (endPos > _used) + { + endPos = _used; + } + + if (endPos > 0 && result.reserve(endPos + 1)) + { + while (endPos--) + { + result += (char)_head->data[_offset++]; + _used--; + + if (_offset >= _segSize) + { + remSeg(); + } + } + } + + return result; +} + +//******************************************************************************************************************* +String xbuf::peekString(int endPos) +{ + String result; + + xseg* seg = _head; + size_t offset = _offset; + + if (endPos > _used) + { + endPos = _used; + } + + if (endPos > 0 && result.reserve(endPos + 1)) + { + while (endPos--) + { + result += (char)seg->data[offset++]; + + if ( offset >= _segSize) + { + seg = seg->next; + offset = 0; + } + } + } + + return result; +} + +//******************************************************************************************************************* +void xbuf::flush() +{ + while (_head) + remSeg(); + + _tail = nullptr; + _offset = 0; + _used = 0; + _free = 0; +} + +//******************************************************************************************************************* +void xbuf::addSeg() +{ + if (_tail) + { + _tail->next = (xseg*) new uint32_t[_segSize / 4 + 1]; + + if (_tail->next == NULL) + AHTTP_LOGERROR("xbuf::addSeg: error new 1"); + + // KH, Must check NULL here + _tail = _tail->next; + } + else + { + // KH, Must check NULL here + _tail = _head = (xseg*) new uint32_t[_segSize / 4 + 1]; + + if (_tail == NULL) + AHTTP_LOGERROR("xbuf::addSeg: error new 2"); + } + + // KH, Must check NULL here + if (_tail) + _tail->next = nullptr; + + _free += _segSize; +} + +//******************************************************************************************************************* +void xbuf::remSeg() +{ + if (_head) + { + xseg *next = _head->next; + delete[] (uint32_t*) _head; + _head = next; + + if ( ! _head) + { + _tail = nullptr; + } + } + + _offset = 0; +} + +//////////////////////////////////////////////////////////////////////////// + //************************************************************************************************************** AsyncHTTPRequest::AsyncHTTPRequest(): _readyState(readyStateUnsent), _HTTPcode(0), _chunked(false), _debug(DEBUG_IOTA_HTTP_SET) , _timeout(DEFAULT_RX_TIMEOUT), _lastActivity(0), _requestStartTime(0), _requestEndTime(0), _URL(nullptr) @@ -248,7 +637,7 @@ bool AsyncHTTPRequest::send() } //************************************************************************************************************** -bool AsyncHTTPRequest::send(String body) +bool AsyncHTTPRequest::send(const String& body) { // New in v1.1.1 if (_requestReadyToSend) @@ -602,7 +991,7 @@ bool AsyncHTTPRequest::_parseURL(const char* url) } //************************************************************************************************************** -bool AsyncHTTPRequest::_parseURL(String url) +bool AsyncHTTPRequest::_parseURL(const String& url) { SAFE_DELETE(_URL)