From 6dd614a1798c55abd7827cea7c7e382882603200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Tue, 27 Feb 2018 23:01:00 +0300 Subject: [PATCH] added dns lib, that accept access from url http://lab1.tstu/ , new ap ip by default - 192.168.1.1 --- src/main.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e4aa1c8..8a8a5cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,10 +9,12 @@ #include #include #include "CpuLoad.h" +#include const char *ssid = "LabWork_1"; ESP8266WebServer server(80); +DNSServer dnsServer; Sensor accelerometer = Sensor(); Graph graphAcc = Graph(200, 50); @@ -129,20 +131,27 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length void setup(void) { + IPAddress apIP(192, 168, 1, 1); Serial.begin(115200); Serial.setDebugOutput(true); Serial.println(); - pinMode(A0, INPUT); - WiFi.setAutoConnect(false); + WiFi.setAutoConnect(false); + WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); WiFi.softAP(ssid); IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP); + // DNS SERVER SETUP + dnsServer.setTTL(300); + dnsServer.setErrorReplyCode(DNSReplyCode::ServerFailure); + dnsServer.start(53, "lab1.tstu", myIP); + // END DNS SERVER SETUP + server.on("/accelerometer", handleAccelerometer); server.on("/", []() { - server.send(200, "text/html", "Main Page"); + server.send(200, "text/html", "Main Page"); }); server.onNotFound(handleNotFound); @@ -151,12 +160,16 @@ void setup(void) webSocket.begin(); webSocket.onEvent(webSocketEvent); + + pinMode(A0, INPUT); } void loop(void) { updateCpuTime(0); + dnsServer.processNextRequest(); + server.handleClient(); webSocket.loop(); updateAccelerometer();