- Why do we need this AsyncDNSServer_Teensy41 library
- Changelog
- Prerequisites
- Installation
- Packages' Patches
- HOWTO Fix
Multiple Definitions
Linker Error - HOWTO Setting up the Async DNS Server
- Examples
- Example AsyncDNSServer
- Debug
- Troubleshooting
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License
- Copyright
Why do we need this AsyncDNSServer_Teensy41 library
This AsyncDNSServer_Teensy41 library is a fully asynchronous DNSServer library, designed for a trouble-free, multi-connection network environment, for Teensy 4.1 using QNEthernet Library.
This library is based on, modified from:
to apply the better and faster asynchronous feature into Teensy 4.1 using QNEthernet Library.
- 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
- Teensy 4.1 using QNEthernet Library
Arduino IDE 1.8.19+
for Arduino.Teensy core v1.57+
QNEthernet Library version v0.16.0+
for Teensy 4.1 built-in Ethernet.AsyncUDP_Teensy41 library v1.2.1+
. To install. check .
The suggested way to install is to:
The best way is to use Arduino Library Manager
. Search for AsyncDNSServer_Teensy41
, then select / install the latest version. You can also use this link for more detailed instructions.
- Navigate to AsyncDNSServer_Teensy41 page.
- Download the latest release
AsyncDNSServer_Teensy41-main.zip
. - Extract the zip file to
AsyncDNSServer_Teensy41-main
directory - Copy the whole
AsyncDNSServer_Teensy41-main
folder to Arduino libraries' directory such as~/Arduino/libraries/
.
- Install VS Code
- Install PlatformIO
- Install AsyncDNSServer_Teensy41 library by using Library Manager. Search for AsyncDNSServer_Teensy41 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 be able to compile and run on Teensy boards, you have to copy the files in Packages_Patches for Teensy directory into Teensy hardware directory (./arduino-1.8.19/hardware/teensy/avr/boards.txt).
Supposing the Arduino version is 1.8.19. These files must be copied into the directory:
./arduino-1.8.19/hardware/teensy/avr/boards.txt
./arduino-1.8.19/hardware/teensy/avr/cores/teensy/Stream.h
./arduino-1.8.19/hardware/teensy/avr/cores/teensy3/Stream.h
./arduino-1.8.19/hardware/teensy/avr/cores/teensy4/Stream.h
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz These files must be copied into the directory:
./arduino-x.yy.zz/hardware/teensy/avr/boards.txt
./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy/Stream.h
./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy3/Stream.h
./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy4/Stream.h
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_Teensy41.hpp" //https://github.com/khoih-prog/AsyncDNSServer_Teensy41
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_Teensy41.h" //https://github.com/khoih-prog/AsyncDNSServer_Teensy41
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
#include "QNEthernet.h" // https://github.com/ssilverman/QNEthernet
using namespace qindesign::network;
#include <AsyncDNSServer_Teensy41.h>
const byte DNS_PORT = 53;
IPAddress apIP;
AsyncDNSServer dnsServer;
void setup()
{
...
// 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, "*", Ethernet.localIP());
...
}
void loop()
{
}
Example AsyncDNSServer
1. File AsyncDNSServer.ino
AsyncDNSServer_Teensy41/examples/AsyncDNSServer/AsyncDNSServer.ino
Lines 12 to 120 in 4a46019
2. File defines.h
AsyncDNSServer_Teensy41/examples/AsyncDNSServer/defines.h
Lines 12 to 45 in 4a46019
Debug is enabled by default on Serial. To disable, use level 0
#define ASYNC_DNS_TEENSY41_DEBUG_PORT Serial
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_DNS_TEENSY41_LOGLEVEL_ 0
You can also change the debugging level from 0 to 4
#define ASYNC_DNS_TEENSY41_DEBUG_PORT Serial
// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_DNS_TEENSY41_LOGLEVEL_ 4
If you get compilation errors, more often than not, you may need to install a newer version of Arduino IDE, the Arduino STM32
core or depending libraries.
Sometimes, the library will only work if you update the STM32
core to the latest version because I am always using the latest cores /libraries.
Submit issues to: AsyncDNSServer_Teensy41 issues
- Fix bug. Add enhancement
- Initial porting and coding for Teensy 4.1 using built-in QNEthernet
- 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