---
title: "W6100 khoih-prog / AsyncHTTPRequest_ESP32_Ethernet"
url: "https://maker.wiznet.io/eric_g/projects/khoih-prog-asynchttprequest-esp32-ethernet/"
markdown_url: "https://maker.wiznet.io/eric_g/projects/khoih-prog-asynchttprequest-esp32-ethernet/md"
type: "UCC: User Created Content"
author: "khoih prog"
author_url: "https://github.com/khoih-prog/AsyncHTTPRequest_ESP32_Ethernet"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "khoih prog"
original_url: "https://github.com/khoih-prog/AsyncHTTPRequest_ESP32_Ethernet"
published: "2023-02-01"
language: "en"
hardware: ["WIZnet W6100"]
likes: 2
views: 444
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# W6100 khoih-prog / AsyncHTTPRequest_ESP32_Ethernet

> Providing a subset of HTTP. Relying on AsyncTCP Methods similar in format and usage to XmlHTTPrequest in Javascript.

Original author: khoih prog (source: https://github.com/khoih-prog/AsyncHTTPRequest_ESP32_Ethernet)

## Components

- **WIZnet W6100** x 1 ([docs](https://docs.wiznet.io/Product/iEthernet/W6100/))

## Documents and links

- [Async HTTP Request](https://github.com/khoih-prog/AsyncHTTPRequest_ESP32_Ethernet) (code)

## Article

### Supports

1. **GET, POST, PUT, PATCH, DELETE and HEAD**

2. Request and response headers

3. Chunked response

4. Single String response for short (&lt;~5K) responses (heap permitting).

5. Optional onData callback.

6. Optional onReadyStatechange callback.W6100

### Example [AsyncHTTPRequest_ESP32_SC_W5500](https://github.com/khoih-prog/AsyncHTTPRequest_ESP32_Ethernet/blob/main/examples/ESP32_SC_W5500/AsyncHTTPRequest_ESP32_SC_W5500)

[AsyncHTTPRequest_ESP32_Ethernet/examples/ESP32_SC_W5500/AsyncHTTPRequest_ESP32_SC_W5500/AsyncHTTPRequest_ESP32_SC_W5500.ino](https://github.com/khoih-prog/AsyncHTTPRequest_ESP32_Ethernet/blob/3272f5f62c0be7783a3a82c547e30951b8b7dc14/examples/ESP32_SC_W5500/AsyncHTTPRequest_ESP32_SC_W5500/AsyncHTTPRequest_ESP32_SC_W5500.ino#L43-L284)

Lines 43 to 284 in [3272f5f](https://github.com/khoih-prog/AsyncHTTPRequest_ESP32_Ethernet/commit/3272f5f62c0be7783a3a82c547e30951b8b7dc14)

|  | #if !( defined(ESP32) ) |
| --- | --- |
|  | #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. |
|  | #endif |
|  |  |
|  | // Level from 0-4 |
|  | #define ASYNC_HTTP_DEBUG_PORT Serial |
|  | #define _ASYNC_HTTP_LOGLEVEL_ 1 |
|  | #define _ETHERNET_WEBSERVER_LOGLEVEL_ 1 |
|  |  |
|  | // 300s = 5 minutes to not flooding |
|  | #define HTTP_REQUEST_INTERVAL 60 //300 |
|  |  |
|  | // 10s |
|  | #define HEARTBEAT_INTERVAL 10 |
|  |  |
|  | ////////////////////////////////////////////////////////// |
|  |  |
|  | // For ESP32-S3 |
|  | // Optional values to override default settings |
|  | //#define ETH_SPI_HOST SPI2_HOST |
|  | //#define SPI_CLOCK_MHZ 8 |
|  |  |
|  | // Must connect INT to GPIOxx or not working |
|  | //#define INT_GPIO 4 |
|  |  |
|  | //#define MISO_GPIO 13 |
|  | //#define MOSI_GPIO 11 |
|  | //#define SCK_GPIO 12 |
|  | //#define CS_GPIO 10 |
|  |  |
|  | // For ESP32_C3 |
|  | // Optional values to override default settings |
|  | // Don't change unless you know what you're doing |
|  | //#define ETH_SPI_HOST SPI2_HOST |
|  | //#define SPI_CLOCK_MHZ 8 |
|  |  |
|  | // Must connect INT to GPIOxx or not working |
|  | //#define INT_GPIO 10 |
|  |  |
|  | //#define MISO_GPIO 5 |
|  | //#define MOSI_GPIO 6 |
|  | //#define SCK_GPIO 4 |
|  | //#define CS_GPIO 7 |
|  |  |
|  | ////////////////////////////////////////////////////////// |
|  |  |
|  | #include &lt;WebServer_ESP32_SC_W5500.h> // https://github.com/khoih-prog/WebServer_ESP32_SC_W5500 |
|  |  |
|  | #define ASYNC_HTTP_REQUEST_ESP32_ETHERNET_VERSION_MIN_TARGET "AsyncHTTPRequest_ESP32_Ethernet v1.14.0" |
|  | #define ASYNC_HTTP_REQUEST_ESP32_ETHERNET_VERSION_MIN 1014000 |
|  |  |
|  | // Uncomment for certain HTTP site to optimize |
|  | //#define NOT_SEND_HEADER_AFTER_CONNECTED true |
|  |  |
|  | // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error |
|  | #include &lt;AsyncHTTPRequest_ESP32_Ethernet.h> // https://github.com/khoih-prog/AsyncHTTPRequest_ESP32_Ethernet |
|  |  |
|  | #include &lt;Ticker.h> |
|  |  |
|  | AsyncHTTPRequest request; |
|  | Ticker ticker; |
|  | Ticker ticker1; |
|  |  |
|  | ///////////////////////////////////////////// |
|  |  |
|  | // Enter a MAC address and IP address for your controller below. |
|  | #define NUMBER_OF_MAC 20 |
|  |  |
|  | byte mac[][NUMBER_OF_MAC] = |
|  | { |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 }, |
|  | { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 }, |
|  | }; |
|  |  |
|  | // Select the IP address according to your local network |
|  | IPAddress myIP(192, 168, 2, 232); |
|  | IPAddress myGW(192, 168, 2, 1); |
|  | IPAddress mySN(255, 255, 255, 0); |
|  |  |
|  | // Google DNS Server IP |
|  | IPAddress myDNS(8, 8, 8, 8); |
|  |  |
|  | ///////////////////////////////////////////// |
|  |  |
|  | void heartBeatPrint(void) |
|  | { |
|  | static int num = 1; |
|  |  |
|  | if (ESP32_W5500_isConnected()) |
|  | Serial.print(F("H")); // H means connected |
|  | else |
|  | Serial.print(F("F")); // F means not connected |
|  |  |
|  | if (num == 80) |
|  | { |
|  | Serial.println(); |
|  | num = 1; |
|  | } |
|  | else if (num++ % 10 == 0) |
|  | { |
|  | Serial.print(F(" ")); |
|  | } |
|  | } |
|  |  |
|  | void sendRequest() |
|  | { |
|  | static bool requestOpenResult; |
|  |  |
|  | if (request.readyState() == readyStateUnsent \|\| request.readyState() == readyStateDone) |
|  | { |
|  | //requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt"); |
|  | requestOpenResult = request.open("GET", "http://worldtimeapi.org/api/timezone/America/Toronto.txt"); |
|  |  |
|  | if (requestOpenResult) |
|  | { |
|  | // Only send() if open() returns true, or crash |
|  | request.send(); |
|  | } |
|  | else |
|  | { |
|  | Serial.println("Can't send bad request"); |
|  | } |
|  | } |
|  | else |
|  | { |
|  | Serial.println("Can't send request"); |
|  | } |
|  | } |
|  |  |
|  | void requestCB(void *optParm, AsyncHTTPRequest *request, int readyState) |
|  | { |
|  | (void) optParm; |
|  |  |
|  | if (readyState == readyStateDone) |
|  | { |
|  | AHTTP_LOGDEBUG(F("\n**")); |
|  | AHTTP_LOGDEBUG1(F("Response Code = "), request->responseHTTPString()); |
|  |  |
|  | if (request->responseHTTPcode() == 200) |
|  | { |
|  | Serial.println(F("\n**")); |
|  | Serial.println(request->responseText()); |
|  | Serial.println(F("**")); |
|  | } |
|  | } |
|  | } |
|  |  |
|  | void setup() |
|  | { |
|  | // put your setup code here, to run once: |
|  | Serial.begin(115200); |
|  |  |
|  | while (!Serial && millis() &lt; 5000); |
|  |  |
|  | delay(500); |
|  |  |
|  | Serial.print("\nStart AsyncHTTPRequest_ESP32_SC_W5500 on "); |
|  | Serial.print(ARDUINO_BOARD); |
|  | Serial.print(" with "); |
|  | Serial.println(SHIELD_TYPE); |
|  | Serial.println(WEBSERVER_ESP32_SC_W5500_VERSION); |
|  | Serial.println(ASYNC_HTTP_REQUEST_ESP32_ETHERNET_VERSION); |
|  |  |
|  | Serial.setDebugOutput(true); |
|  |  |
|  | #if defined(ASYNC_HTTP_REQUEST_ESP32_ETHERNET_VERSION_MIN) |
|  |  |
|  | if (ASYNC_HTTP_REQUEST_ESP32_ETHERNET_VERSION_INT &lt; ASYNC_HTTP_REQUEST_ESP32_ETHERNET_VERSION_MIN) |
|  | { |
|  | Serial.print("Warning. Must use this example on Version equal or later than : "); |
|  | Serial.println(ASYNC_HTTP_REQUEST_ESP32_ETHERNET_VERSION_MIN_TARGET); |
|  | } |
|  |  |
|  | #endif |
|  |  |
|  | AHTTP_LOGWARN(F("Default SPI pinout:")); |
|  | AHTTP_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST); |
|  | AHTTP_LOGWARN1(F("MOSI:"), MOSI_GPIO); |
|  | AHTTP_LOGWARN1(F("MISO:"), MISO_GPIO); |
|  | AHTTP_LOGWARN1(F("SCK:"), SCK_GPIO); |
|  | AHTTP_LOGWARN1(F("CS:"), CS_GPIO); |
|  | AHTTP_LOGWARN1(F("INT:"), INT_GPIO); |
|  | AHTTP_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ); |
|  | AHTTP_LOGWARN(F("=========================")); |
|  |  |
|  | /////////////////////////////////// |
|  |  |
|  | // To be called before ETH.begin() |
|  | ESP32_W5500_onEvent(); |
|  |  |
|  | // start the ethernet connection and the server: |
|  | // Use DHCP dynamic IP and random mac |
|  | uint16_t index = millis() % NUMBER_OF_MAC; |
|  |  |
|  | //bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ, |
|  | // int SPI_HOST, uint8_t *W5500_Mac = W5500_Default_Mac); |
|  | //ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST ); |
|  | ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[index] ); |
|  |  |
|  | // Static IP, leave without this line to get IP via DHCP |
|  | //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); |
|  | //ETH.config(myIP, myGW, mySN, myDNS); |
|  |  |
|  | ESP32_W5500_waitForConnect(); |
|  |  |
|  | /////////////////////////////////// |
|  |  |
|  | Serial.print(F("\nHTTP WebClient is @ IP : ")); |
|  | Serial.println(ETH.localIP()); |
|  |  |
|  | request.setDebug(false); |
|  |  |
|  | request.onReadyStateChange(requestCB); |
|  | ticker.attach(HTTP_REQUEST_INTERVAL, sendRequest); |
|  |  |
|  | ticker1.attach(HEARTBEAT_INTERVAL, heartBeatPrint); |
|  |  |
|  | // Send first request now |
|  | sendRequest(); |
|  | } |
|  |  |
|  | void loop() |
|  | { |
|  | } |

---

`FULL_DUPLEX, 100Mbps`

[![](https://github.com/khoih-prog/AsyncHTTPRequest_ESP32_Ethernet/raw/main/Images/W6100.png)](https://github.com/khoih-prog/AsyncHTTPRequest_ESP32_Ethernet/raw/main/Images/W6100.png)

---

##### W5500

`FULL_DUPLEX, 100Mbps`

[![](https://github.com/khoih-prog/AsyncHTTPRequest_ESP32_Ethernet/raw/main/Images/W5500.png)](https://github.com/khoih-prog/AsyncHTTPRequest_ESP32_Ethernet/raw/main/Images/W5500.png)

---

Source: https://maker.wiznet.io/eric_g/projects/khoih-prog-asynchttprequest-esp32-ethernet/
