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();