-->
Page 1 of 1

Connect 2 esp8266 using Ardui IDE and get a resp from Server

PostPosted: Wed Nov 25, 2015 1:20 pm
by Luciano Jose
Hi everyone,

Like many try LUA and the arduino IDE or viceversa, now its my turn with the arduino IDE :) The examples of the libs worked fine, but I can not see how to connect between 2 esp and get a respond to the client from the server once the server got a msg from the client. I am very middle skill programmer so I copy & paste a lot and edit litle

the server code goes like:

Code: Select allvoid loop() {

  WiFiClient client = server.available();  // Check if a client has connected
   
  if (client==0) {
    return;
  }

  Serial.println("");
  Serial.println("New client");

  // Wait for data from client to become available
  while (client.connected() && !client.available()) {
    delay(1);
  }

  // Read the first line of HTTP request
  String req = client.readStringUntil('\r');
  Serial.print(req);   // I recieved msg ok!

  //server.print("loco");
//?? 
 // client.print("loco");     
  delay(100);
   
}


and this is the basis of the client which seems to be fine:

Code: Select allvoid loop() {
  delay(5000);

  Serial.print("connecting to ");
  Serial.println(host);
 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
 
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
 
  // This will send the request to the server
  client.print("que onda");
  delay(10);
 
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
 
  Serial.println();
  Serial.println("closing connection");
}


Hope someone can give me a hand on this to keep on going, thanks for reading!

Luciano

Re: Connect 2 esp8266 using Ardui IDE and get a resp from Se

PostPosted: Wed Nov 25, 2015 2:43 pm
by Venkatesh
Everything is already there in "Examples" section in arduino IDE (if you have already installed ESP framwork).

Have a look at it.

Re: Connect 2 esp8266 using Ardui IDE and get a resp from Se

PostPosted: Wed Nov 25, 2015 3:33 pm
by Luciano Jose
Hi, thanks for answering!

Looking deeply just found the examples nDNS_Web_Server where the server just flush the client after getting the msg and then just hit "client.print(s);" where "s" is a string, but mine client still get no answer... :oops:

Re: Connect 2 esp8266 using Ardui IDE and get a resp from Se

PostPosted: Wed Nov 25, 2015 4:35 pm
by Luciano Jose
This is finally how I ended up

Code: Select all  // Read the first line of HTTP request
  String req = client.readStringUntil('\r');
  Serial.print(req);

  client.flush();
  client.print("hear you"); 
  delay(200);
   }


client

Code: Select all  client.print("you hear me?");
  delay(100);
 
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
 
  Serial.println();
  Seri


any suggestion? thanks in advance