mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Added simple HTTP server to DNSServer example
This commit is contained in:
parent
28a5a4c97e
commit
bcdb580d7a
@ -1,9 +1,11 @@
|
|||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
|
#include <ESP8266WebServer.h>
|
||||||
|
|
||||||
const byte DNS_PORT = 53;
|
const byte DNS_PORT = 53;
|
||||||
IPAddress apIP(192, 168, 1, 1);
|
IPAddress apIP(192, 168, 1, 1);
|
||||||
DNSServer dnsServer;
|
DNSServer dnsServer;
|
||||||
|
ESP8266WebServer webServer(80);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
@ -21,8 +23,19 @@ void setup() {
|
|||||||
|
|
||||||
//start DNS server for a specific domain name
|
//start DNS server for a specific domain name
|
||||||
dnsServer.start(DNS_PORT, "www.example.com", apIP);
|
dnsServer.start(DNS_PORT, "www.example.com", apIP);
|
||||||
|
|
||||||
|
//simple HTTP server to see that DNS server is working
|
||||||
|
webServer.onNotFound([]() {
|
||||||
|
String message = "Hello World!\n\n";
|
||||||
|
message += "URI: ";
|
||||||
|
message += webServer.uri();
|
||||||
|
|
||||||
|
webServer.send(200, "text/plain", message);
|
||||||
|
});
|
||||||
|
webServer.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
dnsServer.processNextRequest();
|
dnsServer.processNextRequest();
|
||||||
|
webServer.handleClient();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user