khoih-prog / AsyncHTTPSRequest_Generic

Simple Async HTTPS Request library, supporting GET, POST, PUT, PATCH, DELETE and HEAD, on top of AsyncTCP_SSL library for ESP32 (including ESP32_S2, ESP32_S3 and ESP32_C3), WT32_ETH01 (ESP32 + LAN8720). Supporting in the future for RP2040W, ESP8266, Portenta_H7, STM32 with built-in LAN8742A Ethernet, etc. Now you can send HTTP / HTTPS requests to multiple addresses and receive responses from them
GNU General Public License v3.0
19 stars 4 forks source link
async async-http-https-client async-https-client async-tcp-client esp32 esp32-c3 esp32-s2 esp32-s3 https https-client lan8720 lwip lwip-enc28j60 lwip-ethernet lwip-w5500 lwip-w6100 ssl tls wifi-network wt32-eth01

AsyncHTTPSRequest_Generic Library

arduino-library-badge GitHub release contributions welcome GitHub issues

Donate to my libraries using BuyMeACoffee



Table of Contents



Important Change from v2.0.0

Breaking change to permit coexisting with AsyncHTTPRequest library. Now you can send HTTP / HTTPS requests to multiple addresses and receive responses from them.

Important Change from v1.3.0

Please have a look at HOWTO Fix Multiple Definitions Linker Error



Why do we need this Async AsyncHTTPSRequest_Generic library

Important notes for WT32_ETH01

ESP32 Core v2.0.0+ introduces new enum breaking almost all WT32_ETH01 codes written for core v1.0.6-.

It's really strange to define a breaking enum arduino_event_id_t in WiFiGeneric.h#L36-L78, compared to the old system_event_id_t, now placed in esp_event_legacy.h#L29-L63

It's better to preserve the old enum order and just adding new items to do no harm to pre-2.0.0 codes

To use with core v1.0.6-, just define in your sketch

#define USING_CORE_ESP32_CORE_V200_PLUS       false

Features

  1. Asynchronous HTTPS Request library for ESP32, ESP32_S2, ESP32_C3, ESP32_S3 using built-in WiFi, WT32_ETH01 using either WiFi of built-in LAN8720 Ethernet and ESP32 boards using LwIP ENC28J60 Ethernet
  2. Providing a subset of HTTPS.
  3. Relying on AsyncTCP_SSL library for ESP32
  4. Methods similar in format and usage to XmlHTTPrequest in Javascript.
  5. Coexist with AsyncHTTPRequest library to permit sending HTTP / HTTPS requests to multiple addresses and receive responses from them

Supports

  1. GET, POST, PUT, PATCH, DELETE and HEAD
  2. Request and response headers
  3. Chunked response
  4. Single String response for short (<~5K) responses (heap permitting).
  5. Optional onData callback.
  6. Optional onReadyStatechange callback.

Principles of operation

This library adds a simple HTTPS layer on top of the AsyncTCP_SSL library to facilitate REST communication from a Client to a Server. The paradigm is similar to the XMLHttpRequest in Javascript, employing the notion of a ready-state progression through the transaction request.

Synchronization can be accomplished using callbacks on ready-state change, a callback on data receipt, or simply polling for ready-state change. Data retrieval can be incremental as received, or bulk retrieved when the transaction completes provided there is enough heap to buffer the entire response.

The underlying buffering uses a new xbuf class. It handles both character and binary data. Class xbuf uses a chain of small (64 byte) segments that are allocated and added to the tail as data is added and deallocated from the head as data is read, achieving the same result as a dynamic circular buffer limited only by the size of heap. The xbuf implements indexOf and readUntil functions.

For short transactions, buffer space should not be an issue. In fact, it can be more economical than other methods that use larger fixed length buffers. Data is acked when retrieved by the caller, so there is some limited flow control to limit heap usage for larger transfers.

Request and response headers are handled in the typical fashion.

Chunked responses are recognized and handled transparently.

This library is based on, modified from:

  1. Bob Lemaire's asyncHTTPrequest Library
  2. Khoi Hoang's AsyncHTTPRequest_Generic Library

Currently Supported Boards

1. ESP32 including ESP32_S2 (ESP32_S2 Saola, AI-Thinker ESP-12K, etc.), ESP32_S3 and ESP32_C3

  1. ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, etc.) using EEPROM, SPIFFS or LittleFS.
  2. ESP32-C3 (ARDUINO_ESP32C3_DEV) using EEPROM, SPIFFS or LittleFS.
  3. ESP32-S3 (ESP32S3_DEV, ESP32_S3_BOX, UM TINYS3, UM PROS3, UM FEATHERS3, etc.) using EEPROM, SPIFFS or LittleFS.

2. WT32_ETH01 using ESP32-based boards and LAN8720 Ethernet

3. ESP32 boards using LwIP ENC28J60 Ethernet

4. ESP32 boards using LwIP W5500 Ethernet

5. ESP32 boards using LwIP W6100 Ethernet


To be supported boards in the future

  1. ESP8266 using either WiFi or W5x00/ENC28J60 Ethernet
  2. RP2040W using arduino-pico core
  3. STM32 using built-in LAN8742A
  4. Portenta_H7 using either Ethernet or built-in WiFi
  5. ESP32 using either LwIP W5x00, LAN83848, etc. Ethernet


Prerequisites

  1. Arduino IDE 1.8.19+ for Arduino. GitHub release
  2. ESP32 Core 2.0.6+ for ESP32-based boards. [Latest stable release Release Version
  3. AsyncTCP_SSL v1.3.1+ for ESP32. GitHub release
  4. WebServer_WT32_ETH01 v1.5.1+ for ESP32-based WT32_ETH01 using either ESP32 core v2.0.0+ or v1.0.6-. GitHub release
  5. WebServer_ESP32_ENC v1.5.3+ for ESP32 boards using LwIP ENC28J60 Ethernet. GitHub release
  6. WebServer_ESP32_W5500 v1.5.3+ for ESP32 boards using LwIP W5500 Ethernet. GitHub release
  7. WebServer_ESP32_W6100 v1.5.3+ for ESP32 boards using LwIP W6100 Ethernet. GitHub release
  8. ESPAsync_WiFiManager library v1.15.1+ for ESP32/ESP8266 using some examples. GitHub release
  9. AsyncHTTPRequest_Generic library v1.12.0+ for ESP32/ESP8266 using with AsyncHTTP_HTTPSRequest_ESP example. GitHub release


Installation

Use Arduino Library Manager

The best and easiest way is to use Arduino Library Manager. Search for AsyncHTTPSRequest_Generic, then select / install the latest version. You can also use this link arduino-library-badge for more detailed instructions.

Manual Install

  1. Navigate to AsyncHTTPSRequest_Generic page.
  2. Download the latest release AsyncHTTPSRequest_Generic-main.zip.
  3. Extract the zip file to AsyncHTTPSRequest_Generic-main directory
  4. Copy the whole AsyncHTTPSRequest_Generic-main folder to Arduino libraries' directory such as ~/Arduino/libraries/.

VS Code & PlatformIO

  1. Install VS Code
  2. Install PlatformIO
  3. Install AsyncHTTPSRequest_Generic library by using Library Manager. Search for AsyncHTTPSRequest_Generic in Platform.io Author's Libraries
  4. Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File


Note for Platform IO using ESP32 LittleFS

In Platform IO, to fix the error when using LittleFS_esp32 v1.0 for ESP32-based boards with ESP32 core v1.0.4- (ESP-IDF v3.2-), uncomment the following line

from

//#define CONFIG_LITTLEFS_FOR_IDF_3_2   /* For old IDF - like in release 1.0.4 */

to

#define CONFIG_LITTLEFS_FOR_IDF_3_2   /* For old IDF - like in release 1.0.4 */

It's advisable to use the latest LittleFS_esp32 v1.0.5+ to avoid the issue.

Thanks to Roshan to report the issue in Error esp_littlefs.c 'utime_p'



HOWTO Fix Multiple Definitions Linker Error

The current library implementation, using xyz-Impl.h instead of standard xyz.cpp, possibly creates certain Multiple Definitions Linker error in certain use cases.

You can include this .hpp file

// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "AsyncHTTPSRequest_Generic.hpp"     //https://github.com/khoih-prog/AsyncHTTPSRequest_Generic

in many files. But be sure to use the following .h file in just 1 .h, .cpp or .ino file, which must not be included in any other file, to avoid Multiple Definitions Linker Error

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "AsyncHTTPSRequest_Generic.h"           //https://github.com/khoih-prog/AsyncHTTPSRequest_Generic

Check the new multiFileProject example for a HOWTO demo.

Have a look at the discussion in Different behaviour using the src_cpp or src_h lib #80



Note for Platform IO using ESP32 LittleFS

In Platform IO, to fix the error when using LittleFS_esp32 v1.0 for ESP32-based boards with ESP32 core v1.0.4- (ESP-IDF v3.2-), uncomment the following line

from

//#define CONFIG_LITTLEFS_FOR_IDF_3_2   /* For old IDF - like in release 1.0.4 */

to

#define CONFIG_LITTLEFS_FOR_IDF_3_2   /* For old IDF - like in release 1.0.4 */

It's advisable to use the latest LittleFS_esp32 v1.0.5+ to avoid the issue.

Thanks to Roshan to report the issue in Error esp_littlefs.c 'utime_p'



HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)

Please have a look at ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example to have more detailed description and solution of the issue.

1. ESP32 has 2 ADCs, named ADC1 and ADC2

2. ESP32 ADCs functions

3.. ESP32 WiFi uses ADC2 for WiFi functions

Look in file adc_common.c

In ADC2, there're two locks used for different cases:

  1. lock shared with app and Wi-Fi: ESP32: When Wi-Fi using the ADC2, we assume it will never stop, so app checks the lock and returns immediately if failed. ESP32S2: The controller's control over the ADC is determined by the arbiter. There is no need to control by lock.

  2. lock shared between tasks: when several tasks sharing the ADC2, we want to guarantee all the requests will be handled. Since conversions are short (about 31us), app returns the lock very soon, we use a spinlock to stand there waiting to do conversions one by one.

adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock.



HOWTO use ESP32 with LwIP W5500 or ENC28J60 Ethernet

1. ESP32 Wiring

This is the wiring for ESP8266 W5500, W6100 or ENC28J60 Ethernet when using SS = GPIO5

https://github.com/khoih-prog/AsyncHTTPSRequest_Generic/blob/6168613ea8c6cb4fd9dcdf831bacba7d0db04fa6/examples/ESP32_W5500/AsyncHTTPSRequest_ESP32_W5500/AsyncHTTPSRequest_ESP32_W5500.ino#L81-L92

W5x00/W6100/ENC28J60 Ethernet <---> ESP32
MOSI <---> MOSI = GPIO23
MISO <---> MISO = GPIO19
SCK <---> SCK = GPIO18
SS <---> GPIO5
INT <---> GPIO4
GND <---> GND
VCC <---> +3.3V


Examples

For ESP32

  1. AsyncHTTPSRequest_ESP
  2. AsyncHTTPSRequest_ESP_WiFiManager
  3. AsyncHTTPSRequest_ESP_Multi New
  4. AsyncHTTP_HTTPSRequest_ESP New

For WT32_ETH01

  1. AsyncHTTPSRequest_WT32_ETH01

For ESP32_ENC

  1. AsyncHTTPSRequest_ESP32_ENC

For ESP32_W5500

  1. AsyncHTTPSRequest_ESP32_W5500

For ESP32_W6100

  1. AsyncHTTPSRequest_ESP32_W6100

For ESP32, WT32_ETH01, ESP32_ENC, ESP32_W5500 or ESP32_W6100

  1. multiFileProject

Example AsyncHTTP_HTTPSRequest_ESP

https://github.com/khoih-prog/AsyncHTTPSRequest_Generic/blob/c1fc1a5e4c6948f30b741553db2ce5e95c555175/examples/AsyncHTTP_HTTPSRequest_ESP/AsyncHTTP_HTTPSRequest_ESP.ino#L43-L402



Debug Terminal Output Samples

1. AsyncHTTPSRequest_ESP on ESP32_DEV

Following is the debug terminal when running example AsyncHTTPSRequest_ESP on ESP32_DEV to demonstrate the operation of SSL Async HTTPS request, using AsyncTCP_SSL Library.

Starting AsyncHTTPSRequest_ESP using ESP32_DEV
AsyncTCP_SSL v1.3.1
AsyncHTTPSRequest_Generic v2.5.0
Connecting to WiFi SSID: HueNet1
...
AsyncHTTPSRequest @ IP : 192.168.2.80
[AHTTPS] open: connecting to hostname = worldtimeapi.org:443    <====== New connect attempt
[AHTTPS] _client->connecting to worldtimeapi.org , 443
[AHTTPS] client.connect OK to worldtimeapi.org , 443

**************************************
[AHTTPS] Response Code =  HTTP OK

**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:01:30.472515-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224090
utc_datetime: 2023-02-01T04:01:30.472515+00:00
utc_offset: -05:00
week_number: 5
**************************************
HH[AHTTPS] open: already connected    <====== No more connect attempt. Optional
H
**************************************
[AHTTPS] Response Code =  HTTP OK

**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:02:24.463788-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224144
utc_datetime: 2023-02-01T04:02:24.463788+00:00
utc_offset: -05:00
week_number: 5
**************************************

2. AsyncHTTPSRequest_ESP on ESP32S2_DEV

Following is the debug terminal when running example AsyncHTTPSRequest_ESP on ESP32S2_DEV to demonstrate the operation of SSL Async HTTPS request, using AsyncTCP_SSL Library.

Starting AsyncHTTPSRequest_ESP using ESP32S2_DEV
AsyncTCP_SSL v1.3.1
AsyncHTTPSRequest_Generic v2.5.0
Connecting to WiFi SSID: HueNet1
.......
AsyncHTTPSRequest @ IP : 192.168.2.79
[ATCP] _handle_async_event: LWIP_TCP_DNS = 0x3FFE4E24
[ATCP] _handle_async_event: LWIP_TCP_DNS, name = worldtimeapi.org , IP = 213.188.196.246
[ATCP] _handle_async_event: LWIP_TCP_CONNECTED = 0x3FFE4E24 0x3FFE5024
[ATCP] _handle_async_event: LWIP_TCP_CONNECTED =  0
[ATCP] _handle_async_event: LWIP_TCP_SENT = 0x3FFE5024
[ATCP] _sent: len = 305
[ATCP] _handle_async_event: LWIP_TCP_RECV = 0x3FFE5024
[ATCP] _recv: tot_len = 1436
[ATCP] _handle_async_event: LWIP_TCP_RECV = 0x3FFE5024
[ATCP] _recv: tot_len = 1436
[ATCP] _handle_async_event: LWIP_TCP_RECV = 0x3FFE5024
[ATCP] _recv: tot_len = 1242
[ATCP] _handle_async_event: LWIP_TCP_SENT = 0x3FFE5024
[ATCP] _sent: len = 107
[ATCP] _handle_async_event: LWIP_TCP_SENT = 0x3FFE5024
[ATCP] _sent: len = 6
[ATCP] _handle_async_event: LWIP_TCP_SENT = 0x3FFE5024
[ATCP] _sent: len = 45
[ATCP] _handle_async_event: LWIP_TCP_RECV = 0x3FFE5024
[ATCP] _recv: tot_len = 51
[ATCP] _handle_async_event: LWIP_TCP_SENT = 0x3FFE5024
[ATCP] _sent: len = 106
[ATCP] _handle_async_event: LWIP_TCP_RECV = 0x3FFE5024
[ATCP] _recv: tot_len = 1016
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:02:24.463788-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224144
utc_datetime: 2023-02-01T04:02:24.463788+00:00
utc_offset: -05:00
week_number: 5
**************************************
HHHHHH
**************************************
[AHTTPS] Response Code =  HTTP OK

**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:03:24.464007-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224204
utc_datetime: 2023-02-01T04:03:24.464007+00:00
utc_offset: -05:00
week_number: 5
**************************************

3. AsyncHTTPSRequest_ESP on ESP32C3_DEV

Following is the debug terminal when running example AsyncHTTPSRequest_ESP on ESP32C3_DEV to demonstrate the operation of SSL Async HTTPS request, using AsyncTCP_SSL Library.

Starting AsyncHTTPSRequest_ESP using ESP32C3_DEV
AsyncTCP_SSL v1.3.1
AsyncHTTPSRequest_Generic v2.5.0
Connecting to WiFi SSID: HueNet1
.........
AsyncHTTPSRequest @ IP : 192.168.2.80
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:03:24.464007-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224204
utc_datetime: 2023-02-01T04:03:24.464007+00:00
utc_offset: -05:00
week_number: 5
**************************************
HHHHHH
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:04:24.464088-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224264
utc_datetime: 2023-02-01T04:04:24.464088+00:00
utc_offset: -05:00
week_number: 5
**************************************

4. AsyncHTTPSRequest_ESP_WiFiManager on ESP32_DEV

Following is the debug terminal when running example AsyncHTTPSRequest_ESP_WiFiManager on ESP32_DEV to demonstrate the operation of SSL Async HTTPS request, using AsyncTCP_SSL Library, and ESPAsync_WiFiManager Library

Starting AsyncHTTPSRequest_ESP_WiFiManager using LittleFS on ESP32_DEV
ESPAsync_WiFiManager v1.15.1
AsyncTCP_SSL v1.3.1
AsyncHTTPSRequest_Generic v2.5.0
Stored: SSID = HueNet1, Pass = 12345678
Got stored Credentials. Timeout 120s
ConnectMultiWiFi in setup
After waiting 11.38 secs more in setup(), connection result is connected. Local IP: 192.168.2.232
H
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:05:24.465017-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224324
utc_datetime: 2023-02-01T04:05:24.465017+00:00
utc_offset: -05:00
week_number: 5
**************************************
H

5. AsyncHTTPSRequest_WT32_ETH01 on WT32_ETH01 using ESP32 core v2.0.0

Following is the debug terminal when running example AsyncHTTPSRequest_WT32_ETH01 on WT32_ETH01 to demonstrate the operation of SSL Async HTTPS request, using AsyncTCP_SSL Library and ESP32 core v2.0.0

Starting AsyncHTTPSRequest_WT32_ETH01 using ESP32_DEV with ETH_PHY_LAN8720
WebServer_WT32_ETH01 v1.5.1 for core v2.0.0+
AsyncTCP_SSL v1.3.1
AsyncHTTPSRequest_Generic v2.5.0
ETH MAC: A8:03:2A:A1:61:73, IPv4: 192.168.2.82, FULL_DUPLEX, 100Mbps

HTTP WebClient is @ IP : 192.168.2.82

**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:06:24.463935-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224384
utc_datetime: 2023-02-01T04:06:24.463935+00:00
utc_offset: -05:00
week_number: 5
**************************************

6. AsyncHTTPSRequest_WT32_ETH01 on WT32_ETH01 using ESP32 core v1.0.6

Following is the debug terminal when running example AsyncHTTPSRequest_WT32_ETH01 on WT32_ETH01 to demonstrate the operation of SSL Async HTTPS request, using AsyncTCP_SSL Library and ESP32 core v1.0.6

Starting AsyncHTTPSRequest_WT32_ETH01 using ESP32_DEV with ETH_PHY_LAN8720
WebServer_WT32_ETH01 v1.5.1 for core v1.0.6-
AsyncTCP_SSL v1.3.1
AsyncHTTPSRequest_Generic v2.5.0
ETH MAC: A8:03:2A:A1:61:73, IPv4: 192.168.2.232, FULL_DUPLEX, 100Mbps

HTTP WebClient is @ IP : 192.168.2.232
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:08:24.467686-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224504
utc_datetime: 2023-02-01T04:08:24.467686+00:00
utc_offset: -05:00
week_number: 5
**************************************

7. AsyncHTTPSRequest_ESP_WiFiManager using LittleFS on ESP32C3_DEV

Following is the debug terminal when running example AsyncHTTPSRequest_ESP_WiFiManager on ESP32C3_DEV to demonstrate the operation of SSL Async HTTPS request, using AsyncTCP_SSL Library, and ESPAsync_WiFiManager Library

Starting AsyncHTTPSRequest_ESP_WiFiManager using LittleFS on ESP32C3_DEV
ESPAsync_WiFiManager v1.15.1
AsyncHTTPSRequest_Generic v2.5.0
Stored: SSID = HueNet1, Pass = password
Got stored Credentials. Timeout 120s
ConnectMultiWiFi in setup
After waiting 8.75 secs more in setup(), connection result is connected. Local IP: 192.168.2.85
H
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:08:24.467686-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224504
utc_datetime: 2023-02-01T04:08:24.467686+00:00
utc_offset: -05:00
week_number: 5
**************************************
HHHHHH 
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:09:24.464676-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224564
utc_datetime: 2023-02-01T04:09:24.464676+00:00
utc_offset: -05:00
week_number: 5
**************************************
HH

8. AsyncHTTPSRequest_ESP_WiFiManager using LittleFS on ESP32S3_DEV

Following is the debug terminal when running example AsyncHTTPSRequest_ESP_WiFiManager on ESP32S3_DEV to demonstrate the operation of SSL Async HTTPS request, using AsyncTCP_SSL Library, and ESPAsync_WiFiManager Library

Starting AsyncHTTPSRequest_ESP_WiFiManager using LittleFS on ESP32S3_DEV
ESPAsync_WiFiManager v1.15.1
AsyncHTTPSRequest_Generic v2.5.0
Stored: SSID = HueNet1, Pass = password
Got stored Credentials. Timeout 120s
ConnectMultiWiFi in setup
After waiting 8.26 secs more in setup(), connection result is connected. Local IP: 192.168.2.83
H
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:10:24.464712-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224624
utc_datetime: 2023-02-01T04:10:24.464712+00:00
utc_offset: -05:00
week_number: 5
**************************************
HHHH

9. AsyncHTTPSRequest_ESP_Multi on ESP32_DEV

The terminal output of AsyncHTTPSRequest_ESP_Multi example running on ESP32_DEV to demonstrate how to send requests to multiple addresses and receive responses from them.

Starting AsyncHTTPSRequest_ESP_Multi on ESP32_DEV
AsyncTCP_SSL v1.3.1
AsyncHTTPSRequest_Generic v2.5.0
Connecting to WiFi SSID: HueNet1
...
AsyncHTTPSRequest @ IP : 192.168.2.187

Sending request: https://worldtimeapi.org/api/timezone/Europe/Prague.txt

Sending request: https://www.myexternalip.com/raw
[AHTTPS] _onError handler SSL error = OK
[AHTTPS] _onError handler SSL error = OK

**************************************
[AHTTPS] Response Code =  HTTP OK

**************************************
aaa.bbb.ccc.ddd
**************************************

**************************************
[AHTTPS] Response Code =  HTTP OK

**************************************
abbreviation: CET
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-02-01T03:44:24.015957+01:00
day_of_week: 3
day_of_year: 32
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: 3600
timezone: Europe/Prague
unixtime: 1675219464
utc_datetime: 2023-02-01T02:44:24.015957+00:00
utc_offset: +01:00
week_number: 5
**************************************

Sending request: https://worldtimeapi.org/api/timezone/America/Toronto.txt

**************************************
[AHTTPS] Response Code =  HTTP OK

**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T21:44:24.210700-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675219464
utc_datetime: 2023-02-01T02:44:24.210700+00:00
utc_offset: -05:00
week_number: 5
**************************************
H

10. AsyncHTTP_HTTPSRequest_ESP on ESP32_DEV

The terminal output of AsyncHTTP_HTTPSRequest_ESP example running on ESP32_DEV to demonstrate how to send HTTP and HTTPS requests to multiple addresses and receive responses from them.

Starting AsyncHTTP_HTTPSRequest_ESP on ESP32_DEV
AsyncTCP_SSL v1.3.1
AsyncHTTPSRequest_Generic v2.5.0
AsyncHTTPRequest_Generic v1.12.0
Connecting to WiFi SSID: HueNet1
...
AsyncHTTPSRequest @ IP : 192.168.2.80

Sending HTTPS request: https://worldtimeapi.org/api/timezone/Europe/Prague.txt

Sending HTTP request: http://worldtimeapi.org/api/timezone/America/Vancouver.txt

Sending HTTP request: http://www.myexternalip.com/raw

**************************************
aaa.bbb.ccc.ddd
**************************************

**************************************
abbreviation: PST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T18:44:24.061420-08:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -28800
timezone: America/Vancouver
unixtime: 1675219464
utc_datetime: 2023-02-01T02:44:24.061420+00:00
utc_offset: -08:00
week_number: 5
**************************************

**************************************
[AHTTPS] Response Code =  HTTP OK

**************************************
abbreviation: CET
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-02-01T03:44:24.015957+01:00
day_of_week: 3
day_of_year: 32
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: 3600
timezone: Europe/Prague
unixtime: 1675219464
utc_datetime: 2023-02-01T02:44:24.015957+00:00
utc_offset: +01:00
week_number: 5
**************************************

Sending HTTPS request: https://worldtimeapi.org/api/timezone/America/Toronto.txt

**************************************
[AHTTPS] Response Code =  HTTP OK

**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T21:44:24.210700-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675219464
utc_datetime: 2023-02-01T02:44:24.210700+00:00
utc_offset: -05:00
week_number: 5
**************************************

11. AsyncHTTPSRequest_ESP32_ENC using ESP32_DEV with ESP32_ENC28J60

Following is the debug terminal when running example AsyncHTTPSRequest_ESP32_ENC on ESP32_DEV boards using LwIP ENC28J60 Ethernet, to demonstrate the operation of SSL Async HTTPS request, using AsyncTCP_SSL Library

Starting AsyncHTTPSRequest_ESP32_ENC using ESP32_DEV with ESP32_ENC28J60
WebServer_ESP32_ENC v1.5.3 for core v2.0.0+
AsyncTCP_SSL v1.3.1
AsyncHTTPSRequest_Generic v2.5.0
[AHTTPS] Default SPI pinout:
[AHTTPS] MOSI: 23
[AHTTPS] MISO: 19
[AHTTPS] SCK: 18
[AHTTPS] CS: 5
[AHTTPS] INT: 4
[AHTTPS] SPI Clock (MHz): 8
[AHTTPS] =========================

ETH Started
ETH Connected
ETH MAC: DE:AD:BE:EF:FE:01, IPv4: 192.168.2.95
FULL_DUPLEX, 10Mbps

HTTP WebClient is @ IP : 192.168.2.95

**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:14:24.465232-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224864
utc_datetime: 2023-02-01T04:14:24.465232+00:00
utc_offset: -05:00
week_number: 5
**************************************
HHHHHH
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:15:24.464696-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224924
utc_datetime: 2023-02-01T04:15:24.464696+00:00
utc_offset: -05:00
week_number: 5
**************************************

12. AsyncHTTPSRequest_ESP32_W5500 using ESP32_DEV with ESP32_W5500

Following is the debug terminal when running example AsyncHTTPSRequest_ESP32_W5500 on ESP32_DEV boards using LwIP W5500 Ethernet, to demonstrate the operation of SSL Async HTTPS request, using AsyncTCP_SSL Library

Starting AsyncHTTPSRequest_ESP32_W5500 using ESP32_DEV with ESP32_W5500
WebServer_ESP32_W5500 v1.5.3 for core v2.0.0+
AsyncTCP_SSL v1.3.1
AsyncHTTPSRequest_Generic v2.5.0
[AHTTPS] Default SPI pinout:
[AHTTPS] SPI_HOST: 2
[AHTTPS] MOSI: 23
[AHTTPS] MISO: 19
[AHTTPS] SCK: 18
[AHTTPS] CS: 5
[AHTTPS] INT: 4
[AHTTPS] SPI Clock (MHz): 25
[AHTTPS] =========================

ETH Started
ETH Connected
ETH MAC: DE:AD:BE:EF:BE:12, IPv4: 192.168.2.103
FULL_DUPLEX, 100Mbps

HTTP WebClient is @ IP : 192.168.2.103

**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:10:24.464712-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224624
utc_datetime: 2023-02-01T04:10:24.464712+00:00
utc_offset: -05:00
week_number: 5
**************************************
HHHHHH
**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:11:24.464025-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224684
utc_datetime: 2023-02-01T04:11:24.464025+00:00
utc_offset: -05:00
week_number: 5
**************************************
HHHH

13. AsyncHTTPSRequest_ESP32_W6100 using ESP32_DEV with ESP32_W6100

Following is the debug terminal when running example AsyncHTTPSRequest_ESP32_W6100 on ESP32_DEV boards using LwIP W6100 Ethernet, to demonstrate the operation of SSL Async HTTPS request, using AsyncTCP_SSL Library

Starting AsyncHTTPSRequest_ESP32_W6100 using ESP32_DEV with ESP32_W6100
WebServer_ESP32_W6100 v1.5.3 for core v2.0.0+
AsyncTCP_SSL v1.3.1
AsyncHTTPSRequest_Generic v2.5.0
[AHTTPS] Default SPI pinout:
[AHTTPS] SPI_HOST: 2
[AHTTPS] MOSI: 23
[AHTTPS] MISO: 19
[AHTTPS] SCK: 18
[AHTTPS] CS: 5
[AHTTPS] INT: 4
[AHTTPS] SPI Clock (MHz): 25
[AHTTPS] =========================

ETH Started
ETH Connected
ETH MAC: 98:F4:AB:09:13:EB, IPv4: 192.168.2.154
FULL_DUPLEX, 100Mbps

HTTP WebClient is @ IP : 192.168.2.154

**************************************
abbreviation: EST
client_ip: aaa.bbb.ccc.ddd
datetime: 2023-01-31T23:01:30.472515-05:00
day_of_week: 2
day_of_year: 31
dst: false
dst_from: 
dst_offset: 0
dst_until: 
raw_offset: -18000
timezone: America/Toronto
unixtime: 1675224090
utc_datetime: 2023-02-01T04:01:30.472515+00:00
utc_offset: -05:00
week_number: 5
**************************************
H


Debug

Debug is enabled by default on Serial.

You can also change the debugging level from 0 to 4

#define ASYNC_HTTP_DEBUG_PORT           Serial

// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_TCP_SSL_LOGLEVEL_        1
#define _ASYNC_HTTPS_LOGLEVEL_          2

Troubleshooting

If you get compilation errors, more often than not, you may need to install a newer version of the ESP32 / ESP8266 / STM32 core for Arduino.

Sometimes, the library will only work if you update the ESP32 / ESP8266 / STM32 core to the latest version because I am using newly added functions.


Issues

Submit issues to: AsyncHTTPSRequest_Generic issues



TO DO

  1. Fix bug. Add enhancement
  2. Add support to more Ethernet / WiFi shields
  3. Add support to RP2040W, ESP8266, Portenta_H7, STM32 and many more boards
  4. Add many more examples.


DONE

  1. Initially add support to ESP32 using built-in WiFi
  2. Support breaking ESP32 core v2.0.0+ as well as v1.0.6-
  3. Auto detect ESP32 core v1.0.6- or v2.0.0+ to use correct settings
  4. Fix multiple-definitions linker error and weird bug related to src_cpp.
  5. Enable compatibility with old code to include only AsyncHTTPSRequest_Generic.h
  6. Modify to be compatible with AsyncTCP_SSL releases v1.2.0+
  7. Add complex example AsyncHTTPSRequest_ESP_WiFiManager
  8. Add support to ESP32-S3 (ESP32S3_DEV, ESP32_S3_BOX, UM TINYS3, UM PROS3, UM FEATHERS3, etc.) using EEPROM, SPIFFS or LittleFS
  9. Add LittleFS support to ESP32-C3
    1. Use ESP32-core's LittleFS library instead of Lorol's LITTLEFS library for ESP32 core v2.0.0+
    2. Add example AsyncHTTPSRequest_ESP_Multi to demonstrate how to send requests to multiple addresses and receive responses from them.
    3. Permit coexisting with AsyncHTTPRequest library to send and receive both HTTP and HTTPS
    4. Add example AsyncHTTP_HTTPSRequest_ESP to demonstrate how to send HTTP and HTTPS requests to multiple addresses and receive responses from them.
    5. Increase DEFAULT_RX_TIMEOUT to 30s from 3s for slower networks.
    6. Fix long timeout if using bad or unreachable IPAddress
    7. Display only successful responseText in examples
    8. Improve debug messages by adding functions to display error messages instead of cryptic error number
    9. Fix ESP32 chipID for exampleAsyncHTTPSRequest_ESP_WiFiManager
    10. Not try to reconnect to the same host:port after connected.
    11. Fix crash and memory leak
    12. Default to reconnect to the same host:port after connected for new HTTP sites.
    13. Use allman astyle
    14. Add support to ESP32 boards using LwIP ENC28J60 Ethernet
    15. Add support to ESP32 boards using LwIP W5500 Ethernet
    16. Fix "blank new line in chunk" bug #50
    17. Add support to ESP32 boards using LwIP W6100 Ethernet
    18. Fix bug of wrong reqStates. Check Callback behavior buggy #19
    19. Fix bug of _parseURL(). Check Bug with _parseURL() #21
    20. Improve README.md so that links can be used in other sites, such as PIO


Contributions and Thanks

This library is based on, modified, bug-fixed and improved from:

  1. Bob Lemaire's asyncHTTPrequest Library to use the better asynchronous features of the following Async SSL TCP Libraries : ( AsyncTCP_SSL ).
  2. Thanks to DavidAntonin
  3. Thanks to Glenn West
  4. Thanks to rjjrbatarao
    • to request enhancement in setReuse feature #12 leading to new release v2.1.3 to not try to reconnect to the same host:port after connected
  5. Thanks to Roeland Kluit
  6. Thanks to emmettprexus to report Getting 400 Bad Request on second call to same host #14 leading to new release v2.2.1
  7. Thanks to joaorolemberg to report Callback behavior buggy #19 leading to new release v2.5.0
  8. Thanks to redphx to report Bug with _parseURL() #21 leading to new release v2.5.0
boblemaire
⭐️ Bob Lemaire

DavidAntonin
David Antonin

glennswest
Glenn West

rjjrbatarao
rjjrbatarao

roel80
Roeland Kluit

emmettprexus
emmettprexus

joaorolemberg
joaorolemberg

redphx
redphx


Contributing

If you want to contribute to this project:


License and credits


Copyright

Copyright (C) <2018> <Bob Lemaire, IoTaWatt, Inc.>

Copyright (C) 2021- Khoi Hoang