html - 强制门户 esp8266
问题描述
在 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();
}
解决方案
推荐阅读
- html-framework-7 - Framework7 没有从 DOM 中的外部链接插入加载的内容
- javascript - 网页解析基础
- scala-gatling - 如何通过 GatLing-Scala 中的帖子发送从函数返回的文件?
- java - 正则表达式有什么问题?
- node.js - MongoDB 和 NodeJS 超过最大调用堆栈大小
- iis - 突然“文件未预编译,无法请求”
- python - 清理服务器端会话文件 - 使用文件系统的 Flask-Session
- visual-studio-2015 - CodeMap 不按顺序排列方法调用
- python - 使用管道和网格搜索执行特征选择
- r - 理解行为图与 sapply:查看包含特定值的列名