/*
* 115200. Connect GPIO 0 of your ESP8266 to VCC and reset the board
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
MDNSResponder mdns;
// Network id and pw
const char* ssid = "MY_ID";
const char* password = "MY_PASSWORD";
ESP8266WebServer server(80);
String webPage = "";
int gpio0_pin = 0;
int gpio2_pin = 2;
void setup(void)
{
webPage += "<h1>ESP8266 Web Server</h1><p>Socket #1 <a href=\"socket1On\"><button>ON</button></a> <a href=\"socket1Off\"><button>OFF</button></a> </p>";
webPage += "<p>Socket #2 <a href=\"socket2On\"><button>ON</button></a> <a href=\"socket2Off\"><button>OFF</button></a></p>";
// preparing GPIOs
pinMode(gpio0_pin, OUTPUT);
digitalWrite(gpio0_pin, LOW);
pinMode(gpio2_pin, OUTPUT);
digitalWrite(gpio2_pin, LOW);
delay(1000);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (mdns.begin("esp8266", WiFi.localIP()))
Serial.println("MDNS responder started");
server.on("/", []()
{
server.send(200, "text/html", webPage);
});
server.on("/socket1On", []()
{
server.send(200, "text/html", webPage);
digitalWrite(gpio0_pin, HIGH);
delay(1000);
});
server.on("/socket1Off", []()
{
server.send(200, "text/html", webPage);
digitalWrite(gpio0_pin, LOW);
delay(1000);
});
server.on("/socket2On", []()
{
server.send(200, "text/html", webPage);
digitalWrite(gpio2_pin, HIGH);
delay(1000);
});
server.on("/socket2Off", []()
{
server.send(200, "text/html", webPage);
digitalWrite(gpio2_pin, LOW);
delay(1000);
});
server.begin();
Serial.println("HTTP server started");
}
void loop(void)
{
server.handleClient();
}
嗨我試圖用ESP8266使用Arduino做一個wifi網絡服務器。代碼在這個鏈接:code。我遵循this site的 步驟。我用我的ESP8266連接了我的yp-01(USB轉串口) 。警告:espcomm_sync失敗錯誤:espcomm_open失敗錯誤:espcomm_upload_mem失敗
- USB - > ESP
- TX - > RX
- RX - > TX
我用我的Arduino巨型的3.3V電源。
- ARDUINO - > ESP
- 3.3V - > VCC
- GND - > GND。
當我試圖把它上傳給出了錯誤代碼:
warning: espcomm_sync failed error: espcomm_open failed error: espcomm_upload_mem failed
我看過很多帖子,但他們沒有固定我的問題。有沒有人知道解決方案或有同樣問題的人?我正在使用ARduino IDE 1.6.9
GPIO0連接了一個10k電阻接地和CH_PD到VCC,它的工作原理。謝謝! –