Hi I am Using ESP 8266 to Send Serial Data To My Arduino Board using single click ( or post Action )..... My arduino mega controls 6 lights by reciving a character....
for example: if i type 'U' in serial monitor it turn on PIN 7 and turn off light from pin 6 if i type J thn it control 8 andd 9 pin and its working fine from serial monitor ....
next i tried through bluetooth it worked fine.....
Now i used ESP 8266 to send data when clicked .. initially it worked fine ... it was connecting to my router , was showing page using ip... but then it stoped working ...
This is the Sketch I uploaded on ESP using Arduino IDE...
#include <ESP8266WiFi.h>
const char* ssid = "Do-Not-Ask-For-Password";
const char* password = "MyRealPASSWORDHERE";
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(9600);
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() {
// 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
int value1 = LOW;
int value2 = LOW;
int value3 = LOW;
if (request.indexOf("/LOCK=ON1") != -1) {
//digitalWrite(ledPin, HIGH);
value1 = HIGH;
Serial.println("A");
}
if(request.indexOf("/LOCK=ON2") != -1){
value2 = HIGH;
Serial.println("B");
}
if(request.indexOf("/LOCK=ON3") != -1){
value3 = HIGH;
Serial.println("C");
}
// 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("");
}
MY web page is like this and works fine for the first time ( or as long as i am jus connected to laptop ) ...
And As I Connect Through Mobile it gets connected and when i refresh or click, it just do nothing excepting waiting for respose from the server and shows msg Timed Out...
I Have Checked 3 times as long as im running from single device mob or laptop it works fine but as i connect 2 devices it stop working on both devices!! Now My Question is !!!
is something wrong with my ESP 8266? Does ESP 8266 accept Multiple Connections ? What Should I do ? :(
Thanks In Advance!