說明:ESP 8266計劃發行
我作出(01)上的ESP-8266 Web服務器,將控制使用的Arduino米加3個鎖定。
鎖將由藍牙,ESP 8266(從手機獲得方式)和使用我的筆記本電腦瀏覽器控制。
- 我可以用藍牙HC-05(輕鬆地)做到這一切。
我面對的問題是與我的ESP-8266 wifi模塊。
我需要從ESP發送3個不同的字符串給arduino來閱讀它。 如果它的「AAAA」的Arduino會讀它和開鎖之一,如果它BBBB然後門2和等等等等.....
所以我用下面的代碼:
#include <ESP8266WiFi.h>
const char* ssid = "Do-Not-Ask-For-Password";
const char* password = "ITISMYPASSWORD";
//const char* ssid = "`STAR-NET-Azhar-32210352";
//const char* password = "ITISMYPASSWORD";
int ledPin = 2; // GPIO2
WiFiServer server(80);
// Update these with values suitable for your network.
IPAddress ip(192,168,8,128); //Node static IP
IPAddress gateway(192,168,8,1);
IPAddress subnet(255,255,255,0);
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
ESP.wdtDisable();
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
// Serial.println("new client");
// while(!client.available()){
// delay(1);
// }
if(!client.available()){
delay(1);
client.flush();
}
// Read the first line of the request
String request = client.readStringUntil('\r');
//Serial.println(request);
client.flush();
// Match the request
int value1 = LOW;
int value2 = LOW;
int value3 = LOW;
if (request.indexOf("/LOCK=ON1") != -1) {
//digitalWrite(ledPin, HIGH);
value1 = HIGH;
Serial.println("AAAA");
}
if(request.indexOf("/LOCK=ON2") != -1){
value2 = HIGH;
Serial.println("BBBB");
}
if(request.indexOf("/LOCK=ON3") != -1){
value3 = HIGH;
Serial.println("CCCC");
}
// Set ledPin according to the request
//digitalWrite(ledPin, value);
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<br><br>");
client.print("LOCK ONE IS NOW: ");
if(value1 == HIGH) {
client.print("UNLOCKED");
// Serial.println("A");
} else {
client.print("LOCKED");
}
client.println("<br><br>");
client.print("LOCK TWO IS NOW: ");
if(value2 == HIGH) {
client.print("UNLOCKED");
// Serial.println("B");
} else {
client.print("LOCKED");
}
client.println("<br><br>");
client.print("LOCK THREE IS NOW: ");
if(value3 == HIGH) {
client.print("UNLOCKED");
//Serial.println("C");
} else {
client.print("LOCKED");
}
client.println("<br><br>");
client.println("CLICK <a href=\"/LOCK=ON1\">HERE</a> TO UNLOCK THE LOCK ONE<br>");
client.println("CLICK <a href=\"/LOCK=ON2\">HERE</a> TO UNLOCK THE LOCK TWO<br>");
client.println("CLICK <a href=\"/LOCK=ON3\">HERE</a> TO UNLOCK THE LOCK THREE<br>");
client.println("</html>");
delay(100);
//Serial.println("client disconnected");
// Serial.println("");
}
結果我獲取有關瀏覽器是(這正是我所需要的):
問題:
現在問題是有些時候它錯過了我發送的串行數據,例如,如果我點擊解鎖門1,它發送數據,我點擊解鎖門2它沒有,當我重置它發送所有3的數據,但爲兩到3次,然後模塊復位它的自我....
這是我得到了從串行監視器:
現在我有很多搜索和watchdre什麼我做錯了什麼代碼。
這是我的ESP是如何連接:
VCC & CHPD至3.3V ragulator
GND到powersuply的GND和Arduino的GND ...
GP 0 ----- - > 3.3v和2.2k電阻(非閃爍狀態)。
Rst的------> 3.3V與電阻
RX到TX
TX到RX
任何想法如何解決呢?
是否有任何其他方式來控制從ESP 8266模塊的Arduino引腳(6 diffrnt引腳)?
我一直試圖從很多天請幫助!