首页 > 解决方案 > 强制门户 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();
}
 

标签: htmlc++ajaxesp8266

解决方案


推荐阅读