+ajout d'un client HTTP vers djxmmx.net (exemple WiFIClient de l'IDE)
le client HTTP se connecte bien au site distant via les deux adresses IP alternées
#include <ESP8266WiFi.h>
// paramètres du point d'accès
const char* ssid = "Freebox-XXXXXX
const char* password = "motdepasse";
const char* host = "djxmmx.net";
const uint16_t port = 17;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Zapping IP");
WiFi.mode(WIFI_OFF);
}
//////////////////////////////////////////////////////
void loop() {
WiFi.mode(WIFI_STA);
delay(100);
WiFi.config(IPAddress(192, 168, 1, 40), IPAddress(192, 168, 1, 254), IPAddress(255, 255, 255, 0), IPAddress(192, 168, 1, 254));
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(WiFi.localIP());
delay (1000);
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
delay(5000);
return;
}
// This will send a string to the server
Serial.println("sending data to server");
if (client.connected()) {
client.println("hello from ESP8266");
}
// wait for data to be available
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
delay(60000);
return;
}
}
// Read all the lines of the reply from server and print them to Serial
Serial.println("receiving from remote server");
// not testing 'client.connected()' since we do not need to send data here
while (client.available()) {
char ch = static_cast<char>(client.read());
Serial.print(ch);
}
Serial.println("deconnection");
WiFi.disconnect();
delay(100);
WiFi.mode(WIFI_OFF);
delay(1000);
// on zappe
WiFi.mode(WIFI_STA);
delay(100);
WiFi.config(IPAddress(192, 168, 1, 41), IPAddress(192, 168, 1, 254), IPAddress(255, 255, 255, 0), IPAddress(192, 168, 1, 254));
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(WiFi.localIP());
delay (1000);
// Use WiFiClient class to create TCP connections
WiFiClient client2;
if (!client2.connect(host, port)) {
Serial.println("connection failed");
delay(5000);
return;
}
// This will send a string to the server
Serial.println("sending data to server");
if (client2.connected()) {
client2.println("hello from ESP8266");
}
// wait for data to be available
unsigned long timeout2 = millis();
while (client2.available() == 0) {
if (millis() - timeout2 > 5000) {
Serial.println(">>> Client Timeout !");
client2.stop();
delay(60000);
return;
}
}
// Read all the lines of the reply from server and print them to Serial
Serial.println("receiving from remote server");
// not testing 'client.connected()' since we do not need to send data here
while (client2.available()) {
char ch = static_cast<char>(client2.read());
Serial.print(ch);
}
Serial.println("deconnection");
WiFi.disconnect();
delay(100);
WiFi.mode(WIFI_OFF);
delay(1000);
}
4:58:47.193 -> ..............................192.168.1.40
14:58:48.957 -> sending data to server
14:58:49.057 -> receiving from remote server
14:58:49.057 -> "Assassination is the extreme form of censorship."
14:58:49.057 -> George Bernard Shaw (1856-1950)
14:58:50.855 -> ..............................192.168.1.41
14:58:55.780 -> sending data to server
14:58:55.914 -> receiving from remote server
14:58:55.914 -> "My spelling is Wobbly. It's good spelling but it Wobbles, and the letters
14:58:55.914 -> get in the wrong places." A. A. Milne (1882-1958)
14:58:57.710 -> ..............................192.168.1.40
14:59:02.668 -> sending data to server
14:59:02.768 -> receiving from remote server
14:59:02.768 -> "Assassination is the extreme form of censorship."
14:59:02.768 -> George Bernard Shaw (1856-1950)
......je vois ça comme un amusement, pas comme quelque chose à mettre en place 'pour de vrai' !!