如何解决无法从esp8266接收数据
我正在尝试使用esp8266和aruino uno从HTML页面接收密码,在代码中,串行监视器读取了该信息,如果正确,则闪烁led,但我不能正确接收此信息>
这是esp8266的代码,其中是HTML页面,密码请求和服务器
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
// WiFi network
const char* ssid = "Rede Wi-Fi de Leonard";
const char* password = "a01051970c";
ESP8266WebServer server ( 80 );
char htmlResponse[3000];
void handleRoot() {
snprintf ( htmlResponse,3000,"<!DOCTYPE html>\
<html lang=\"en\">\
<head>\
<style>\
body {background-color: rgb(250,250,250);}\
h3 {color: red;text-align:center;}\
p {color: black; text-align:center;}\
div {color: black; text-align:center;}\
ID {text-align:center;}\
input {text-align:center;}\
</style>\
<Meta charset=\"utf-8\">\
<Meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\
</head>\
<body>\
<h3>\<canter>MACK HOTEL</canter>\</h3>\
<p>\<canter>Entre com sua Senha</canter>\</p>\
<div>SENHA: <input type='text' name='pass_word' id='pass_word' align='center' size=10 autofocus></div> \
<div>\
<br><button id=\"save_button\">ENTRAR</button>\
</div>\
<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js\"></script>\
<script>\
var pass;\
$('#save_button').click(function(e){\
e.preventDefault();\
pass = $('#pass_word').val();\
$.get('/save?pass=' + pass,function(data){\
console.log(data);\
});\
});\
</script>\
</body>\
</html>");
server.send ( 200,"text/html",htmlResponse );
}
void handleSave() {
if (server.arg("pass")!= ""){
Serial.println(server.arg("pass"));
}
}
void setup() {
// Start serial
Serial.begin(115200);
delay(10);
// Connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid,password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.on ( "/",handleRoot );
server.on ("/save",handleSave);
server.begin();
Serial.println ( "HTTP server started" );
}
void loop() {
server.handleClient();
}
String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // whether the string is complete
void setup() {
// initialize serial:
Serial.begin(115200);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
pinMode(13,OUTPUT);
}
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
if (inputString=="123456")
{
digitalWrite(13,HIGH);
delay(300);
digitalWrite(13,LOW);
Serial.println(inputString);
// clear the string:
inputString = "";
stringComplete = false;
}
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline,set a flag so the main loop can
// do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
感谢所有支持!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。