- Sat Sep 26, 2015 6:57 pm
#29952
Thanks for your reply.
I did exactly as you suggested, but no success.
For flashing, my setup is :
Vcc ->3.3V
Reset -> 3.3V
CH_PD -> 3.3V
GPIO 0 -> GND
GPIO 2 -> 3.3V via a 10K resistor (I once tried with GPIO2 left open too)
GND ->GND
Tx -> Rx
Rx -> Tx
Flashing succeeds using esptool (run as root)
Code: Select all./esptool.py --port=/dev/cu.wchusbserial1450 write_flash 0x0 /var/folders/r7/41c230xj3fz8d70lnbcbqg540000gq/T/build4549159985828382406.tmp/WiFiWebServer.cpp.bin -fs 32m -fm dio -ff 40m The WiFiWebServer.cpp.bin is from the examples included with esptool. I just added more Serial.print statements to check initialization.
Code: Select all#include <ESP8266WiFi.h>
const char* ssid = "MyNet";
const char* password = "MyPassword";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
Serial.print("Starting up... ");
// prepare GPIO2
pinMode(2, OUTPUT);
digitalWrite(2, 0);
// Connect to 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");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// 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);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();
// Match the request
int val;
if (req.indexOf("/gpio/0") != -1)
val = 0;
else if (req.indexOf("/gpio/1") != -1)
val = 1;
else {
Serial.println("invalid request");
client.stop();
return;
}
// Set GPIO2 according to the request
digitalWrite(2, val);
client.flush();
// Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s += (val)?"high":"low";
s += "</html>\n";
// Send the response to the client
client.print(s);
delay(1);
Serial.println("Client disonnected");
// The client will actually be disconnected
// when the function returns and 'client' object is detroyed
}
After flashing, I plug out the USB-FTDI, and change setup to this before plugging back in :
Vcc ->3.3V
Reset -> 3.3V
CH_PD -> 3.3V
GPIO 0 -> 3.3V via a 10K resistor
GPIO 2 -> 3.3V via a 10K resistor (I also once tried with GPIO2 left open)
GND ->GND
Tx -> Rx
Rx -> Tx
I launched Serial monitor with board as "Generic ESP8266" and correct port. But I don't see anything logged on serial monitor.
When I tried connecting from Esplorer, it doesn't even open connection (stuck up in Connecting without any errors).