mirror of
https://github.com/khoih-prog/AsyncHTTPRequest_Generic.git
synced 2025-07-31 19:04:27 +02:00
Releases v1.1.0
### Releases v1.1.0 1. Add HTTP PUT, PATCH, DELETE and HEAD methods. Check [Add support for sending PUT, PATCH, DELETE request](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/5) 2. Add Table of Contents 3. Add Version String
This commit is contained in:
82
README.md
82
README.md
@@ -9,6 +9,62 @@
|
|||||||
---
|
---
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
|
||||||
|
|
||||||
|
* [Why do we need the new Async AsyncHTTPRequest_Generic library](#why-do-we-need-this-async-asynchttprequest_generic-library)
|
||||||
|
* [Features](#features)
|
||||||
|
* [Supports](#supports)
|
||||||
|
* [Principles of operation](#principles-of-operation)
|
||||||
|
* [Changelog](#changelog)
|
||||||
|
* [Releases v1.1.0](#releases-v110)
|
||||||
|
* [Releases v1.0.2](#releases-v102)
|
||||||
|
* [Releases v1.0.1](#releases-v101)
|
||||||
|
* [Releases v1.0.0](#releases-v100)
|
||||||
|
* [AsyncHTTPRequest_Generic for ESP32, ESP8266 using built-in WiFi and STM32 boards using built-in LAN8742A Ethernet](#asynchttprequest_generic-for-esp32-esp8266-using-built-in-wifi-and-stm32-boards-using-built-in-lan8742a-ethernet)
|
||||||
|
* [Prerequisites](#prerequisites)
|
||||||
|
* [Installation](#installation)
|
||||||
|
* [Use Arduino Library Manager](#use-arduino-library-manager)
|
||||||
|
* [Manual Install](#manual-install)
|
||||||
|
* [VS Code & PlatformIO](#vs-code--platformio)
|
||||||
|
* [Packages' Patches](#packages-patches)
|
||||||
|
* [HOWTO Fix `Multiple Definitions` Linker Error](#howto-fix-multiple-definitions-linker-error)
|
||||||
|
* [HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)](#howto-use-analogread-with-esp32-running-wifi-andor-bluetooth-btble)
|
||||||
|
* [1. ESP32 has 2 ADCs, named ADC1 and ADC2](#1--esp32-has-2-adcs-named-adc1-and-adc2)
|
||||||
|
* [2. ESP32 ADCs functions](#2-esp32-adcs-functions)
|
||||||
|
* [3. ESP32 WiFi uses ADC2 for WiFi functions](#3-esp32-wifi-uses-adc2-for-wifi-functions)
|
||||||
|
* [Examples](#examples)
|
||||||
|
* [AsyncHTTPRequest_ESP](examples/AsyncHTTPRequest_ESP)
|
||||||
|
* [AsyncHTTPRequest_ESP_WiFiManager](examples/AsyncHTTPRequest_ESP_WiFiManager)
|
||||||
|
* [AsyncHTTPRequest_STM32](examples/AsyncHTTPRequest_STM32)
|
||||||
|
* [AsyncCustomHeader_STM32](examples/AsyncCustomHeader_STM32)
|
||||||
|
* [AsyncDweetGet_STM32](examples/AsyncDweetGet_STM32)
|
||||||
|
* [AsyncDweetPost_STM32](examples/AsyncDweetPost_STM32)
|
||||||
|
* [AsyncSimpleGET_STM32](examples/AsyncSimpleGET_STM32)
|
||||||
|
* [AsyncWebClientRepeating_STM32](examples/AsyncWebClientRepeating_STM32)
|
||||||
|
* [Example AsyncHTTPRequest_STM32](#example-asynchttprequest_stm32)
|
||||||
|
* [File AsyncHTTPRequest_STM32.ino](#1-file-asynchttprequest_stm32ino)
|
||||||
|
* [2. File defines.h](#2-file-definesh)
|
||||||
|
* [Debug Terminal Output Samples](#debug-termimal-output-samples)
|
||||||
|
* [1. AsyncHTTPRequest_STM32 running on STM32F7 Nucleo-144 NUCLEO_F767ZI using built-in LAN8742A ](#1-asynchttprequest_stm32-running-on-stm32f7-nucleo-144-nucleo_f767zi-using-built-in-lan8742a)
|
||||||
|
* [2. AsyncHTTPRequest_ESP_WiFiManager running on ESP8266_NODEMCU](#2-asynchttprequest_esp_wifimanager-running-on-esp8266_nodemcu)
|
||||||
|
* [3. AsyncHTTPRequest_ESP_WiFiManager running on ESP32_DEV](#3-asynchttprequest_esp_wifimanager-running-on-esp32_dev)
|
||||||
|
* [4. AsyncHTTPRequest_ESP running on ESP8266_NODEMCU](#4-asynchttprequest_esp-running-on-esp8266_nodemcu)
|
||||||
|
* [5. AsyncWebClientRepeating_STM32 running on STM32F7 Nucleo-144 NUCLEO_F767ZI using built-in LAN8742A](#5-asyncwebclientrepeating_stm32-running-on-stm32f7-nucleo-144-nucleo_f767zi-using-built-in-lan8742a)
|
||||||
|
* [Debug](#debug)
|
||||||
|
* [Troubleshooting](#troubleshooting)
|
||||||
|
* [Issues](#issues)
|
||||||
|
* [Releases](#releases)
|
||||||
|
* [TO DO](#to-do)
|
||||||
|
* [DONE](#done)
|
||||||
|
* [Contributions and Thanks](#contributions-and-thanks)
|
||||||
|
* [Contributing](#contributing)
|
||||||
|
* [License and credits](#license-and-credits)
|
||||||
|
* [Copyright](#copyright)
|
||||||
|
|
||||||
|
---
|
||||||
|
---
|
||||||
|
|
||||||
## Why do we need this Async [AsyncHTTPRequest_Generic library](https://github.com/khoih-prog/AsyncHTTPRequest_Generic)
|
## Why do we need this Async [AsyncHTTPRequest_Generic library](https://github.com/khoih-prog/AsyncHTTPRequest_Generic)
|
||||||
|
|
||||||
#### Features
|
#### Features
|
||||||
@@ -19,9 +75,9 @@
|
|||||||
4. Relying on **[`STM32duino LwIP`](https://github.com/stm32duino/LwIP)/[`STM32duino STM32Ethernet`](https://github.com/stm32duino/STM32Ethernet)/[`STM32AsyncTCP`](https://github.com/philbowles/STM32AsyncTCP) for STM32 using built-in LAN8742A Ethernet.**
|
4. Relying on **[`STM32duino LwIP`](https://github.com/stm32duino/LwIP)/[`STM32duino STM32Ethernet`](https://github.com/stm32duino/STM32Ethernet)/[`STM32AsyncTCP`](https://github.com/philbowles/STM32AsyncTCP) for STM32 using built-in LAN8742A Ethernet.**
|
||||||
5. Methods similar in format and usage to XmlHTTPrequest in Javascript.
|
5. Methods similar in format and usage to XmlHTTPrequest in Javascript.
|
||||||
|
|
||||||
#### Supports:
|
#### Supports
|
||||||
|
|
||||||
1. **GET and POST**
|
1. **GET, POST, PUT, PATCH, DELETE and HEAD**
|
||||||
2. Request and response headers
|
2. Request and response headers
|
||||||
3. Chunked response
|
3. Chunked response
|
||||||
4. Single String response for short (<~5K) responses (heap permitting).
|
4. Single String response for short (<~5K) responses (heap permitting).
|
||||||
@@ -45,6 +101,16 @@ Chunked responses are recognized and handled transparently.
|
|||||||
---
|
---
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
|
||||||
|
### Releases v1.1.0
|
||||||
|
|
||||||
|
1. Add HTTP PUT, PATCH, DELETE and HEAD methods. Check [Add support for sending PUT, PATCH, DELETE request](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/5)
|
||||||
|
2. Add Table of Contents
|
||||||
|
3. Add Version String
|
||||||
|
|
||||||
|
|
||||||
### Releases v1.0.2
|
### Releases v1.0.2
|
||||||
|
|
||||||
1. Make Mutex Lock and delete more reliable and error-proof to prevent random crash.
|
1. Make Mutex Lock and delete more reliable and error-proof to prevent random crash.
|
||||||
@@ -509,7 +575,7 @@ IPAddress ip(192, 168, 2, 232);
|
|||||||
---
|
---
|
||||||
---
|
---
|
||||||
|
|
||||||
### Debug Terminal Oouput Samples
|
### Debug Terminal Ouput Samples
|
||||||
|
|
||||||
#### 1. [AsyncHTTPRequest_STM32](examples/AsyncHTTPRequest_STM32) running on STM32F7 Nucleo-144 NUCLEO_F767ZI using built-in LAN8742A
|
#### 1. [AsyncHTTPRequest_STM32](examples/AsyncHTTPRequest_STM32) running on STM32F7 Nucleo-144 NUCLEO_F767ZI using built-in LAN8742A
|
||||||
|
|
||||||
@@ -763,10 +829,17 @@ Submit issues to: [AsyncHTTPRequest_Generic issues](https://github.com/khoih-pro
|
|||||||
1. Initially add support to STM32 using built-in LAN8742A Etnernet. Tested on **STM32F7 Nucleo-144 F767ZI**.
|
1. Initially add support to STM32 using built-in LAN8742A Etnernet. Tested on **STM32F7 Nucleo-144 F767ZI**.
|
||||||
2. Add more examples.
|
2. Add more examples.
|
||||||
3. Add debugging features.
|
3. Add debugging features.
|
||||||
|
4. Add PUT, PATCH, DELETE and HEAD besides GET and POST.
|
||||||
|
|
||||||
---
|
---
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Releases
|
||||||
|
|
||||||
|
### Releases v1.1.0
|
||||||
|
|
||||||
|
1. Add HTTP PUT, PATCH, DELETE and HEAD methods. Check [Add support for sending PUT, PATCH, DELETE request](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/5)
|
||||||
|
|
||||||
### Releases v1.0.2
|
### Releases v1.0.2
|
||||||
|
|
||||||
1. Make Mutex Lock and delete more reliable and error-proof to prevent random crash.
|
1. Make Mutex Lock and delete more reliable and error-proof to prevent random crash.
|
||||||
@@ -791,10 +864,13 @@ This library is based on, modified, bug-fixed and improved from:
|
|||||||
|
|
||||||
2. Thanks to [Daniel Brunner](https://github.com/0xFEEDC0DE64) to report and make PR in [Fixed linker errors when included in multiple .cpp files](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/pull/1) leading to v1.0.1. See [**HOWTO Fix `Multiple Definitions` Linker Error**](https://github.com/khoih-prog/AsyncHTTPRequest_Generic#HOWTO-Fix-Multiple-Definitions-Linker-Error)
|
2. Thanks to [Daniel Brunner](https://github.com/0xFEEDC0DE64) to report and make PR in [Fixed linker errors when included in multiple .cpp files](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/pull/1) leading to v1.0.1. See [**HOWTO Fix `Multiple Definitions` Linker Error**](https://github.com/khoih-prog/AsyncHTTPRequest_Generic#HOWTO-Fix-Multiple-Definitions-Linker-Error)
|
||||||
|
|
||||||
|
3. Thanks to [gleniat](https://github.com/gleniat) to make enhancement request in[Add support for sending PUT, PATCH, DELETE request](https://github.com/khoih-prog/AsyncHTTPRequest_Generic/issues/5) leading to v1.1.0.
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center"><a href="https://github.com/boblemaire"><img src="https://github.com/boblemaire.png" width="100px;" alt="boblemaire"/><br /><sub><b>⭐️ Bob Lemaire</b></sub></a><br /></td>
|
<td align="center"><a href="https://github.com/boblemaire"><img src="https://github.com/boblemaire.png" width="100px;" alt="boblemaire"/><br /><sub><b>⭐️ Bob Lemaire</b></sub></a><br /></td>
|
||||||
<td align="center"><a href="https://github.com/0xFEEDC0DE64"><img src="https://github.com/0xFEEDC0DE64.png" width="100px;" alt="0xFEEDC0DE64"/><br /><sub><b>Daniel Brunner</b></sub></a><br /></td>
|
<td align="center"><a href="https://github.com/0xFEEDC0DE64"><img src="https://github.com/0xFEEDC0DE64.png" width="100px;" alt="0xFEEDC0DE64"/><br /><sub><b>Daniel Brunner</b></sub></a><br /></td>
|
||||||
|
<td align="center"><a href="https://github.com/gleniat"><img src="https://github.com/gleniat.png" width="100px;" alt="gleniat"/><br /><sub><b>gleniat</b></sub></a><br /></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
@@ -76,6 +77,7 @@ void setup(void)
|
|||||||
while (!Serial);
|
while (!Serial);
|
||||||
|
|
||||||
Serial.println("\nStart AsyncCustomHeader_STM32 on " + String(BOARD_NAME));
|
Serial.println("\nStart AsyncCustomHeader_STM32 on " + String(BOARD_NAME));
|
||||||
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||||
|
|
||||||
// start the ethernet connection and the server
|
// start the ethernet connection and the server
|
||||||
// Use random mac
|
// Use random mac
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,6 +124,7 @@ void setup(void)
|
|||||||
while (!Serial);
|
while (!Serial);
|
||||||
|
|
||||||
Serial.println("\nStart AsyncDweetGET_STM32 on " + String(BOARD_NAME));
|
Serial.println("\nStart AsyncDweetGET_STM32 on " + String(BOARD_NAME));
|
||||||
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||||
|
|
||||||
// start the ethernet connection and the server
|
// start the ethernet connection and the server
|
||||||
// Use random mac
|
// Use random mac
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
// Dweet.io POST client. Connects to dweet.io once every ten seconds, sends a POST request and a request body.
|
// Dweet.io POST client. Connects to dweet.io once every ten seconds, sends a POST request and a request body.
|
||||||
@@ -122,6 +123,7 @@ void setup(void)
|
|||||||
while (!Serial);
|
while (!Serial);
|
||||||
|
|
||||||
Serial.println("\nStart AsyncDweetPOST_STM32 on " + String(BOARD_NAME));
|
Serial.println("\nStart AsyncDweetPOST_STM32 on " + String(BOARD_NAME));
|
||||||
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||||
|
|
||||||
// start the ethernet connection and the server
|
// start the ethernet connection and the server
|
||||||
// Use random mac
|
// Use random mac
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
//************************************************************************************************************
|
//************************************************************************************************************
|
||||||
//
|
//
|
||||||
@@ -133,6 +134,7 @@ void setup()
|
|||||||
while (!Serial);
|
while (!Serial);
|
||||||
|
|
||||||
Serial.println("\nStarting AsyncHTTPRequest_ESP using " + String(ARDUINO_BOARD));
|
Serial.println("\nStarting AsyncHTTPRequest_ESP using " + String(ARDUINO_BOARD));
|
||||||
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
|
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
//************************************************************************************************************
|
//************************************************************************************************************
|
||||||
//
|
//
|
||||||
@@ -48,6 +49,8 @@
|
|||||||
//
|
//
|
||||||
//*************************************************************************************************************
|
//*************************************************************************************************************
|
||||||
|
|
||||||
|
// Important note: This code is intended to run with the ESPAsync_WiFiManager library version 1.4.1+.
|
||||||
|
|
||||||
#if !( defined(ESP8266) || defined(ESP32) )
|
#if !( defined(ESP8266) || defined(ESP32) )
|
||||||
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
|
#error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting.
|
||||||
#endif
|
#endif
|
||||||
@@ -223,6 +226,10 @@ bool initialConfig = false;
|
|||||||
IPAddress dns1IP = gatewayIP;
|
IPAddress dns1IP = gatewayIP;
|
||||||
IPAddress dns2IP = IPAddress(8, 8, 8, 8);
|
IPAddress dns2IP = IPAddress(8, 8, 8, 8);
|
||||||
|
|
||||||
|
IPAddress APStaticIP = IPAddress(192, 168, 100, 1);
|
||||||
|
IPAddress APStaticGW = IPAddress(192, 168, 100, 1);
|
||||||
|
IPAddress APStaticSN = IPAddress(255, 255, 255, 0);
|
||||||
|
|
||||||
#include <ESPAsync_WiFiManager.h> //https://github.com/khoih-prog/ESPAsync_WiFiManager
|
#include <ESPAsync_WiFiManager.h> //https://github.com/khoih-prog/ESPAsync_WiFiManager
|
||||||
|
|
||||||
#define HTTP_PORT 80
|
#define HTTP_PORT 80
|
||||||
@@ -236,6 +243,139 @@ DNSServer dnsServer;
|
|||||||
AsyncHTTPRequest request;
|
AsyncHTTPRequest request;
|
||||||
Ticker ticker;
|
Ticker ticker;
|
||||||
|
|
||||||
|
///////////////////////////////////////////
|
||||||
|
// New in v1.4.0
|
||||||
|
/******************************************
|
||||||
|
* // Defined in ESPAsync_WiFiManager.h
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
IPAddress _ap_static_ip;
|
||||||
|
IPAddress _ap_static_gw;
|
||||||
|
IPAddress _ap_static_sn;
|
||||||
|
|
||||||
|
} WiFi_AP_IPConfig;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
IPAddress _sta_static_ip;
|
||||||
|
IPAddress _sta_static_gw;
|
||||||
|
IPAddress _sta_static_sn;
|
||||||
|
#if USE_CONFIGURABLE_DNS
|
||||||
|
IPAddress _sta_static_dns1;
|
||||||
|
IPAddress _sta_static_dns2;
|
||||||
|
#endif
|
||||||
|
} WiFi_STA_IPConfig;
|
||||||
|
******************************************/
|
||||||
|
|
||||||
|
WiFi_AP_IPConfig WM_AP_IPconfig;
|
||||||
|
WiFi_STA_IPConfig WM_STA_IPconfig;
|
||||||
|
|
||||||
|
void initAPIPConfigStruct(WiFi_AP_IPConfig &in_WM_AP_IPconfig)
|
||||||
|
{
|
||||||
|
in_WM_AP_IPconfig._ap_static_ip = APStaticIP;
|
||||||
|
in_WM_AP_IPconfig._ap_static_gw = APStaticGW;
|
||||||
|
in_WM_AP_IPconfig._ap_static_sn = APStaticSN;
|
||||||
|
}
|
||||||
|
|
||||||
|
void initSTAIPConfigStruct(WiFi_STA_IPConfig &in_WM_STA_IPconfig)
|
||||||
|
{
|
||||||
|
in_WM_STA_IPconfig._sta_static_ip = stationIP;
|
||||||
|
in_WM_STA_IPconfig._sta_static_gw = gatewayIP;
|
||||||
|
in_WM_STA_IPconfig._sta_static_sn = netMask;
|
||||||
|
#if USE_CONFIGURABLE_DNS
|
||||||
|
in_WM_STA_IPconfig._sta_static_dns1 = dns1IP;
|
||||||
|
in_WM_STA_IPconfig._sta_static_dns2 = dns2IP;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayIPConfigStruct(WiFi_STA_IPConfig in_WM_STA_IPconfig)
|
||||||
|
{
|
||||||
|
LOGERROR3(F("stationIP ="), in_WM_STA_IPconfig._sta_static_ip, ", gatewayIP =", in_WM_STA_IPconfig._sta_static_gw);
|
||||||
|
LOGERROR1(F("netMask ="), in_WM_STA_IPconfig._sta_static_sn);
|
||||||
|
#if USE_CONFIGURABLE_DNS
|
||||||
|
LOGERROR3(F("dns1IP ="), in_WM_STA_IPconfig._sta_static_dns1, ", dns2IP =", in_WM_STA_IPconfig._sta_static_dns2);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void configWiFi(WiFi_STA_IPConfig in_WM_STA_IPconfig)
|
||||||
|
{
|
||||||
|
#if USE_CONFIGURABLE_DNS
|
||||||
|
// Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
|
||||||
|
WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn, in_WM_STA_IPconfig._sta_static_dns1, in_WM_STA_IPconfig._sta_static_dns2);
|
||||||
|
#else
|
||||||
|
// Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2.
|
||||||
|
WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////
|
||||||
|
|
||||||
|
uint8_t connectMultiWiFi()
|
||||||
|
{
|
||||||
|
#if ESP32
|
||||||
|
// For ESP32, this better be 0 to shorten the connect time
|
||||||
|
#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 0
|
||||||
|
#else
|
||||||
|
// For ESP8266, this better be 2200 to enable connect the 1st time
|
||||||
|
#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 2200L
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define WIFI_MULTI_CONNECT_WAITING_MS 100L
|
||||||
|
|
||||||
|
uint8_t status;
|
||||||
|
|
||||||
|
LOGERROR(F("ConnectMultiWiFi with :"));
|
||||||
|
|
||||||
|
if ( (Router_SSID != "") && (Router_Pass != "") )
|
||||||
|
{
|
||||||
|
LOGERROR3(F("* Flash-stored Router_SSID = "), Router_SSID, F(", Router_Pass = "), Router_Pass );
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++)
|
||||||
|
{
|
||||||
|
// Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8)
|
||||||
|
if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) )
|
||||||
|
{
|
||||||
|
LOGERROR3(F("* Additional SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGERROR(F("Connecting MultiWifi..."));
|
||||||
|
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
|
||||||
|
#if !USE_DHCP_IP
|
||||||
|
// New in v1.4.0
|
||||||
|
configWiFi(WM_STA_IPconfig);
|
||||||
|
//////
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
status = wifiMulti.run();
|
||||||
|
delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS);
|
||||||
|
|
||||||
|
while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) )
|
||||||
|
{
|
||||||
|
status = wifiMulti.run();
|
||||||
|
|
||||||
|
if ( status == WL_CONNECTED )
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
delay(WIFI_MULTI_CONNECT_WAITING_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( status == WL_CONNECTED )
|
||||||
|
{
|
||||||
|
LOGERROR1(F("WiFi connected after time: "), i);
|
||||||
|
LOGERROR3(F("SSID:"), WiFi.SSID(), F(",RSSI="), WiFi.RSSI());
|
||||||
|
LOGERROR3(F("Channel:"), WiFi.channel(), F(",IP address:"), WiFi.localIP() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LOGERROR(F("WiFi not connected"));
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
void heartBeatPrint(void)
|
void heartBeatPrint(void)
|
||||||
{
|
{
|
||||||
static int num = 1;
|
static int num = 1;
|
||||||
@@ -292,16 +432,31 @@ void check_status(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadConfigData(void)
|
void loadConfigData()
|
||||||
{
|
{
|
||||||
File file = FileFS.open(CONFIG_FILENAME, "r");
|
File file = FileFS.open(CONFIG_FILENAME, "r");
|
||||||
LOGERROR(F("LoadWiFiCfgFile "));
|
LOGERROR(F("LoadWiFiCfgFile "));
|
||||||
|
|
||||||
|
memset(&WM_config, 0, sizeof(WM_config));
|
||||||
|
|
||||||
|
// New in v1.4.0
|
||||||
|
memset(&WM_STA_IPconfig, 0, sizeof(WM_STA_IPconfig));
|
||||||
|
//////
|
||||||
|
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
file.readBytes((char *) &WM_config, sizeof(WM_config));
|
file.readBytes((char *) &WM_config, sizeof(WM_config));
|
||||||
|
|
||||||
|
// New in v1.4.0
|
||||||
|
file.readBytes((char *) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig));
|
||||||
|
//////
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
LOGERROR(F("OK"));
|
LOGERROR(F("OK"));
|
||||||
|
|
||||||
|
// New in v1.4.0
|
||||||
|
displayIPConfigStruct(WM_STA_IPconfig);
|
||||||
|
//////
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -309,7 +464,7 @@ void loadConfigData(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveConfigData(void)
|
void saveConfigData()
|
||||||
{
|
{
|
||||||
File file = FileFS.open(CONFIG_FILENAME, "w");
|
File file = FileFS.open(CONFIG_FILENAME, "w");
|
||||||
LOGERROR(F("SaveWiFiCfgFile "));
|
LOGERROR(F("SaveWiFiCfgFile "));
|
||||||
@@ -317,6 +472,11 @@ void saveConfigData(void)
|
|||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
file.write((uint8_t*) &WM_config, sizeof(WM_config));
|
file.write((uint8_t*) &WM_config, sizeof(WM_config));
|
||||||
|
|
||||||
|
// New in v1.4.0
|
||||||
|
file.write((uint8_t*) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig));
|
||||||
|
//////
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
LOGERROR(F("OK"));
|
LOGERROR(F("OK"));
|
||||||
}
|
}
|
||||||
@@ -326,76 +486,6 @@ void saveConfigData(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t connectMultiWiFi(void)
|
|
||||||
{
|
|
||||||
#if ESP32
|
|
||||||
// For ESP32, this better be 0 to shorten the connect time
|
|
||||||
#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 0
|
|
||||||
#else
|
|
||||||
// For ESP8266, this better be 2200 to enable connect the 1st time
|
|
||||||
#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 2200L
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define WIFI_MULTI_CONNECT_WAITING_MS 100L
|
|
||||||
|
|
||||||
uint8_t status;
|
|
||||||
|
|
||||||
LOGERROR(F("ConnectMultiWiFi with :"));
|
|
||||||
|
|
||||||
if ( (Router_SSID != "") && (Router_Pass != "") )
|
|
||||||
{
|
|
||||||
LOGERROR3(F("* Flash-stored Router_SSID = "), Router_SSID, F(", Router_Pass = "), Router_Pass );
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++)
|
|
||||||
{
|
|
||||||
// Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8)
|
|
||||||
if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != "") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) )
|
|
||||||
{
|
|
||||||
LOGERROR3(F("* Additional SSID = "), WM_config.WiFi_Creds[i].wifi_ssid, F(", PW = "), WM_config.WiFi_Creds[i].wifi_pw );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGERROR(F("Connecting MultiWifi..."));
|
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
|
||||||
|
|
||||||
#if !USE_DHCP_IP
|
|
||||||
#if USE_CONFIGURABLE_DNS
|
|
||||||
// Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
|
|
||||||
WiFi.config(stationIP, gatewayIP, netMask, dns1IP, dns2IP);
|
|
||||||
#else
|
|
||||||
// Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2.
|
|
||||||
WiFi.config(stationIP, gatewayIP, netMask);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
status = wifiMulti.run();
|
|
||||||
delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS);
|
|
||||||
|
|
||||||
while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) )
|
|
||||||
{
|
|
||||||
status = wifiMulti.run();
|
|
||||||
|
|
||||||
if ( status == WL_CONNECTED )
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
delay(WIFI_MULTI_CONNECT_WAITING_MS);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( status == WL_CONNECTED )
|
|
||||||
{
|
|
||||||
LOGERROR1(F("WiFi connected after time: "), i);
|
|
||||||
LOGERROR3(F("SSID:"), WiFi.SSID(), F(",RSSI="), WiFi.RSSI());
|
|
||||||
LOGERROR3(F("Channel:"), WiFi.channel(), F(",IP address:"), WiFi.localIP() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
LOGERROR(F("WiFi not connected"));
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendRequest()
|
void sendRequest()
|
||||||
{
|
{
|
||||||
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
if (request.readyState() == readyStateUnsent || request.readyState() == readyStateDone)
|
||||||
@@ -426,6 +516,8 @@ void setup()
|
|||||||
|
|
||||||
Serial.print("\nStarting AsyncHTTPRequest_ESP_WiFiManager using " + String(FS_Name));
|
Serial.print("\nStarting AsyncHTTPRequest_ESP_WiFiManager using " + String(FS_Name));
|
||||||
Serial.println(" on " + String(ARDUINO_BOARD));
|
Serial.println(" on " + String(ARDUINO_BOARD));
|
||||||
|
Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION);
|
||||||
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||||
|
|
||||||
if (FORMAT_FILESYSTEM)
|
if (FORMAT_FILESYSTEM)
|
||||||
FileFS.format();
|
FileFS.format();
|
||||||
@@ -447,6 +539,11 @@ void setup()
|
|||||||
|
|
||||||
unsigned long startedAt = millis();
|
unsigned long startedAt = millis();
|
||||||
|
|
||||||
|
// New in v1.4.0
|
||||||
|
initAPIPConfigStruct(WM_AP_IPconfig);
|
||||||
|
initSTAIPConfigStruct(WM_STA_IPconfig);
|
||||||
|
//////
|
||||||
|
|
||||||
//Local intialization. Once its business is done, there is no need to keep it around
|
//Local intialization. Once its business is done, there is no need to keep it around
|
||||||
// Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX
|
// Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX
|
||||||
//ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer);
|
//ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer);
|
||||||
@@ -459,7 +556,9 @@ void setup()
|
|||||||
//ESPAsync_wifiManager.resetSettings();
|
//ESPAsync_wifiManager.resetSettings();
|
||||||
|
|
||||||
//set custom ip for portal
|
//set custom ip for portal
|
||||||
ESPAsync_wifiManager.setAPStaticIPConfig(IPAddress(192, 168, 100, 1), IPAddress(192, 168, 100, 1), IPAddress(255, 255, 255, 0));
|
// New in v1.4.0
|
||||||
|
ESPAsync_wifiManager.setAPStaticIPConfig(WM_AP_IPconfig);
|
||||||
|
//////
|
||||||
|
|
||||||
ESPAsync_wifiManager.setMinimumSignalQuality(-1);
|
ESPAsync_wifiManager.setMinimumSignalQuality(-1);
|
||||||
|
|
||||||
@@ -469,13 +568,10 @@ void setup()
|
|||||||
//////
|
//////
|
||||||
|
|
||||||
#if !USE_DHCP_IP
|
#if !USE_DHCP_IP
|
||||||
#if USE_CONFIGURABLE_DNS
|
// Set (static IP, Gateway, Subnetmask, DNS1 and DNS2) or (IP, Gateway, Subnetmask). New in v1.0.5
|
||||||
// Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5
|
// New in v1.4.0
|
||||||
ESPAsync_wifiManager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask, dns1IP, dns2IP);
|
ESPAsync_wifiManager.setSTAStaticIPConfig(WM_STA_IPconfig);
|
||||||
#else
|
//////
|
||||||
// Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2.
|
|
||||||
ESPAsync_wifiManager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask);
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// New from v1.1.1
|
// New from v1.1.1
|
||||||
@@ -549,6 +645,11 @@ void setup()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New in v1.4.0
|
||||||
|
ESPAsync_wifiManager.getSTAStaticIPConfig(WM_STA_IPconfig);
|
||||||
|
displayIPConfigStruct(WM_STA_IPconfig);
|
||||||
|
//////
|
||||||
|
|
||||||
saveConfigData();
|
saveConfigData();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
//************************************************************************************************************
|
//************************************************************************************************************
|
||||||
//
|
//
|
||||||
@@ -92,6 +93,7 @@ void setup(void)
|
|||||||
while (!Serial);
|
while (!Serial);
|
||||||
|
|
||||||
Serial.println("\nStart AsyncHTTPRequest_STM32 on " + String(BOARD_NAME));
|
Serial.println("\nStart AsyncHTTPRequest_STM32 on " + String(BOARD_NAME));
|
||||||
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||||
|
|
||||||
// start the ethernet connection and the server
|
// start the ethernet connection and the server
|
||||||
// Use random mac
|
// Use random mac
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
@@ -73,6 +74,7 @@ void setup(void)
|
|||||||
while (!Serial);
|
while (!Serial);
|
||||||
|
|
||||||
Serial.println("\nStart AsyncSimpleGET_STM32 on " + String(BOARD_NAME));
|
Serial.println("\nStart AsyncSimpleGET_STM32 on " + String(BOARD_NAME));
|
||||||
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||||
|
|
||||||
// start the ethernet connection and the server
|
// start the ethernet connection and the server
|
||||||
// Use random mac
|
// Use random mac
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
@@ -76,6 +77,7 @@ void setup(void)
|
|||||||
while (!Serial);
|
while (!Serial);
|
||||||
|
|
||||||
Serial.println("\nStart AsyncWebClientRepeating_STM32 on " + String(BOARD_NAME));
|
Serial.println("\nStart AsyncWebClientRepeating_STM32 on " + String(BOARD_NAME));
|
||||||
|
Serial.println(ASYNC_HTTP_REQUEST_GENERIC_VERSION);
|
||||||
|
|
||||||
// start the ethernet connection and the server
|
// start the ethernet connection and the server
|
||||||
// Use random mac
|
// Use random mac
|
||||||
|
16
library.json
16
library.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name":"AsyncHTTPRequest_Generic",
|
"name":"AsyncHTTPRequest_Generic",
|
||||||
"version": "1.0.2",
|
"version": "1.1.0",
|
||||||
"description":"Simple Async HTTP Request library, supporting GET and POST, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, AsyncTCP_STM32, etc.. for ESP32, ESP8266 and currently STM32 with built-in LAN8742A Ethernet.",
|
"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, ESP8266 and currently STM32 with built-in LAN8742A Ethernet.",
|
||||||
"keywords":"async,tcp,http,ESP8266,ESP32,ESPAsyncTCP,AsyncTCP,stm32,ethernet,wifi,lan8742a",
|
"keywords":"async,tcp,http,ESP8266,ESP32,ESPAsyncTCP,AsyncTCP,stm32,ethernet,wifi,lan8742a",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
@@ -22,34 +22,36 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"dependencies": [
|
"dependencies":
|
||||||
|
[
|
||||||
{
|
{
|
||||||
"owner": "me-no-dev",
|
"owner": "me-no-dev",
|
||||||
"name": "AsyncTCP",
|
"name": "AsyncTCP",
|
||||||
"version": "*",
|
"version": ">=1.1.1",
|
||||||
"platforms": ["espressif32"]
|
"platforms": ["espressif32"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"owner": "me-no-dev",
|
"owner": "me-no-dev",
|
||||||
"name": "ESP AsyncTCP",
|
"name": "ESP AsyncTCP",
|
||||||
"version": "*",
|
"version": ">=1.2.2",
|
||||||
"platforms": "espressif8266"
|
"platforms": "espressif8266"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"owner": "khoih-prog",
|
"owner": "khoih-prog",
|
||||||
"name": "ESPAsync_WiFiManager",
|
"name": "ESPAsync_WiFiManager",
|
||||||
|
"version": ">=1.4.1",
|
||||||
"platforms": ["espressif8266", "espressif32"]
|
"platforms": ["espressif8266", "espressif32"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"owner": "stm32duino",
|
"owner": "stm32duino",
|
||||||
"name": "STM32duino LwIP",
|
"name": "STM32duino LwIP",
|
||||||
"version": "^2.1.2",
|
"version": ">=2.1.2",
|
||||||
"platforms": "ststm32"
|
"platforms": "ststm32"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"owner": "stm32duino",
|
"owner": "stm32duino",
|
||||||
"name": "STM32Ethernet",
|
"name": "STM32Ethernet",
|
||||||
"version": "^1.2.0",
|
"version": ">=1.2.0",
|
||||||
"platforms": "ststm32"
|
"platforms": "ststm32"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
name=AsyncHTTPRequest_Generic
|
name=AsyncHTTPRequest_Generic
|
||||||
version=1.0.2
|
version=1.1.0
|
||||||
author=Bob Lemaire,Khoi Hoang <khoih.prog@gmail.com>
|
author=Bob Lemaire,Khoi Hoang <khoih.prog@gmail.com>
|
||||||
maintainer=Khoi Hoang <khoih.prog@gmail.com>
|
maintainer=Khoi Hoang <khoih.prog@gmail.com>
|
||||||
license=MIT
|
license=MIT
|
||||||
sentence=Simple Async HTTP Request library, supporting GET and POST, on top of AsyncTCP libraries, such as AsyncTCP, ESPAsyncTCP, AsyncTCP_STM32, etc.. for ESP32, ESP8266 and currently STM32 with built-in LAN8742A Ethernet.
|
sentence=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, ESP8266 and currently STM32 with built-in LAN8742A Ethernet.
|
||||||
paragraph=This AsyncHTTPRequest_Generic Library, supporting GET and POST, for ESP32, ESP8266 and STM32 with built-in LAN8742A Ethernet, such as Nucleo-144 F767ZI, etc.
|
paragraph=This AsyncHTTPRequest_Generic Library, supporting GET and POST, for ESP32, ESP8266 and STM32 with built-in LAN8742A Ethernet, such as Nucleo-144 F767ZI, etc.
|
||||||
category=Communication,AsyncTCP,AsyncHTTP
|
category=Communication,AsyncTCP,AsyncHTTP
|
||||||
url=https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
url=https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
|
@@ -35,19 +35,19 @@ upload_speed = 921600
|
|||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
; PlatformIO 4.x
|
; PlatformIO 4.x
|
||||||
AsyncTCP@~1.1.1
|
AsyncTCP@>=1.1.1
|
||||||
ESPAsyncTCP@~1.2.2
|
ESPAsyncTCP@>=1.2.2
|
||||||
STM32AsyncTCP@~1.0.0
|
STM32AsyncTCP@>=1.0.0
|
||||||
STM32duino LwIP@~2.1.2
|
STM32duino LwIP@>=2.1.2
|
||||||
STM32duino STM32Ethernet@~1.2.0
|
STM32duino STM32Ethernet@>=1.2.0
|
||||||
ESPAsync_WiFiManager@~1.1.2
|
ESPAsync_WiFiManager@>=1.4.1
|
||||||
; PlatformIO 5.x
|
; PlatformIO 5.x
|
||||||
; me-no-dev/AsyncTCP@~1.1.1
|
; me-no-dev/AsyncTCP@>=1.1.1
|
||||||
; me-no-dev/ESPAsyncTCP@~1.2.2
|
; me-no-dev/ESPAsyncTCP@>=1.2.2
|
||||||
; philbowles/STM32AsyncTCP@~1.0.0
|
; philbowles/STM32AsyncTCP@>=1.0.0
|
||||||
; stm32duino/STM32duino LwIP@~2.1.2
|
; stm32duino/STM32duino LwIP@>=2.1.2
|
||||||
; stm32duino/STM32duino STM32Ethernet@~1.2.0
|
; stm32duino/STM32duino STM32Ethernet@>=1.2.0
|
||||||
; khoih-prog/ESPAsync_WiFiManager@~1.1.2
|
; khoih-prog/ESPAsync_WiFiManager@>=1.4.1
|
||||||
|
|
||||||
build_flags =
|
build_flags =
|
||||||
; set your debug output (default=Serial)
|
; set your debug output (default=Serial)
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@@ -17,18 +17,19 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "1.0.2"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.1.0"
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
@@ -225,7 +226,13 @@ class AsyncHTTPRequest
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
enum {HTTPmethodGET, HTTPmethodPOST} _HTTPmethod;
|
// New in v1.1.0
|
||||||
|
typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod;
|
||||||
|
|
||||||
|
HTTPmethod _HTTPmethod;
|
||||||
|
|
||||||
|
const char* _HTTPmethodStringwithSpace[HTTPmethodMAX] = {"GET ", "POST ", "PUT ", "PATCH ", "DELETE ", "HEAD "};
|
||||||
|
//////
|
||||||
|
|
||||||
reqStates _readyState;
|
reqStates _readyState;
|
||||||
|
|
||||||
@@ -286,3 +293,5 @@ class AsyncHTTPRequest
|
|||||||
};
|
};
|
||||||
|
|
||||||
#include "AsyncHTTPRequest_Impl_Generic.h"
|
#include "AsyncHTTPRequest_Impl_Generic.h"
|
||||||
|
|
||||||
|
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@@ -110,6 +111,7 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
|||||||
_contentRead = 0;
|
_contentRead = 0;
|
||||||
_readyState = readyStateUnsent;
|
_readyState = readyStateUnsent;
|
||||||
|
|
||||||
|
|
||||||
if (strcmp(method, "GET") == 0)
|
if (strcmp(method, "GET") == 0)
|
||||||
{
|
{
|
||||||
_HTTPmethod = HTTPmethodGET;
|
_HTTPmethod = HTTPmethodGET;
|
||||||
@@ -118,9 +120,28 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
|||||||
{
|
{
|
||||||
_HTTPmethod = HTTPmethodPOST;
|
_HTTPmethod = HTTPmethodPOST;
|
||||||
}
|
}
|
||||||
|
// New in v1.1.0
|
||||||
|
else if (strcmp(method, "PUT") == 0)
|
||||||
|
{
|
||||||
|
_HTTPmethod = HTTPmethodPUT;
|
||||||
|
}
|
||||||
|
else if (strcmp(method, "PATCH") == 0)
|
||||||
|
{
|
||||||
|
_HTTPmethod = HTTPmethodPATCH;
|
||||||
|
}
|
||||||
|
else if (strcmp(method, "DELETE") == 0)
|
||||||
|
{
|
||||||
|
_HTTPmethod = HTTPmethodDELETE;
|
||||||
|
}
|
||||||
|
else if (strcmp(method, "HEAD") == 0)
|
||||||
|
{
|
||||||
|
_HTTPmethod = HTTPmethodHEAD;
|
||||||
|
}
|
||||||
|
//////
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
if (!_parseURL(URL))
|
if (!_parseURL(URL))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -589,12 +610,18 @@ bool AsyncHTTPRequest::_buildRequest()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_request->write(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ");
|
|
||||||
|
// New in v1.1.0
|
||||||
|
_request->write(_HTTPmethodStringwithSpace[_HTTPmethod]);
|
||||||
|
//////
|
||||||
|
|
||||||
_request->write(_URL->path);
|
_request->write(_URL->path);
|
||||||
_request->write(_URL->query);
|
_request->write(_URL->query);
|
||||||
_request->write(" HTTP/1.1\r\n");
|
_request->write(" HTTP/1.1\r\n");
|
||||||
|
|
||||||
AHTTP_LOGDEBUG3(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ", _URL->path, _URL->query, " HTTP/1.1\r\n" );
|
// New in v1.1.0
|
||||||
|
AHTTP_LOGDEBUG3(_HTTPmethodStringwithSpace[_HTTPmethod], _URL->path, _URL->query, " HTTP/1.1\r\n" );
|
||||||
|
//////
|
||||||
|
|
||||||
SAFE_DELETE(_URL)
|
SAFE_DELETE(_URL)
|
||||||
|
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
/********************************************************************************************
|
/********************************************************************************************
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#include "AsyncHTTPRequest_Debug_Generic.h"
|
#include "AsyncHTTPRequest_Debug_Generic.h"
|
||||||
@@ -111,6 +112,7 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
|||||||
_contentRead = 0;
|
_contentRead = 0;
|
||||||
_readyState = readyStateUnsent;
|
_readyState = readyStateUnsent;
|
||||||
|
|
||||||
|
|
||||||
if (strcmp(method, "GET") == 0)
|
if (strcmp(method, "GET") == 0)
|
||||||
{
|
{
|
||||||
_HTTPmethod = HTTPmethodGET;
|
_HTTPmethod = HTTPmethodGET;
|
||||||
@@ -119,9 +121,28 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
|||||||
{
|
{
|
||||||
_HTTPmethod = HTTPmethodPOST;
|
_HTTPmethod = HTTPmethodPOST;
|
||||||
}
|
}
|
||||||
|
// New in v1.1.0
|
||||||
|
else if (strcmp(method, "PUT") == 0)
|
||||||
|
{
|
||||||
|
_HTTPmethod = HTTPmethodPUT;
|
||||||
|
}
|
||||||
|
else if (strcmp(method, "PATCH") == 0)
|
||||||
|
{
|
||||||
|
_HTTPmethod = HTTPmethodPATCH;
|
||||||
|
}
|
||||||
|
else if (strcmp(method, "DELETE") == 0)
|
||||||
|
{
|
||||||
|
_HTTPmethod = HTTPmethodDELETE;
|
||||||
|
}
|
||||||
|
else if (strcmp(method, "HEAD") == 0)
|
||||||
|
{
|
||||||
|
_HTTPmethod = HTTPmethodHEAD;
|
||||||
|
}
|
||||||
|
//////
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
if (!_parseURL(URL))
|
if (!_parseURL(URL))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -590,12 +611,18 @@ bool AsyncHTTPRequest::_buildRequest()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_request->write(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ");
|
|
||||||
|
// New in v1.1.0
|
||||||
|
_request->write(_HTTPmethodStringwithSpace[_HTTPmethod]);
|
||||||
|
//////
|
||||||
|
|
||||||
_request->write(_URL->path);
|
_request->write(_URL->path);
|
||||||
_request->write(_URL->query);
|
_request->write(_URL->query);
|
||||||
_request->write(" HTTP/1.1\r\n");
|
_request->write(" HTTP/1.1\r\n");
|
||||||
|
|
||||||
AHTTP_LOGDEBUG3(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ", _URL->path, _URL->query, " HTTP/1.1\r\n" );
|
// New in v1.1.0
|
||||||
|
AHTTP_LOGDEBUG3(_HTTPmethodStringwithSpace[_HTTPmethod], _URL->path, _URL->query, " HTTP/1.1\r\n" );
|
||||||
|
//////
|
||||||
|
|
||||||
SAFE_DELETE(_URL)
|
SAFE_DELETE(_URL)
|
||||||
|
|
||||||
|
@@ -17,18 +17,19 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "1.0.2"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.1.0"
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
@@ -225,7 +226,13 @@ class AsyncHTTPRequest
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
enum {HTTPmethodGET, HTTPmethodPOST} _HTTPmethod;
|
// New in v1.1.0
|
||||||
|
typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod;
|
||||||
|
|
||||||
|
HTTPmethod _HTTPmethod;
|
||||||
|
|
||||||
|
const char* _HTTPmethodStringwithSpace[HTTPmethodMAX] = {"GET ", "POST ", "PUT ", "PATCH ", "DELETE ", "HEAD "};
|
||||||
|
//////
|
||||||
|
|
||||||
reqStates _readyState;
|
reqStates _readyState;
|
||||||
|
|
||||||
@@ -285,3 +292,4 @@ class AsyncHTTPRequest
|
|||||||
bool _collectHeaders();
|
bool _collectHeaders();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
/********************************************************************************************
|
/********************************************************************************************
|
||||||
@@ -147,3 +148,5 @@ class xbuf: public Print
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include "utility/xbuf_Impl.h"
|
||||||
|
|
||||||
|
400
src_cpp/utility/xbuf_Impl.h
Normal file
400
src_cpp/utility/xbuf_Impl.h
Normal file
@@ -0,0 +1,400 @@
|
|||||||
|
/****************************************************************************************************************************
|
||||||
|
xbuf_Impl.h - Dead simple AsyncHTTPRequest for ESP8266, ESP32 and currently STM32 with built-in LAN8742A Ethernet
|
||||||
|
|
||||||
|
For ESP8266, ESP32 and STM32 with built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
|
||||||
|
|
||||||
|
AsyncHTTPRequest_STM32 is a library for the ESP8266, ESP32 and currently STM32 run built-in Ethernet WebServer
|
||||||
|
|
||||||
|
Based on and modified from asyncHTTPrequest Library (https://github.com/boblemaire/asyncHTTPrequest)
|
||||||
|
|
||||||
|
Built by Khoi Hoang https://github.com/khoih-prog/AsyncHTTPRequest_Generic
|
||||||
|
Licensed under MIT license
|
||||||
|
|
||||||
|
Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>
|
||||||
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||||
|
as published bythe Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Version: 1.1.0
|
||||||
|
|
||||||
|
Version Modified By Date Comments
|
||||||
|
------- ----------- ---------- -----------
|
||||||
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
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(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))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
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];
|
||||||
|
|
||||||
|
// KH, Must check NULL here
|
||||||
|
_tail = _tail->next;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// KH, Must check NULL here
|
||||||
|
_tail = _head = (xseg*) new uint32_t[_segSize / 4 + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@@ -17,18 +17,19 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "1.0.2"
|
#define ASYNC_HTTP_REQUEST_GENERIC_VERSION "AsyncHTTPRequest_Generic v1.1.0"
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
@@ -225,7 +226,13 @@ class AsyncHTTPRequest
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
enum {HTTPmethodGET, HTTPmethodPOST} _HTTPmethod;
|
// New in v1.1.0
|
||||||
|
typedef enum { HTTPmethodGET, HTTPmethodPOST, HTTPmethodPUT, HTTPmethodPATCH, HTTPmethodDELETE, HTTPmethodHEAD, HTTPmethodMAX } HTTPmethod;
|
||||||
|
|
||||||
|
HTTPmethod _HTTPmethod;
|
||||||
|
|
||||||
|
const char* _HTTPmethodStringwithSpace[HTTPmethodMAX] = {"GET ", "POST ", "PUT ", "PATCH ", "DELETE ", "HEAD "};
|
||||||
|
//////
|
||||||
|
|
||||||
reqStates _readyState;
|
reqStates _readyState;
|
||||||
|
|
||||||
@@ -286,3 +293,5 @@ class AsyncHTTPRequest
|
|||||||
};
|
};
|
||||||
|
|
||||||
#include "AsyncHTTPRequest_Impl_Generic.h"
|
#include "AsyncHTTPRequest_Impl_Generic.h"
|
||||||
|
|
||||||
|
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@@ -110,6 +111,7 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
|||||||
_contentRead = 0;
|
_contentRead = 0;
|
||||||
_readyState = readyStateUnsent;
|
_readyState = readyStateUnsent;
|
||||||
|
|
||||||
|
|
||||||
if (strcmp(method, "GET") == 0)
|
if (strcmp(method, "GET") == 0)
|
||||||
{
|
{
|
||||||
_HTTPmethod = HTTPmethodGET;
|
_HTTPmethod = HTTPmethodGET;
|
||||||
@@ -118,9 +120,28 @@ bool AsyncHTTPRequest::open(const char* method, const char* URL)
|
|||||||
{
|
{
|
||||||
_HTTPmethod = HTTPmethodPOST;
|
_HTTPmethod = HTTPmethodPOST;
|
||||||
}
|
}
|
||||||
|
// New in v1.1.0
|
||||||
|
else if (strcmp(method, "PUT") == 0)
|
||||||
|
{
|
||||||
|
_HTTPmethod = HTTPmethodPUT;
|
||||||
|
}
|
||||||
|
else if (strcmp(method, "PATCH") == 0)
|
||||||
|
{
|
||||||
|
_HTTPmethod = HTTPmethodPATCH;
|
||||||
|
}
|
||||||
|
else if (strcmp(method, "DELETE") == 0)
|
||||||
|
{
|
||||||
|
_HTTPmethod = HTTPmethodDELETE;
|
||||||
|
}
|
||||||
|
else if (strcmp(method, "HEAD") == 0)
|
||||||
|
{
|
||||||
|
_HTTPmethod = HTTPmethodHEAD;
|
||||||
|
}
|
||||||
|
//////
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
if (!_parseURL(URL))
|
if (!_parseURL(URL))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -589,12 +610,18 @@ bool AsyncHTTPRequest::_buildRequest()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_request->write(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ");
|
|
||||||
|
// New in v1.1.0
|
||||||
|
_request->write(_HTTPmethodStringwithSpace[_HTTPmethod]);
|
||||||
|
//////
|
||||||
|
|
||||||
_request->write(_URL->path);
|
_request->write(_URL->path);
|
||||||
_request->write(_URL->query);
|
_request->write(_URL->query);
|
||||||
_request->write(" HTTP/1.1\r\n");
|
_request->write(" HTTP/1.1\r\n");
|
||||||
|
|
||||||
AHTTP_LOGDEBUG3(_HTTPmethod == HTTPmethodGET ? "GET " : "POST ", _URL->path, _URL->query, " HTTP/1.1\r\n" );
|
// New in v1.1.0
|
||||||
|
AHTTP_LOGDEBUG3(_HTTPmethodStringwithSpace[_HTTPmethod], _URL->path, _URL->query, " HTTP/1.1\r\n" );
|
||||||
|
//////
|
||||||
|
|
||||||
SAFE_DELETE(_URL)
|
SAFE_DELETE(_URL)
|
||||||
|
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
/********************************************************************************************
|
/********************************************************************************************
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
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 <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Version: 1.0.2
|
Version: 1.1.0
|
||||||
|
|
||||||
Version Modified By Date Comments
|
Version Modified By Date Comments
|
||||||
------- ----------- ---------- -----------
|
------- ----------- ---------- -----------
|
||||||
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
1.0.0 K Hoang 14/09/2020 Initial coding to add support to STM32 using built-in Ethernet (Nucleo-144, DISCOVERY, etc).
|
||||||
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
1.0.1 K Hoang 09/10/2020 Restore cpp code besides Impl.h code.
|
||||||
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
1.0.2 K Hoang 09/11/2020 Make Mutex Lock and delete more reliable and error-proof
|
||||||
|
1.1.0 K Hoang 23/12/2020 Add HTTP PUT, PATCH, DELETE and HEAD methods
|
||||||
*****************************************************************************************************************************/
|
*****************************************************************************************************************************/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
Reference in New Issue
Block a user