- Thu Oct 27, 2016 9:19 am
#57214
Where to connect that Capacitor? can you send me the connection diagram?
Actually i am facing a problem with ESP8266, i am using it to blink a LED from a browser, i type the IP address of the ESP8266 and it'll load an html page written in that ESP, but it works for few trials, but after that it'll stop responding, in the sense it won't load the html page, but if we rest the ESP, then it'll start responding but problem remains unsolved, Please help me with this,, I'm Waiting..
i'm using this code for esp8266.
LOW logic to switch ON and HIGH logic to switch OFF
#include <ESP8266WiFi.h>
int a=0;
const char* ssid = "Automate";
const char* password = "qwerty123";
int ledPin1 = 5;
int ledPin2 = 4;
int ledPin3 = 13;
int ledPin4 = 12;
int ledPin5 = 14;
int ledPin6 = 16;
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
//Assigning the pins to particular lights and setting them as OUTPUTs
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
// initializing it to OFF condition
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, HIGH);
// 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.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
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 request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
static int value1 = HIGH;
static int value2 = HIGH;
static int value3 = HIGH;
static int value4 = HIGH;
static int value5 = HIGH;
static int value6 = HIGH;
// Set ledPin according to the request
//digitalWrite(ledPin, value);
//configuring fan number 1
if ((request.indexOf("LED1=ON") != -1)||(request.indexOf("LED7=ON") != -1)) {
digitalWrite(ledPin1, HIGH);
delay(250);
value1 = HIGH;
a=2;
}
if ((request.indexOf("LED1=OFF") != -1)||(request.indexOf("LED7=OFF") != -1)) {
digitalWrite(ledPin1, LOW);
value1 = LOW;
delay(250);
a=1;
}
//configuring fan number 2
if ((request.indexOf("LED2=OFF") != -1)||(request.indexOf("LED7=OFF") != -1)) {
digitalWrite(ledPin2, LOW);
value2 = LOW;
delay(250);
a=3;
}
if ((request.indexOf("LED2=ON") != -1)||(request.indexOf("LED7=ON") != -1)) {
digitalWrite(ledPin2, HIGH);
value2 = HIGH;
delay(250);
a=4;
}
//configuring fan number 3
if ((request.indexOf("LED3=OFF") != -1)||(request.indexOf("LED7=OFF") != -1)) {
digitalWrite(ledPin3, LOW);
value3 = LOW;
delay(250);
a=5;
}
if ((request.indexOf("LED3=ON") != -1)||(request.indexOf("LED7=ON") != -1)) {
digitalWrite(ledPin3, HIGH);
value3 = HIGH;
delay(250);
a=6;
}
//configuring fan number 4
if ((request.indexOf("LED4=OFF") != -1)||(request.indexOf("LED7=OFF") != -1)) {
digitalWrite(ledPin4, LOW);
value4 = LOW;
delay(250);
a=7;
}
if ((request.indexOf("LED4=ON") != -1)||(request.indexOf("LED7=ON") != -1)) {
digitalWrite(ledPin4, HIGH);
value4 = HIGH;
delay(250);
a=8;
}
//configuring fan number 5
if ((request.indexOf("LED5=OFF") != -1)||(request.indexOf("LED7=OFF") != -1)) {
digitalWrite(ledPin5, LOW);
value5 = LOW;
delay(250);
a=9;
}
if ((request.indexOf("LED5=ON") != -1)||(request.indexOf("LED7=ON") != -1)) {
digitalWrite(ledPin5, HIGH);
value5 = HIGH;
delay(250);
a=10;
}
//configuring fan number 6
if ((request.indexOf("LED6=OFF") != -1)||(request.indexOf("LED7=OFF") != -1)) {
digitalWrite(ledPin6, LOW);
value6 = LOW;
delay(250);
a=11;
}
if ((request.indexOf("LED6=ON") != -1)||(request.indexOf("LED7=ON") != -1)) {
digitalWrite(ledPin6, HIGH);
value6 = HIGH;
delay(250);
a=12;
}
// 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("<head><title>light controller</title></head>");
client.println("<body bgcolor=#ad2b10><center>");
client.println("<font color=#FFFFFF size=5>");
switch(a){
case 1: client.println("Fan 1 is ON now <br>");
break;
case 2: client.println("Fan 1 OFF now <br>");
break;
case 3: client.println("Fan 2 is ON now <br>");
break;
case 4: client.println("Fan 2 OFF now <br>");
break;
case 5: client.println("Fan 3 is ON now <br>");
break;
case 6: client.println("Fan 3 is OFF now <br>");
break;
case 7: client.println("Fan 4 is ON now <br>");
break;
case 8: client.println("Fan 4 is OFF now <br>");
break;
case 9: client.println("Fan 5 is ON now <br>");
break;
case 10: client.println("Fan 5 is OFF now <br>");
break;
case 11: if(request.indexOf("LED7=OFF") != -1) client.println("All Fans are ON now <br>");
else client.println("Fan 6 is ON now <br>");
break;
case 12: if(request.indexOf("LED7=ON") != -1) client.println("All Fans are OFF now <br>");
else client.println("Fan 6 is OFF now <br>");
break;
default : break;
}
client.println("</font></center>");
client.println("<br><br><br>");
client.println("<a href=\"http://192.168.0.110:8082/app/server_fan.html\" ><font size=4 color=#FFFFFF>Back</font></a><br />");
client.println("</html>");
client.stop();
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}