Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ) ...

Webpage

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...

enter image description here

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!

share|improve this question
1  
Do you have an external FTDI that you can use to 'eavesdrop' on the serial line going to and from the ESP? If you can plug the RX side of the FTDI into the TX from the Arduino, you can see what it is sending, going the other way, the RX to the Arduino, you can see what the ESP is sending back. That will give you an idea if your code is not interpreting something correctly, or if you have another issue. – Butters Dec 1 '15 at 16:50
    
i have placed // Wait until the client sends some data Serial.println("new client"); while(!client.available()){ delay(1); client.flush(); } it fixes the error but there is a of 3 secs delay ..... when i click Unlock door 1 ... it turns off the arduino light after 2-4 secs.... y this delay? – Haziq Sheikh Dec 2 '15 at 16:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.