Browse Source

added dns lib, that accept access from url http://lab1.tstu/ , new ap ip by default - 192.168.1.1

master
Никита 7 years ago
parent
commit
6dd614a179
  1. 19
      src/main.cpp

19
src/main.cpp

@ -9,10 +9,12 @@
#include <WebSocketsServer.h> #include <WebSocketsServer.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include "CpuLoad.h" #include "CpuLoad.h"
#include <DNSServer.h>
const char *ssid = "LabWork_1"; const char *ssid = "LabWork_1";
ESP8266WebServer server(80); ESP8266WebServer server(80);
DNSServer dnsServer;
Sensor accelerometer = Sensor(); Sensor accelerometer = Sensor();
Graph graphAcc = Graph(200, 50); 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) void setup(void)
{ {
IPAddress apIP(192, 168, 1, 1);
Serial.begin(115200); Serial.begin(115200);
Serial.setDebugOutput(true); Serial.setDebugOutput(true);
Serial.println(); Serial.println();
pinMode(A0, INPUT); WiFi.setAutoConnect(false);
WiFi.setAutoConnect(false); WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(ssid); WiFi.softAP(ssid);
IPAddress myIP = WiFi.softAPIP(); IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: "); Serial.print("AP IP address: ");
Serial.println(myIP); 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("/accelerometer", handleAccelerometer);
server.on("/", []() { server.on("/", []() {
server.send(200, "text/html", "<a href=\"http://192.168.4.1/accelerometer\">Main Page</a>"); server.send(200, "text/html", "<a style=\"font-size:10em;2\"href=\"http://lab1.tstu/accelerometer\">Main Page</a>");
}); });
server.onNotFound(handleNotFound); server.onNotFound(handleNotFound);
@ -151,12 +160,16 @@ void setup(void)
webSocket.begin(); webSocket.begin();
webSocket.onEvent(webSocketEvent); webSocket.onEvent(webSocketEvent);
pinMode(A0, INPUT);
} }
void loop(void) void loop(void)
{ {
updateCpuTime(0); updateCpuTime(0);
dnsServer.processNextRequest();
server.handleClient(); server.handleClient();
webSocket.loop(); webSocket.loop();
updateAccelerometer(); updateAccelerometer();

Loading…
Cancel
Save