0

Need help with a project on esp8266. I'm trying to do something like a chat. Combined several examples and wrote an html page. In theory, it should accept user input on a page in the Captive Portal. But that doesn't work, the data just isn't sent. Although in a regular browser everything works for this ip. Please tell me what could be the problem?

Code:

#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();
}
 
RtroN
  • 21
  • 2
  • 4
  • You really mean to hard code all that html in your application? That's going to be super painful to maintain / update down the line in a couple of years. – Jesper Juhl Jul 19 '20 at 20:00
  • You're right. I need to create an .html file and then open it as a string. – RtroN Jul 19 '20 at 20:07

0 Answers0