Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Luciano Jose
#34984 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
User avatar
By Luciano Jose
#35000 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