Connect 2 esp8266 using Ardui IDE and get a resp from Server
Posted: Wed Nov 25, 2015 1:20 pm
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:
and this is the basis of the client which seems to be fine:
Hope someone can give me a hand on this to keep on going, thanks for reading!
Luciano
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 all
void 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 all
void 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