This repository was archived by the owner on Jan 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAsyncDNServerFull_STM32_LAN8720.ino
More file actions
83 lines (60 loc) · 2.41 KB
/
Copy pathAsyncDNServerFull_STM32_LAN8720.ino
File metadata and controls
83 lines (60 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/****************************************************************************************************************************
AsyncDNSServerFull_LAN8720.ino
For STM32 with LAN8720 (STM32F4/F7)or built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)
AsyncDNSServer_STM32 is a Async DNS Server library for the STM32 using built-in LAN8742A Ethernet
Based on and modified from ESPAsyncDNSServer Library (https://github.com/devyte/ESPAsyncDNSServer)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncDNSServer_STM32
Licensed under MIT license
*****************************************************************************************************************************/
#include "defines.h"
#include <AsyncDNSServer_STM32.h>
#include <AsyncWebServer_STM32.h>
const byte DNS_PORT = 53;
IPAddress apIP;
AsyncDNSServer dnsServer;
AsyncWebServer server(80);
void handleNotFound(AsyncWebServerRequest *request)
{
String message = "Hello World from " + String(BOARD_NAME) + "using LAN8720\n\n";
message += "URI: ";
message += request->url();
request->send(200, "text/plain", message);
}
void setup()
{
Serial.begin(115200);
delay(2000);
Serial.print("\nStart AsyncDNSServerFull_STM32_LAN8720 on ");
Serial.println(BOARD_NAME);
Serial.println(ASYNC_DNS_SERVER_STM32_VERSION);
// start the ethernet connection and the server
// Use random mac
uint16_t index = millis() % NUMBER_OF_MAC;
// Use Static IP
//Ethernet.begin(mac[index], ip);
// Use DHCP dynamic IP and random mac
Ethernet.begin(mac[index]);;
apIP = Ethernet.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);
// simple HTTP server to see that DNS server is working
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request)
{
request->send(200, "text/plain", "Hello from LAN8720 DNSServer running on " + String(BOARD_NAME));
});
server.onNotFound(handleNotFound);
server.begin();
Serial.print(F("HTTP DNSServer is @ IP : "));
Serial.println(apIP);
}
void loop()
{
}