GET request to multiple server / Master to slaves
Posted: Thu Feb 20, 2020 3:28 am
Hello everyone,
\* I am new on this forum so I hope I can post it here
/* sorry for my bad English
I try to establish a link between one ESP8266 master and several ESP8266 slaves (max 5)
I succeed to control one esp by an other one using a request GET from my master (client) to the slave ( server)
But I can’t establish connexion to multiple server from my master.
My master create an access point,
Connect to the first server
Send a GET request
Close the connexion
But can t connect to the server2
However, I can send request to all different server from my phone.
Here the piece of code I use for the master part. (Slaves side works fine)
Is it possible to do it by several GET request or do I to built a MQQT broker or .... ?
Thank you very much for your advices.
J
\* I am new on this forum so I hope I can post it here
/* sorry for my bad English
I try to establish a link between one ESP8266 master and several ESP8266 slaves (max 5)
I succeed to control one esp by an other one using a request GET from my master (client) to the slave ( server)
But I can’t establish connexion to multiple server from my master.
My master create an access point,
Connect to the first server
Send a GET request
Close the connexion
But can t connect to the server2
However, I can send request to all different server from my phone.
Here the piece of code I use for the master part. (Slaves side works fine)
Is it possible to do it by several GET request or do I to built a MQQT broker or .... ?
Thank you very much for your advices.
J
Code: Select all
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
ESP8266WebServer server (80);
IPAddress IP(192,168,4,4);
IPAddress mask = (255, 255, 255, 0);
WiFiClient client;
/*IPAddress server(192,168,4,15);
IPAddress server2(192,168,4,20);// IP address of the AP
//const char* host = "192.168.4.15";*/
String host = "192.168.4.103";
String host2 = "192.168.4.104";
void setup() {
Serial.begin(9600);
// WiFi.mode(WIFI_AP);
WiFi.softAP("StudioPS", "studioPS");
WiFi.softAPConfig(IP, IP, mask);
server.begin();
pinMode(ledPin, OUTPUT);
Serial.println();
Serial.println("Server started.");
Serial.print("IP: "); Serial.println(WiFi.softAPIP());
Serial.print("MAC:"); Serial.println(WiFi.softAPmacAddress());
server.on("/go", go);
}
void loop() {
String url = "/go";
client.connect(host, 80);
if (client.connect(host, 80)) {
Serial.println("connected serveur 1");
}
Serial.println("envoi serveur 1");
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
client.stop();
Serial.println(client.connected());
delay(100);
client.connect(host2, 81);
if (client.connect(host2, 81)) {
Serial.println("connected serveur 2");
}
Serial.println("envoi serveur 2");
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host2 + "\r\n" + "Connection: close\r\n\r\n");
delay(100);
client.stop();
server.handleClient();
}
void go(){
Serial.println("serveur ESP12 OK");
// server.send(200, "text/", "");
}