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 <ArduinoJson.h>
#include "CpuLoad.h"
#include <DNSServer.h>
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", "<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);
@ -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();

Loading…
Cancel
Save