需要有关esp8266的项目的帮助。我正在尝试进行聊天。结合几个示例并编写了一个html页面。从理论上讲,它应在Captive Portal中的页面上接受用户输入。但这不起作用,只是不发送数据。尽管在常规浏览器中,所有内容都适用于该IP。请告诉我可能是什么问题?
代码:
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
const byte DNS_PORT = 53;
IPAddress apIP(172, 0, 0, 1);
DNSServer dnsServer;
ESP8266WebServer webServer(80);
String handleRoot = ""
"<!DOCTYPE html>"
"<html lang='en'>"
"<head>"
"<meta charset='utf-8'>"
"<meta name='viewport' content='width=device-width, initial-scale=1'>"
"</head>"
"<body>"
"<h1>Ввод:</h1>"
"<input type='text' name='date_hh' id='date_hh' size=2 autofocus>"
"<div>"
"<br><button id='save_button'>Save</button>"
"</div>"
"<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js'></script>"
"<script>"
"var hh;"
"$('#save_button').click(function(e){"
"e.preventDefault();"
"hh = $('#date_hh').val();"
"$.get('/save?hh=' + hh, function(data){"
"console.log(data);"
"});"
"});"
"</script>"
"</body>"
"</html>";
void setup() {
Serial.begin(115200);
delay(10);
Serial.println("Started");
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP("INFO");
dnsServer.start(DNS_PORT, "*", apIP);
webServer.onNotFound([]() {
webServer.send(200, "text/html", handleRoot);
});
webServer.begin();
}
void loop() {
Serial.println(webServer.arg("hh"));
dnsServer.processNextRequest();
webServer.handleClient();
}