Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 930b912

Browse files
authored
v1.0.0 for ESP32 + LwIP W5500
### Initial Releases v1.0.0 1. Initial coding to support **ESP32 boards using LwIP W5500 Ethernet**
1 parent 0ef0082 commit 930b912

File tree

1 file changed

+374
-0
lines changed

1 file changed

+374
-0
lines changed

README.md

Lines changed: 374 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,374 @@
1+
# AsyncDNSServer_ESP32_W5500 Library
2+
3+
4+
[![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncDNSServer_ESP32_W5500.svg?)](https://www.ardu-badge.com/AsyncDNSServer_ESP32_W5500)
5+
[![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncDNSServer_ESP32_W5500.svg)](https://github.com/khoih-prog/AsyncDNSServer_ESP32_W5500/releases)
6+
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
7+
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncDNSServer_ESP32_W5500.svg)](http://github.com/khoih-prog/AsyncDNSServer_ESP32_W5500/issues)
8+
9+
10+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
11+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
12+
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
13+
<a href="https://profile-counter.glitch.me/khoih-prog-AsyncDNSServer_ESP32_W5500/count.svg" title="AsyncDNSServer_ESP32_W5500 Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-AsyncDNSServer_ESP32_W5500/count.svg" style="height: 30px;width: 200px;"></a>
14+
15+
16+
---
17+
---
18+
19+
## Table of Contents
20+
21+
22+
* [Why do we need this AsyncDNSServer_ESP32_W5500 library](#why-do-we-need-this-AsyncDNSServer_ESP32_W5500-library)
23+
* [Features](#features)
24+
* [Why Async is better](#why-async-is-better)
25+
* [Currently supported Boards](#currently-supported-boards)
26+
* [Changelog](changelog.md)
27+
* [Prerequisites](#prerequisites)
28+
* [Installation](#installation)
29+
* [Use Arduino Library Manager](#use-arduino-library-manager)
30+
* [Manual Install](#manual-install)
31+
* [VS Code & PlatformIO](#vs-code--platformio)
32+
* [Libraries' Patches](#libraries-patches)
33+
* [1. For fixing ESP32 compile error](#1-for-fixing-esp32-compile-error)
34+
* [HOWTO Fix `Multiple Definitions` Linker Error](#howto-fix-multiple-definitions-linker-error)
35+
* [HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)](#howto-use-analogread-with-esp32-running-wifi-andor-bluetooth-btble)
36+
* [1. ESP32 has 2 ADCs, named ADC1 and ADC2](#1--esp32-has-2-adcs-named-adc1-and-adc2)
37+
* [2. ESP32 ADCs functions](#2-esp32-adcs-functions)
38+
* [3. ESP32 WiFi uses ADC2 for WiFi functions](#3-esp32-wifi-uses-adc2-for-wifi-functions)
39+
* [HOWTO Setting up the Async DNS Server](#howto-setting-up-the-async-dns-server)
40+
* [Examples](#examples)
41+
* [ 1. AsyncCaptivePortalAdvanced_ESP32_W5500](examples/AsyncCaptivePortalAdvanced_ESP32_W5500)
42+
* [ 2. AsyncCaptivePortal_ESP32_W5500](examples/AsyncCaptivePortal_ESP32_W5500)
43+
* [ 3. AsyncDNServerFull_ESP32_W5500](examples/AsyncDNServerFull_ESP32_W5500)
44+
* [ 4. AsyncDNSServer_ESP32_W5500](examples/AsyncDNSServer_ESP32_W5500)
45+
* [Example AsyncDNSServer_ESP32_W5500](#example-AsyncDNSServer_ESP32_W5500)
46+
* [1. File AsyncDNSServer_ESP32_W5500.ino](#1-file-AsyncDNSServer_ESP32_W5500ino)
47+
* [Debug](#debug)
48+
* [Troubleshooting](#troubleshooting)
49+
* [Issues](#issues)
50+
* [TO DO](#to-do)
51+
* [DONE](#done)
52+
* [Contributions and Thanks](#contributions-and-thanks)
53+
* [Contributing](#contributing)
54+
* [License](#license)
55+
* [Copyright](#copyright)
56+
57+
---
58+
---
59+
60+
### Why do we need this [AsyncDNSServer_ESP32_W5500 library](https://github.com/khoih-prog/AsyncDNSServer_ESP32_W5500)
61+
62+
#### Features
63+
64+
This [AsyncDNSServer_ESP32_W5500 library](https://github.com/khoih-prog/AsyncDNSServer_ESP32_W5500) is a fully `asynchronous DNSServer` library, designed for a trouble-free, multi-connection network environment, for **ESP32 boards using LwIP W5500 Ethernet**.
65+
66+
This library is based on, modified from:
67+
68+
1. [Develo's ESPAsyncDNSServer](https://github.com/devyte/ESPAsyncDNSServer)
69+
70+
to apply the better and faster **asynchronous** feature of the **powerful** [AsyncDNSServer_ESP32_W5500 Library](https://github.com/khoih-prog/AsyncDNSServer_ESP32_W5500) into **ESP32 boards using LwIP W5500 Ethernet**.
71+
72+
73+
#### Why Async is better
74+
75+
- Using asynchronous network means that you can handle **more than one connection at the same time**
76+
- You are called once the packet is ready
77+
- After a DNS Client connected to this Async DNS server, you are **immediately ready** to handle other connections while the Server is taking care of receiving and responding to the UDP packets in the background.
78+
- You are not required to check in a tight loop() the arrival of the DNS requesting packets to process them.
79+
- **Speed is OMG**
80+
81+
82+
#### Currently supported Boards
83+
84+
1. **ESP32_W5500 boards** using ESP32 boards with `LwIP` W5500 Ethernet
85+
86+
---
87+
---
88+
89+
## Prerequisites
90+
91+
1. [`Arduino IDE 1.8.19+` for Arduino](https://www.arduino.cc/en/Main/Software)
92+
2. [`ESP32 Core 2.0.5+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. [![Latest release](https://img.shields.io/github/release/espressif/arduino-esp32.svg)](https://github.com/espressif/arduino-esp32/releases/latest/)
93+
3. [`WebServer_ESP32_W5500 library 1.5.1+`](https://github.com/khoih-prog/WebServer_ESP32_W5500). To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/WebServer_ESP32_W5500.svg?)](https://www.ardu-badge.com/WebServer_ESP32_W5500)
94+
4. [`AsyncUdp_ESP32_W5500 library 2.0.0+`](https://github.com/khoih-prog/AsyncUdp_ESP32_W5500). To install, check [![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncUdp_ESP32_W5500.svg?)](https://www.ardu-badge.com/AsyncUdp_ESP32_W5500)
95+
96+
---
97+
---
98+
99+
### Installation
100+
101+
The suggested way to install is to:
102+
103+
#### Use Arduino Library Manager
104+
105+
The best way is to use `Arduino Library Manager`. Search for `AsyncDNSServer_ESP32_W5500`, then select / install the latest version. You can also use this link [![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncDNSServer_ESP32_W5500.svg?)](https://www.ardu-badge.com/AsyncDNSServer_ESP32_W5500) for more detailed instructions.
106+
107+
### Manual Install
108+
109+
1. Navigate to [AsyncDNSServer_ESP32_W5500](https://github.com/khoih-prog/AsyncDNSServer_ESP32_W5500) page.
110+
2. Download the latest release `AsyncDNSServer_ESP32_W5500-main.zip`.
111+
3. Extract the zip file to `AsyncDNSServer_ESP32_W5500-main` directory
112+
4. Copy the whole `AsyncDNSServer_ESP32_W5500-main` folder to Arduino libraries' directory such as `~/Arduino/libraries/`.
113+
114+
### VS Code & PlatformIO:
115+
116+
1. Install [VS Code](https://code.visualstudio.com/)
117+
2. Install [PlatformIO](https://platformio.org/platformio-ide)
118+
3. Install [**AsyncDNSServer_ESP32_W5500** library](https://registry.platformio.org/libraries/AsyncDNSServer_ESP32_W5500) by using [Library Manager](https://registry.platformio.org/libraries/AsyncDNSServer_ESP32_W5500/installation). Search for AsyncDNSServer_ESP32_W5500 in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22)
119+
4. Use included [platformio.ini](platformio/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](https://docs.platformio.org/page/projectconf.html)
120+
121+
---
122+
---
123+
124+
### Libraries' Patches
125+
126+
#### 1. For fixing ESP32 compile error
127+
128+
To fix [`ESP32 compile error`](https://github.com/espressif/arduino-esp32), just copy the following file into the [`ESP32`](https://github.com/espressif/arduino-esp32) cores/esp32 directory (e.g. ./arduino-1.8.19/hardware/espressif/cores/esp32) to overwrite the old file:
129+
- [Server.h](LibraryPatches/esp32/cores/esp32/Server.h)
130+
131+
---
132+
---
133+
134+
### HOWTO Fix `Multiple Definitions` Linker Error
135+
136+
The current library implementation, using `xyz-Impl.h` instead of standard `xyz.cpp`, possibly creates certain `Multiple Definitions` Linker error in certain use cases.
137+
138+
You can include this `.hpp` file
139+
140+
```cpp
141+
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
142+
#include "AsyncDNSServer_ESP32_W5500.hpp" //https://github.com/khoih-prog/AsyncDNSServer_ESP32_W5500
143+
```
144+
145+
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
146+
147+
```cpp
148+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
149+
#include "AsyncDNSServer_ESP32_W5500.h" //https://github.com/khoih-prog/AsyncDNSServer_ESP32_W5500
150+
```
151+
152+
Check the new [**multiFileProject** example](examples/multiFileProject) for a `HOWTO` demo.
153+
154+
---
155+
---
156+
157+
### HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)
158+
159+
Please have a look at [**ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example**](https://github.com/khoih-prog/ESP_WiFiManager/issues/39) to have more detailed description and solution of the issue.
160+
161+
#### 1. ESP32 has 2 ADCs, named ADC1 and ADC2
162+
163+
#### 2. ESP32 ADCs functions
164+
165+
- `ADC1` controls ADC function for pins **GPIO32-GPIO39**
166+
- `ADC2` controls ADC function for pins **GPIO0, 2, 4, 12-15, 25-27**
167+
168+
#### 3.. ESP32 WiFi uses ADC2 for WiFi functions
169+
170+
Look in file [**adc_common.c**](https://github.com/espressif/esp-idf/blob/master/components/driver/adc_common.c#L61)
171+
172+
> In `ADC2`, there're two locks used for different cases:
173+
> 1. lock shared with app and Wi-Fi:
174+
> ESP32:
175+
> When Wi-Fi using the `ADC2`, we assume it will never stop, so app checks the lock and returns immediately if failed.
176+
> ESP32S2:
177+
> The controller's control over the ADC is determined by the arbiter. There is no need to control by lock.
178+
>
179+
> 2. lock shared between tasks:
180+
> when several tasks sharing the `ADC2`, we want to guarantee
181+
> all the requests will be handled.
182+
> Since conversions are short (about 31us), app returns the lock very soon,
183+
> we use a spinlock to stand there waiting to do conversions one by one.
184+
>
185+
> adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock.
186+
187+
188+
- In order to use `ADC2` for other functions, we have to **acquire complicated firmware locks and very difficult to do**
189+
- So, it's not advisable to use `ADC2` with WiFi/BlueTooth (BT/BLE).
190+
- Use `ADC1`, and pins **GPIO32-GPIO39**
191+
- If somehow it's a must to use those pins serviced by `ADC2` (**GPIO0, 2, 4, 12, 13, 14, 15, 25, 26 and 27**), use the **fix mentioned at the end** of [**ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example**](https://github.com/khoih-prog/ESP_WiFiManager/issues/39) to work with ESP32 WiFi/BlueTooth (BT/BLE)
192+
193+
---
194+
---
195+
196+
## HOWTO Setting up the Async DNS Server
197+
198+
```cpp
199+
#include <AsyncDNSServer_ESP32_W5500.h>
200+
#include <ESPAsyncWebServer.h>
201+
202+
const byte DNS_PORT = 53;
203+
204+
IPAddress apIP;
205+
206+
AsyncDNSServer dnsServer;
207+
208+
AsyncWebServer server(80);
209+
210+
void setup()
211+
{
212+
...
213+
214+
///////////////////////////////////
215+
216+
// To be called before ETH.begin()
217+
ESP32_W5500_onEvent();
218+
219+
// start the ethernet connection and the server:
220+
// Use DHCP dynamic IP and random mac
221+
uint16_t index = millis() % NUMBER_OF_MAC;
222+
223+
//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
224+
// int SPI_HOST, uint8_t *W5500_Mac = W5500_Default_Mac);
225+
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST );
226+
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[index] );
227+
228+
// Static IP, leave without this line to get IP via DHCP
229+
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
230+
//ETH.config(myIP, myGW, mySN, myDNS);
231+
232+
ESP32_W5500_waitForConnect();
233+
234+
///////////////////////////////////
235+
236+
apIP = ETH.localIP();
237+
238+
///////////////////////////////////
239+
240+
// modify TTL associated with the domain name (in seconds)
241+
// default is 60 seconds
242+
dnsServer.setTTL(300);
243+
// set which return code will be used for all other domains (e.g. sending
244+
// ServerFailure instead of NonExistentDomain will reduce number of queries
245+
// sent by clients)
246+
// default is AsyncDNSReplyCode::NonExistentDomain
247+
dnsServer.setErrorReplyCode(AsyncDNSReplyCode::ServerFailure);
248+
249+
// start DNS server for a specific domain name
250+
dnsServer.start(DNS_PORT, "*", apIP);
251+
252+
...
253+
}
254+
255+
void loop()
256+
{
257+
}
258+
259+
```
260+
261+
---
262+
---
263+
264+
### Examples
265+
266+
1. [AsyncCaptivePortalAdvanced_ESP32_W5500](examples/AsyncCaptivePortalAdvanced_ESP32_W5500)
267+
2. [AsyncCaptivePortal_ESP32_W5500](examples/AsyncCaptivePortal_ESP32_W5500)
268+
3. [AsyncDNServerFull_ESP32_W5500](examples/AsyncDNServerFull_ESP32_W5500)
269+
4. [AsyncDNSServer_ESP32_W5500](examples/AsyncDNSServer_ESP32_W5500)
270+
271+
---
272+
---
273+
274+
### Example [AsyncDNSServer_ESP32_W5500](examples/AsyncDNSServer_ESP32_W5500)
275+
276+
#### 1. File [AsyncDNSServer_ESP32_W5500.ino](examples/AsyncDNSServer_ESP32_W5500/AsyncDNSServer_ESP32_W5500.ino)
277+
278+
https://github.com/khoih-prog/AsyncDNSServer_ESP32_W5500/blob/0ef00823dccdc9c7616542b377c0798e37353128/examples/AsyncDNSServer_ESP32_W5500/AsyncDNSServer_ESP32_W5500.ino#L13-L170
279+
280+
---
281+
---
282+
283+
### Debug
284+
285+
Debug is enabled by default on Serial. To disable, use level 0
286+
287+
```cpp
288+
#define ASYNC_DNS_ESP32_W5500_DEBUG_PORT Serial
289+
290+
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
291+
#define _ASYNC_DNS_ESP32_W5500_LOGLEVEL_ 0
292+
```
293+
294+
You can also change the debugging level from 0 to 4
295+
296+
```cpp
297+
#define ASYNC_DNS_ESP32_W5500_DEBUG_PORT Serial
298+
299+
300+
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
301+
#define _ASYNC_DNS_ESP32_W5500_LOGLEVEL_ 4
302+
```
303+
304+
---
305+
306+
### Troubleshooting
307+
308+
If you get compilation errors, more often than not, you may need to install a newer version of Arduino IDE, the Arduino `ESP32` core or depending libraries.
309+
310+
Sometimes, the library will only work if you update the `ESP32` core to the latest version because I am always using the latest cores /libraries.
311+
312+
313+
---
314+
---
315+
316+
317+
### Issues
318+
319+
Submit issues to: [AsyncDNSServer_ESP32_W5500 issues](https://github.com/khoih-prog/AsyncDNSServer_ESP32_W5500/issues)
320+
321+
---
322+
323+
324+
## TO DO
325+
326+
1. Fix bug. Add enhancement
327+
328+
329+
## DONE
330+
331+
1. Add support to **ESP32-based boards using LwIP W5500 Ethernet**
332+
2. Add more examples.
333+
3. Add debugging features
334+
4. Add astyle using `allman` style. Restyle the library
335+
336+
---
337+
---
338+
339+
### Contributions and Thanks
340+
341+
1. Based on and modified from [Develo's ESPAsyncDNSServer Library](https://github.com/devyte/ESPAsyncDNSServer).
342+
343+
344+
<table>
345+
<tr>
346+
<td align="center"><a href="https://github.com/devyte"><img src="https://github.com/devyte.png" width="100px;" alt="devyte"/><br/><sub><b>⭐️ Develo</b></sub></a><br/></td>
347+
</tr>
348+
</table>
349+
350+
---
351+
352+
### Contributing
353+
354+
If you want to contribute to this project:
355+
- Report bugs and errors
356+
- Ask for enhancements
357+
- Create issues and pull requests
358+
- Tell other people about this library
359+
360+
---
361+
---
362+
363+
### License
364+
365+
- The library is licensed under [GPLv3](https://github.com/khoih-prog/AsyncDNSServer_ESP32_W5500/blob/main/LICENSE)
366+
367+
---
368+
369+
## Copyright
370+
371+
- Copyright (c) 2016- Develo
372+
- Copyright (c) 2022- Khoi Hoang
373+
374+

0 commit comments

Comments
 (0)