You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.8 KiB
71 lines
1.8 KiB
|
2 years ago
|
|
||
|
|
#include <ESP8266WebServer.h>
|
||
|
|
#include <WiFiClient.h>
|
||
|
|
#include <ESP8266WiFi.h>
|
||
|
|
|
||
|
|
const char* ssid = "mathematics";
|
||
|
|
const char* password = "fzbyj8r7pdEk";
|
||
|
|
|
||
|
|
ESP8266WebServer server(7000);
|
||
|
|
|
||
|
|
String page = "";
|
||
|
|
String txt = "";
|
||
|
|
String txx = "";
|
||
|
|
|
||
|
|
void setup() {
|
||
|
|
|
||
|
|
delay(1000);
|
||
|
|
Serial.begin(115200);
|
||
|
|
WiFi.begin(ssid, password);
|
||
|
|
Serial.println("");
|
||
|
|
|
||
|
|
// wait for connection
|
||
|
|
while (WiFi.status() != WL_CONNECTED) {
|
||
|
|
delay(500);
|
||
|
|
Serial.print(".");
|
||
|
|
}
|
||
|
|
Serial.print("connected to ");
|
||
|
|
Serial.println(ssid);
|
||
|
|
Serial.print("ip: ");
|
||
|
|
Serial.println(WiFi.localIP());
|
||
|
|
server.on("/txt.txt", []() {
|
||
|
|
//txx = String(txt);
|
||
|
|
server.send(200, "text/html", txt);
|
||
|
|
});
|
||
|
|
server.on("/", []() {
|
||
|
|
// page = "<h1>hi</h1>" + String(txt);
|
||
|
|
page = "<h1>txx</h1><h1>[ ]:</h1> <h1 id=\"txt\">""</h1>\r\n";
|
||
|
|
page += "<script>\r\n";
|
||
|
|
page += "var x = setInterval(function() {loadData(\"txt.txt\",updateData)}, 1000);\r\n";
|
||
|
|
page += " function loadData(url, callback){\r\n";
|
||
|
|
page += " var xhttp = new XMLHttpRequest();\r\n";
|
||
|
|
page += " xhttp.onreadystatechange = function(){\r\n";
|
||
|
|
page += " if(this.readyState == 4 && this.status == 200){\r\n";
|
||
|
|
page += " callback.apply(xhttp);\r\n";
|
||
|
|
page += " }\r\n";
|
||
|
|
page += " };\r\n";
|
||
|
|
page += "xhttp.open(\"GET\", url, true);\r\n";
|
||
|
|
page += "xhttp.send();\r\n";
|
||
|
|
page += "}\r\n";
|
||
|
|
page += "function updateData(){\r\n";
|
||
|
|
page += " document.getElementById(\"txt\").innerHTML = this.responseText;\r\n";
|
||
|
|
page += "}\r\n";
|
||
|
|
page += "</script>\r\n";
|
||
|
|
server.send(200, "text/html", page);
|
||
|
|
});
|
||
|
|
|
||
|
|
server.begin();
|
||
|
|
Serial.println("started");
|
||
|
|
}
|
||
|
|
|
||
|
|
void loop() {
|
||
|
|
|
||
|
|
if (Serial.available() > 0) {
|
||
|
|
String txt = Serial.readStringUntil('\n');
|
||
|
|
//txt += txx;
|
||
|
|
Serial.println(txt);
|
||
|
|
Serial.println(page);
|
||
|
|
}
|
||
|
|
|
||
|
|
server.handleClient();
|
||
|
|
}
|