- Why do we need this AsyncDNSServer_WT32_ETH01 library
- Changelog
- Prerequisites
- Installation
- Libraries' Patches
- HOWTO Fix
Multiple Definitions
Linker Error - HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)
- HOWTO Setting up the Async DNS Server
- Examples
- Example AsyncDNSServer_WT32_ETH01
- Debug
- Troubleshooting
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License
- Copyright
Why do we need this AsyncDNSServer_WT32_ETH01 library
This AsyncDNSServer_WT32_ETH01 library is a fully asynchronous DNSServer library, designed for a trouble-free, multi-connection network environment, for WT32_ETH01 or ESP32-based boards using LwIP LAN8720 Ethernet.
This library is based on, modified from:
to apply the better and faster asynchronous feature of the powerful AsyncDNSServer_WT32_ETH01 Library into WT32_ETH01 or ESP32-based boards using LwIP LAN8720 Ethernet.
- Using asynchronous network means that you can handle more than one connection at the same time
- You are called once the packet is ready
- 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.
- You are not required to check in a tight loop() the arrival of the DNS requesting packets to process them.
- Speed is OMG
- WT32_ETH01 or ESP32-based boards using LwIP LAN8720 Ethernet
Arduino IDE 1.8.19+
for ArduinoESP32 Core 2.0.5+
for ESP32-based boards.WebServer_WT32_ETH01 library 1.5.1+
. To install, checkAsyncUDP_WT32_ETH01 library 2.1.0+
. To install, check
The suggested way to install is to:
The best way is to use Arduino Library Manager
. Search for AsyncDNSServer_WT32_ETH01
, then select / install the latest version. You can also use this link for more detailed instructions.
- Navigate to AsyncDNSServer_WT32_ETH01 page.
- Download the latest release
AsyncDNSServer_WT32_ETH01-main.zip
. - Extract the zip file to
AsyncDNSServer_WT32_ETH01-main
directory - Copy the whole
AsyncDNSServer_WT32_ETH01-main
folder to Arduino libraries' directory such as~/Arduino/libraries/
.
- Install VS Code
- Install PlatformIO
- Install AsyncDNSServer_WT32_ETH01 library by using Library Manager. Search for AsyncDNSServer_WT32_ETH01 in Platform.io Author's Libraries
- 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
To fix ESP32 compile error
, just copy the following file into the ESP32
cores/esp32 directory (e.g. ./arduino-1.8.19/hardware/espressif/cores/esp32) to overwrite the old file:
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 "AsyncDNSServer_WT32_ETH01.hpp" //https://github.com/khoih-prog/AsyncDNSServer_WT32_ETH01
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 "AsyncDNSServer_WT32_ETH01.h" //https://github.com/khoih-prog/AsyncDNSServer_WT32_ETH01
Check the new multiFileProject example for a HOWTO
demo.
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.
ADC1
controls ADC function for pins GPIO32-GPIO39ADC2
controls ADC function for pins GPIO0, 2, 4, 12-15, 25-27
Look in file adc_common.c
In
ADC2
, there're two locks used for different cases:
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.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.
- In order to use
ADC2
for other functions, we have to acquire complicated firmware locks and very difficult to do - So, it's not advisable to use
ADC2
with WiFi/BlueTooth (BT/BLE). - Use
ADC1
, and pins GPIO32-GPIO39 - 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 to work with ESP32 WiFi/BlueTooth (BT/BLE)
#include <AsyncDNSServer_WT32_ETH01.h>
#include <ESPAsyncWebServer.h>
const byte DNS_PORT = 53;
IPAddress apIP;
AsyncDNSServer dnsServer;
AsyncWebServer server(80);
void setup()
{
...
///////////////////////////////////
/// To be called before ETH.begin()
WT32_ETH01_onEvent();
//bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO,
// eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE);
//ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_TYPE, ETH_CLK_MODE);
ETH.begin(ETH_PHY_ADDR, ETH_PHY_POWER);
WT32_ETH01_waitForConnect();
apIP = ETH.localIP();
///////////////////////////////////
// modify TTL associated with the domain name (in seconds)
// default is 60 seconds
dnsServer.setTTL(300);
// set which return code will be used for all other domains (e.g. sending
// ServerFailure instead of NonExistentDomain will reduce number of queries
// sent by clients)
// default is AsyncDNSReplyCode::NonExistentDomain
dnsServer.setErrorReplyCode(AsyncDNSReplyCode::ServerFailure);
// start DNS server for a specific domain name
dnsServer.start(DNS_PORT, "*", apIP);
...
}
void loop()
{
}
- AsyncCaptivePortalAdvanced_WT32_ETH01
- AsyncCaptivePortal_WT32_ETH01
- AsyncDNServerFull_WT32_ETH01
- AsyncDNSServer_WT32_ETH01
- multiFileProject
Example AsyncDNSServer_WT32_ETH01
1. File AsyncDNSServer_WT32_ETH01.ino
Debug is enabled by default on Serial. To disable, use level 0
#define ASYNC_DNS_WT32_ETH01_DEBUG_PORT Serial
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_DNS_WT32_ETH01_LOGLEVEL_ 0
You can also change the debugging level from 0 to 4
#define ASYNC_DNS_WT32_ETH01_DEBUG_PORT Serial
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_DNS_WT32_ETH01_LOGLEVEL_ 4
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.
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.
Submit issues to: AsyncDNSServer_WT32_ETH01 issues
- Fix bug. Add enhancement
- Add support to WT32_ETH01 or ESP32-based boards using LwIP LAN8720 Ethernet
- Add more examples.
- Add debugging features
- Add astyle using
allman
style. Restyle the library
- Based on and modified from Develo's ESPAsyncDNSServer Library.
⭐️ Develo |
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
- The library is licensed under GPLv3
- Copyright (c) 2016- Develo
- Copyright (c) 2022- Khoi Hoang