Code Monkey home page Code Monkey logo

khoih-prog / asyncdnsserver_rp2040w Goto Github PK

View Code? Open in Web Editor NEW
5.0 4.0 0.0 215 KB

Fully Asynchronous DNS Server Library for RASPBERRY_PI_PICO_W using CYW43439 WiFi with arduino-pico core. This library is one of the current or future and more advanced Async libraries, such as AsyncWebServer_RP2040W, AsyncHTTPRequest_RP2040W, AsyncHTTPSRequest_RP2040W

License: GNU General Public License v3.0

C 85.59% C++ 13.16% Shell 1.25%
async communication cyw43439 data dns dns-server lwip raspberry-pi-pico-w rp2040 rp2040w

asyncdnsserver_rp2040w's Introduction

AsyncDNSServer_RP2040W Library

arduino-library-badge GitHub release contributions welcome GitHub issues

Donate to my libraries using BuyMeACoffee



Table of Contents



Why do we need this AsyncDNSServer_RP2040W library

Features

This AsyncDNSServer_RP2040W library is a fully asynchronous DNSServer library, designed for a trouble-free, multi-connection network environment, for RASPBERRY_PI_PICO_W using CYW43439 WiFi.

This library is based on, modified from:

  1. Develo's ESPAsyncDNSServer
  2. AsyncDNSServer_STM32

to apply the better and faster asynchronous feature into RASPBERRY_PI_PICO_W using CYW43439 WiFi.

Why Async is better

  • 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

Currently Supported Boards

  1. RASPBERRY_PI_PICO_W with CYW43439 WiFi using arduino-pico core



Prerequisites

  1. Arduino IDE 1.8.19+ for Arduino. GitHub release
  2. Earle Philhower's arduino-pico core v2.6.3+ for RASPBERRY_PI_PICO_W with CYW43439 WiFi, etc. GitHub release
  3. AsyncUDP_RP2040W library v1.0.0+ for RASPBERRY_PI_PICO_W with CYW43439 WiFi. To install. check arduino-library-badge

Installation

The suggested way to install is to:

Use Arduino Library Manager

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

Manual Install

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

VS Code & PlatformIO:

  1. Install VS Code
  2. Install PlatformIO
  3. Install AsyncDNSServer_RP2040W library by using Library Manager. Search for AsyncDNSServer_RP2040W 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


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 "AsyncDNSServer_RP2040W.hpp"         //https://github.com/khoih-prog/AsyncDNSServer_RP2040W

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_RP2040W.h"           //https://github.com/khoih-prog/AsyncDNSServer_RP2040W

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



HOWTO Setting up the Async DNS Server

#include <AsyncDNSServer_RP2040W.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() 
{
}


Examples

  1. AsyncCaptivePortal
  2. AsyncCaptivePortalAdvanced
  3. AsyncDNServerFull
  4. AsyncDNSServer
  5. multiFileProject

#include "defines.h"
#include <AsyncDNSServer_RP2040W.h>
#include <AsyncWebServer_RP2040W.h>
const byte DNS_PORT = 53;
IPAddress apIP;
AsyncDNSServer dnsServer;
AsyncWebServer server(80);
int status = WL_IDLE_STATUS;
void handleNotFound(AsyncWebServerRequest *request)
{
String message = "Hello World from " + String(BOARD_NAME) + " using CYW43439 WiFi\n\n";
message += "URI: ";
message += request->url();
request->send(200, "text/plain", message);
}
void printWifiStatus()
{
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("Local IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
void setup()
{
Serial.begin(115200);
while (!Serial && millis() < 5000);
Serial.print("\nStart AsyncDNSServer on "); Serial.println(BOARD_NAME);
Serial.println(ASYNC_DNS_SERVER_RP2040W_VERSION);
#if defined(ASYNC_DNS_SERVER_RP2040W_VERSION_MIN)
if (ASYNC_DNS_SERVER_RP2040W_VERSION_INT < ASYNC_DNS_SERVER_RP2040W_VERSION_MIN)
{
Serial.print("Warning. Must use this example on Version equal or later than : ");
Serial.println(ASYNC_DNS_SERVER_RP2040W_VERSION_MIN_TARGET);
}
#endif
///////////////////////////////////
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE)
{
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
Serial.print(F("Connecting to SSID: "));
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(1000);
// attempt to connect to WiFi network
while ( status != WL_CONNECTED)
{
delay(500);
// Connect to WPA/WPA2 network
status = WiFi.status();
}
printWifiStatus();
///////////////////////////////////
// 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);
server.onNotFound(handleNotFound);
server.begin();
Serial.print(F("HTTP EthernetWebServer is @ IP : "));
Serial.println(apIP);
}
void loop()
{
}

2. File defines.h

/****************************************************************************************************************************
defines.h
AsyncDNSServer_RP2040W is an Async DNS_Server library for the RP2040W with CYW43439 WiFi
Based on and modified from ESPAsyncDNSServer Library (https://github.com/devyte/ESPAsyncDNSServer)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncDNSServer_RP2040W
*****************************************************************************************************************************/
#ifndef defines_h
#define defines_h
#if !( defined(ARDUINO_RASPBERRY_PI_PICO_W) )
#error For RASPBERRY_PI_PICO_W only
#endif
#define ASYNC_DNS_RP2040W_DEBUG_PORT Serial
// Debug Level from 0 to 4
#define _ASYNC_DNS_RP2040W_LOGLEVEL_ 4
#if (_ASYNC_DNS_RP2040W_LOGLEVEL_ > 3)
#warning Using RASPBERRY_PI_PICO_W with CYW43439 WiFi
#endif
char ssid[] = "your_ssid"; // your network SSID (name)
char pass[] = "12345678"; // your network password (use for WPA, or use as key for WEP), length must be 8+
#endif //defines_h



Debug

Debug is enabled by default on Serial. To disable, use level 0

#define ASYNC_DNS_RP2040W_DEBUG_PORT      Serial

// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_DNS_RP2040W_LOGLEVEL_      0

You can also change the debugging level from 0 to 4

#define ASYNC_DNS_RP2040W_DEBUG_PORT      Serial


// Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _ASYNC_DNS_RP2040W_LOGLEVEL_    	4

Troubleshooting

If you get compilation errors, more often than not, you may need to install a newer version of the arduino-pico core

Sometimes, the library will only work if you update the arduino-pico core core to the latest version because I am using newly added functions.



Issues

Submit issues to: AsyncDNSServer_RP2040W issues


TO DO

  1. Fix bug. Add enhancement

DONE

  1. Add support to RASPBERRY_PI_PICO_W using CYW43439 WiFi
  2. Add more examples.
  3. Add debugging features
  4. Add astyle using allman style. Restyle the library


Contributions and Thanks

  1. Based on and modified from Develo's ESPAsyncDNSServer Library.
devyte
⭐️ Develo


Contributing

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

License

  • The library is licensed under GPLv3

Copyright

  • Copyright (c) 2016- Develo
  • Copyright (c) 2022- Khoi Hoang

asyncdnsserver_rp2040w's People

Contributors

dependabot[bot] avatar khoih-prog avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.