diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d4601fe..0ca85aa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,7 +15,7 @@ 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.0 or STM32 v2.1.0) +* `ESP8266`,`ESP32` or `STM32` Core Version (e.g. ESP8266 core v3.0.2, ESP32 v2.0.1 or STM32 v2.1.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: @@ -27,9 +27,9 @@ Please ensure to specify the following: ``` Arduino IDE version: 1.8.16 -ESP32 Core Version 2.0.0 +ESP32 Core Version 2.0.1 OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.4.0-86-generic #97-Ubuntu SMP Fri Sep 17 19:19:40 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux +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 Context: I encountered an endless loop while trying to connect to Local WiFi. diff --git a/README.md b/README.md index 9a440cb..b59f42d 100644 --- a/README.md +++ b/README.md @@ -649,7 +649,7 @@ IPAddress ip(192, 168, 2, 232); ``` Start AsyncHTTPRequest_STM32 on NUCLEO_F767ZI -AsyncHTTPRequest_Generic v1.3.1 +AsyncHTTPRequest_Generic v1.4.0 AsyncHTTPRequest @ IP : 192.168.2.72 ************************************** @@ -694,7 +694,7 @@ week_number: 37 ``` Starting AsyncHTTPRequest_ESP_WiFiManager using LittleFS on ESP8266_NODEMCU -AsyncHTTPRequest_Generic v1.3.1 +AsyncHTTPRequest_Generic v1.4.0 Stored: SSID = HueNet1, Pass = 12345678 Got stored Credentials. Timeout 120s ConnectMultiWiFi in setup @@ -727,7 +727,7 @@ HHHHHH ``` Starting AsyncHTTPRequest_ESP_WiFiManager using SPIFFS on ESP32_DEV -AsyncHTTPRequest_Generic v1.3.1 +AsyncHTTPRequest_Generic v1.4.0 Stored: SSID = HueNet1, Pass = 12345678 Got stored Credentials. Timeout 120s ConnectMultiWiFi in setup @@ -778,7 +778,7 @@ HHHHHHHHH HHHHHHHHHH HHHHHHHHHH ``` Starting AsyncHTTPRequest_ESP using ESP8266_NODEMCU -AsyncHTTPRequest_Generic v1.3.1 +AsyncHTTPRequest_Generic v1.4.0 Connecting to WiFi SSID: HueNet1 ........... HTTP WebServer is @ IP : 192.168.2.81 @@ -810,7 +810,7 @@ HHHHHHHHH HHHHHHHHHH HHHHHHHHHH H ``` Start AsyncWebClientRepeating_STM32 on NUCLEO_F767ZI -AsyncHTTPRequest_Generic v1.3.1 +AsyncHTTPRequest_Generic v1.4.0 AsyncHTTPRequest @ IP : 192.168.2.72 ************************************** @@ -865,7 +865,7 @@ AsyncHTTPRequest @ IP : 192.168.2.72 ``` Start AsyncWebClientRepeating_STM32_LAN8720 on BLACK_F407VE -AsyncHTTPRequest_Generic v1.3.1 +AsyncHTTPRequest_Generic v1.4.0 AsyncHTTPRequest @ IP : 192.168.2.150 @@ -920,8 +920,8 @@ AsyncHTTPRequest @ IP : 192.168.2.150 ``` Starting AsyncHTTPRequest_WT32_ETH01 on ESP32_DEV with ETH_PHY_LAN8720 -WebServer_WT32_ETH01 v1.2.1 -AsyncHTTPRequest_Generic v1.3.1 +WebServer_WT32_ETH01 v1.3.0 +AsyncHTTPRequest_Generic v1.4.0 ETH MAC: A8:03:2A:A1:61:73, IPv4: 192.168.2.232, FULL_DUPLEX, 100Mbps AsyncHTTPRequest @ IP : 192.168.2.232 @@ -946,8 +946,8 @@ H ``` Starting AsyncHTTPRequest_WT32_ETH01 on ESP32_DEV with ETH_PHY_LAN8720 -WebServer_WT32_ETH01 v1.2.1 -AsyncHTTPRequest_Generic v1.3.1 +WebServer_WT32_ETH01 v1.3.0 +AsyncHTTPRequest_Generic v1.4.0 ETH MAC: A8:03:2A:A1:61:73, IPv4: 192.168.2.232, FULL_DUPLEX, 100Mbps AsyncHTTPRequest @ IP : 192.168.2.232 @@ -1037,6 +1037,8 @@ This library is based on, modified, bug-fixed and improved from: 5. Thanks to [spdi](https://github.com/spdi) to report [**'Connection' header expects 'disconnect' instead 'close' ? #13**](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/13) leading to new release v1.1.3 to fix bug. +6. Thanks to [andrewk123](https://github.com/andrewk123) to report [**Http GET polling causes crash when host disconnected #22**](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/22) leading to new release v1.4.0 to fix bug. + @@ -1045,6 +1047,7 @@ This library is based on, modified, bug-fixed and improved from: +
gleniat
gleniat

baddwarf
BadDwarf

spdi
spdi

andrewk123
andrewk123

diff --git a/changelog.md b/changelog.md index 932aa50..c1af4d8 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ ## Table of Contents * [Changelog](#changelog) + * [Releases v1.4.0](#releases-v140) * [Releases v1.3.1](#releases-v131) * [Releases v1.3.0](#releases-v130) * [Releases v1.2.0](#releases-v120) @@ -30,6 +31,11 @@ ## Changelog +### Releases v1.4.0 + +1. Fix crashing bug when request a non-existing IP. Check [Http GET polling causes crash when host disconnected #22](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/22) +2. Modify `platform.ini` to avoid compile error with PIO when using ESP8266/ESP32 + ### Releases v1.3.1 1. Update `platform.ini` and `library.json` to use original `khoih-prog` instead of `khoih.prog` after PIO fix diff --git a/library.json b/library.json index 801b87f..b5f65b3 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name":"AsyncHTTPRequest_Generic", - "version": "1.3.1", + "version": "1.4.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 bd335ab..c1beb95 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AsyncHTTPRequest_Generic -version=1.3.1 +version=1.4.0 author=Bob Lemaire,Khoi Hoang maintainer=Khoi Hoang license=MIT diff --git a/platformio/platformio.ini b/platformio/platformio.ini index b28ffbb..30cfad6 100644 --- a/platformio/platformio.ini +++ b/platformio/platformio.ini @@ -50,12 +50,12 @@ lib_deps = me-no-dev/AsyncTCP@>=1.1.1 me-no-dev/ESPAsyncTCP@>=1.2.2 ; philbowles/STM32AsyncTCP - https://github.com/khoih-prog/STM32AsyncTCP.git - stm32duino/STM32duino LwIP@>=2.1.2 - stm32duino/STM32duino STM32Ethernet@>=1.2.0 +; 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.3 lorol/LittleFS_esp32@>=1.0.6 - khoih-prog/WebServer_WT32_ETH01@>=1.2.1 +; khoih-prog/WebServer_WT32_ETH01@>=1.2.1 build_flags = ; set your debug output (default=Serial) diff --git a/src/AsyncHTTPRequest_Debug_Generic.h b/src/AsyncHTTPRequest_Debug_Generic.h index 6658a63..9be6f0a 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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ #pragma once diff --git a/src/AsyncHTTPRequest_Generic.h b/src/AsyncHTTPRequest_Generic.h index ffad63c..dc65278 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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ #pragma once @@ -40,7 +41,7 @@ #ifndef ASYNC_HTTP_REQUEST_GENERIC_H #define ASYNC_HTTP_REQUEST_GENERIC_H -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.3.1" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.4.0" #include diff --git a/src/AsyncHTTPRequest_Impl_Generic.h b/src/AsyncHTTPRequest_Impl_Generic.h index 9a90b71..1bf9fa4 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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ #pragma once @@ -259,9 +260,13 @@ bool AsyncHTTPRequest::send(String body) return false; } ////// + + AHTTP_LOGERROR1("01) send String body =", body); MUTEX_LOCK(false) + AHTTP_LOGERROR1("02) send String body =", body); + _addHeader("Content-Length", String(body.length()).c_str()); if ( ! _buildRequest()) @@ -271,9 +276,15 @@ bool AsyncHTTPRequest::send(String body) return false; } + AHTTP_LOGERROR1("1) send String body =", body); + _request->write(body); + + AHTTP_LOGERROR1("2) send String body =", body); _send(); + AHTTP_LOGERROR1("3) send String body =", body); + _AHTTP_unlock; return true; @@ -790,12 +801,27 @@ size_t AsyncHTTPRequest::_send() AHTTP_LOGDEBUG1("_send(), _request->available =", _request->available()); +#if 1 + if ( ! _client->connected()) + { + AHTTP_LOGDEBUG("!connected"); + + return 0; + } + else if ( ! _client->canSend()) + { + AHTTP_LOGDEBUG("*can't send"); + + return 0; + } +#else if ( ! _client->connected() || ! _client->canSend()) { AHTTP_LOGDEBUG("*can't send"); return 0; } +#endif size_t supply = _request->available(); size_t demand = _client->space(); @@ -1009,17 +1035,17 @@ void AsyncHTTPRequest::_onDisconnect(AsyncClient* client) if (_readyState < readyStateOpened) { + AHTTP_LOGDEBUG("HTTPCODE_NOT_CONNECTED"); _HTTPcode = HTTPCODE_NOT_CONNECTED; } else if (_HTTPcode > 0 && (_readyState < readyStateHdrsRecvd || (_contentRead + _response->available()) < _contentLength)) { + AHTTP_LOGDEBUG("HTTPCODE_CONNECTION_LOST"); _HTTPcode = HTTPCODE_CONNECTION_LOST; } - SAFE_DELETE(_client) - - _client = nullptr; + AHTTP_LOGDEBUG1("_HTTPcode = ", _HTTPcode); SAFE_DELETE_ARRAY(_connectedHost) diff --git a/src/utility/xbuf.h b/src/utility/xbuf.h index e05bae5..fd1bb33 100644 --- a/src/utility/xbuf.h +++ b/src/utility/xbuf.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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ /******************************************************************************************** diff --git a/src/utility/xbuf_Impl.h b/src/utility/xbuf_Impl.h index e1c220d..979e0bf 100644 --- a/src/utility/xbuf_Impl.h +++ b/src/utility/xbuf_Impl.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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ #pragma once diff --git a/src_cpp/AsyncHTTPRequest_Debug_Generic.h b/src_cpp/AsyncHTTPRequest_Debug_Generic.h index 6658a63..9be6f0a 100644 --- a/src_cpp/AsyncHTTPRequest_Debug_Generic.h +++ b/src_cpp/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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ #pragma once diff --git a/src_cpp/AsyncHTTPRequest_Generic.cpp b/src_cpp/AsyncHTTPRequest_Generic.cpp index b8695f0..daaa25e 100644 --- a/src_cpp/AsyncHTTPRequest_Generic.cpp +++ b/src_cpp/AsyncHTTPRequest_Generic.cpp @@ -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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ #include "AsyncHTTPRequest_Debug_Generic.h" @@ -183,6 +184,8 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL) sprintf(hostName, "%s:%d", _URL->host, _URL->port); _addHeader("host", hostName); + AHTTP_LOGDEBUG1("open: conneting to hostname =", hostName); + SAFE_DELETE_ARRAY(hostName) _lastActivity = millis(); @@ -191,8 +194,6 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL) _requestReadyToSend = true; ////// - AHTTP_LOGDEBUG1("open: conneting to hostname =", hostName); - return _connect(); } else @@ -258,9 +259,13 @@ bool AsyncHTTPRequest::send(String body) return false; } ////// + + AHTTP_LOGERROR1("01) send String body =", body); MUTEX_LOCK(false) + AHTTP_LOGERROR1("02) send String body =", body); + _addHeader("Content-Length", String(body.length()).c_str()); if ( ! _buildRequest()) @@ -270,9 +275,15 @@ bool AsyncHTTPRequest::send(String body) return false; } + AHTTP_LOGERROR1("1) send String body =", body); + _request->write(body); + + AHTTP_LOGERROR1("2) send String body =", body); _send(); + AHTTP_LOGERROR1("3) send String body =", body); + _AHTTP_unlock; return true; @@ -789,12 +800,27 @@ size_t AsyncHTTPRequest::_send() AHTTP_LOGDEBUG1("_send(), _request->available =", _request->available()); +#if 1 + if ( ! _client->connected()) + { + AHTTP_LOGDEBUG("!connected"); + + return 0; + } + else if ( ! _client->canSend()) + { + AHTTP_LOGDEBUG("*can't send"); + + return 0; + } +#else if ( ! _client->connected() || ! _client->canSend()) { AHTTP_LOGDEBUG("*can't send"); return 0; } +#endif size_t supply = _request->available(); size_t demand = _client->space(); @@ -1008,17 +1034,17 @@ void AsyncHTTPRequest::_onDisconnect(AsyncClient* client) if (_readyState < readyStateOpened) { + AHTTP_LOGDEBUG("HTTPCODE_NOT_CONNECTED"); _HTTPcode = HTTPCODE_NOT_CONNECTED; } else if (_HTTPcode > 0 && (_readyState < readyStateHdrsRecvd || (_contentRead + _response->available()) < _contentLength)) { + AHTTP_LOGDEBUG("HTTPCODE_CONNECTION_LOST"); _HTTPcode = HTTPCODE_CONNECTION_LOST; } - SAFE_DELETE(_client) - - _client = nullptr; + AHTTP_LOGDEBUG1("_HTTPcode = ", _HTTPcode); SAFE_DELETE_ARRAY(_connectedHost) diff --git a/src_cpp/AsyncHTTPRequest_Generic.h b/src_cpp/AsyncHTTPRequest_Generic.h index 65b3b22..60d4a38 100644 --- a/src_cpp/AsyncHTTPRequest_Generic.h +++ b/src_cpp/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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ #pragma once @@ -40,7 +41,7 @@ #ifndef ASYNC_HTTP_REQUEST_GENERIC_H #define ASYNC_HTTP_REQUEST_GENERIC_H -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.3.0" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.4.0" #include diff --git a/src_cpp/utility/xbuf.cpp b/src_cpp/utility/xbuf.cpp index a21e94f..75dd377 100644 --- a/src_cpp/utility/xbuf.cpp +++ b/src_cpp/utility/xbuf.cpp @@ -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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ #include "utility/xbuf.h" diff --git a/src_cpp/utility/xbuf.h b/src_cpp/utility/xbuf.h index 0b2c46a..b557124 100644 --- a/src_cpp/utility/xbuf.h +++ b/src_cpp/utility/xbuf.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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ /******************************************************************************************** diff --git a/src_h/AsyncHTTPRequest_Debug_Generic.h b/src_h/AsyncHTTPRequest_Debug_Generic.h index 6658a63..9be6f0a 100644 --- a/src_h/AsyncHTTPRequest_Debug_Generic.h +++ b/src_h/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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ #pragma once diff --git a/src_h/AsyncHTTPRequest_Generic.h b/src_h/AsyncHTTPRequest_Generic.h index ffad63c..dc65278 100644 --- a/src_h/AsyncHTTPRequest_Generic.h +++ b/src_h/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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ #pragma once @@ -40,7 +41,7 @@ #ifndef ASYNC_HTTP_REQUEST_GENERIC_H #define ASYNC_HTTP_REQUEST_GENERIC_H -#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.3.1" +#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.4.0" #include diff --git a/src_h/AsyncHTTPRequest_Impl_Generic.h b/src_h/AsyncHTTPRequest_Impl_Generic.h index 9a90b71..1bf9fa4 100644 --- a/src_h/AsyncHTTPRequest_Impl_Generic.h +++ b/src_h/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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ #pragma once @@ -259,9 +260,13 @@ bool AsyncHTTPRequest::send(String body) return false; } ////// + + AHTTP_LOGERROR1("01) send String body =", body); MUTEX_LOCK(false) + AHTTP_LOGERROR1("02) send String body =", body); + _addHeader("Content-Length", String(body.length()).c_str()); if ( ! _buildRequest()) @@ -271,9 +276,15 @@ bool AsyncHTTPRequest::send(String body) return false; } + AHTTP_LOGERROR1("1) send String body =", body); + _request->write(body); + + AHTTP_LOGERROR1("2) send String body =", body); _send(); + AHTTP_LOGERROR1("3) send String body =", body); + _AHTTP_unlock; return true; @@ -790,12 +801,27 @@ size_t AsyncHTTPRequest::_send() AHTTP_LOGDEBUG1("_send(), _request->available =", _request->available()); +#if 1 + if ( ! _client->connected()) + { + AHTTP_LOGDEBUG("!connected"); + + return 0; + } + else if ( ! _client->canSend()) + { + AHTTP_LOGDEBUG("*can't send"); + + return 0; + } +#else if ( ! _client->connected() || ! _client->canSend()) { AHTTP_LOGDEBUG("*can't send"); return 0; } +#endif size_t supply = _request->available(); size_t demand = _client->space(); @@ -1009,17 +1035,17 @@ void AsyncHTTPRequest::_onDisconnect(AsyncClient* client) if (_readyState < readyStateOpened) { + AHTTP_LOGDEBUG("HTTPCODE_NOT_CONNECTED"); _HTTPcode = HTTPCODE_NOT_CONNECTED; } else if (_HTTPcode > 0 && (_readyState < readyStateHdrsRecvd || (_contentRead + _response->available()) < _contentLength)) { + AHTTP_LOGDEBUG("HTTPCODE_CONNECTION_LOST"); _HTTPcode = HTTPCODE_CONNECTION_LOST; } - SAFE_DELETE(_client) - - _client = nullptr; + AHTTP_LOGDEBUG1("_HTTPcode = ", _HTTPcode); SAFE_DELETE_ARRAY(_connectedHost) diff --git a/src_h/utility/xbuf.h b/src_h/utility/xbuf.h index e05bae5..fd1bb33 100644 --- a/src_h/utility/xbuf.h +++ b/src_h/utility/xbuf.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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ /******************************************************************************************** diff --git a/src_h/utility/xbuf_Impl.h b/src_h/utility/xbuf_Impl.h index e1c220d..979e0bf 100644 --- a/src_h/utility/xbuf_Impl.h +++ b/src_h/utility/xbuf_Impl.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.3.1 + Version: 1.4.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -33,6 +33,7 @@ 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 *****************************************************************************************************************************/ #pragma once