that my frist time to use esp8266 chip
i have problem and i try to fix it but i fail
i try to make http server with my esp to control 12 relay with browser
i make my code and upload it via arduino IDE
#include <ESP8266WiFi.h>
const char* ssid = "GJ";
const char* password = "nvidiageforce";
int led0 = 0; //1
//int led1 = 1; tx0
int led2 = 2; //2
//int led 3 = 3; rx0
int led4 = 4; //3
int led5 = 5; //4
int led6 = 6; //5
int led7 = 7; //6
int led8 = 8; //7
int led9 = 9; //8
int led10 = 10; //9
int led11 = 11; //10
int led12 = 12; //11
//int led13 = 13; rxd2
int led14 = 14; //12
//int led15 = 15; txd2
//int led16 = 16; wake
int value = LOW;
WiFiServer server(80);
void setup(){
Serial.begin(115200);
delay(100);
///////0
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
/////1
//pinMode(led1, OUTPUT);
//digitalWrite(led1, LOW);
/////2
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
/////3
//pinMode(led3, OUTPUT);
//digitalWrite(led3, LOW);
/////4
pinMode(led4, OUTPUT);
digitalWrite(led4, LOW);
/////5
pinMode(led5, OUTPUT);
digitalWrite(led5, LOW);
/////6
pinMode(led6, OUTPUT);
digitalWrite(led6, LOW);
/////7
pinMode(led7, OUTPUT);
digitalWrite(led7, LOW);
/////8
pinMode(led8, OUTPUT);
digitalWrite(led8, LOW);
/////9
pinMode(led9, OUTPUT);
digitalWrite(led9, LOW);
/////10
pinMode(led10, OUTPUT);
digitalWrite(led10, LOW);
/////10
pinMode(led10, OUTPUT);
digitalWrite(led10, LOW);
/////11
pinMode(led11, OUTPUT);
digitalWrite(led11, LOW);
/////12
pinMode(led12, OUTPUT);
digitalWrite(led12, LOW);
/////13
//pinMode(led13, OUTPUT);
//digitalWrite(led13, LOW);
/////14
pinMode(led14, OUTPUT);
digitalWrite(led14, LOW);
/////15
//pinMode(led15, OUTPUT);
//digitalWrite(led15, LOW);
/////16
//pinMode(led16, OUTPUT);
//digitalWrite(led16, LOW);
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");
server.begin();
Serial.println("Server started");
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("new client");
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<head>");
client.println("<title>ATS Systems</title>");
client.println("<meta charset=\"utf-8\">");
client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"stylesheet\" href=\"http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css\">");
client.println("<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js\"></script>");
client.println("<script src=\"http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js\"></script>");
client.println("</head>");
///led2
client.println("<body>");
client.println("<div class=\"container\">");
client.print("<h1>Elsayed Smart Home Device</h1>");
client.print("<h1>Room TV</h1>");
client.print("<p class=\"text-danger\">on-off Button:</p>");
client.print("<a href=\"/LED2=ON\" class=\"btn btn-success\" role=\"button\">ON</a>");
client.print("<a href=\"/LED2=OFF\" class=\"btn btn-danger\" role=\"button\">OFF</a>");
client.print("<br><br>");
client.println("Led2 pin is now: ");
if(value == HIGH) {
client.print("On");
} else {
client.print("Off");
}
///// led6
client.println("<body>");
client.println("<div class=\"container\">");
client.print("<h1>Room Light</h1>");
client.print("<p class=\"text-danger\">on-off Button:</p>");
client.print("<a href=\"/LED6=ON\" class=\"btn btn-success\" role=\"button\">ON</a>");
client.print("<a href=\"/LED6=OFF\" class=\"btn btn-danger\" role=\"button\">OFF</a>");
client.print("<br><br>");
client.println("Led6 pin is now: ");
if(value == HIGH) {
client.print("On");
} else {
client.print("Off");
}
client.println("</div>");
client.println("</body>");
client.println("</html>");
while(!client.available()){
delay(1);
}
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
//////2
if (request.indexOf('/LED2=ON') != -1) {
digitalWrite(led2, HIGH);
value = HIGH;
}
if (request.indexOf('/LED2=OFF') != -1) {
digitalWrite(led2, LOW);
value = LOW;
}
///////6
if (request.indexOf('/LED6=ON') != -1) {
digitalWrite(led6, HIGH);
value = HIGH;
}
if (request.indexOf('/LED6=OFF') != -1) {
digitalWrite(led6, LOW);
value = LOW;
}
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}
that code should control 2 relays one for pin (2) and one for pin (6)
and i uploaded my code but esp not run it
i can control just one pin but when i rewrite my code again to control more than one pin the ESP just reboot (( that what i think )) it give me that message via serial monitor
---------------------------------------------
ets Jan 8 2013,rst cause:4, boot mode:(3,6)
wdt reset
load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld
-------------------------------------------------
please i hope tell me how i can fix my code
sorry for my bad english
thanks for help