#include <WiFi.h>
const char *ServerTest = "google.fr";
uint16_t portTest = 80;
//const char *ServerTest = "fr.pool.ntp.org";
//uint16_t portTest = 80;
const char *txt = R"====(HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: 98\r\nConnection: close\r\n\r\n
Deb31/08/2025 23:11:33UxI019.50|-127.00|-127.00|-127.00|154605820798638346161264Fin\r\n)====";
String test = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: 98\r\nConnection: close\r\n\r\nDeb31/08/2025 23:11:33UxI019.50|-127.00|-127.00|-127.00|154605820798638346161264Fin";
void setup() {
Serial.begin(115200);
uint32_t timeout = millis();
String line = "";
int sizeOfContent = 0;
for (int i=0; i < test.length() + 1; i++) {
if (test.charAt(i) == '\n') {
if (line == "\r") {
Serial.println("Found");
break;
}
if (line.startsWith("Content-Length:")) {
Serial.println(line.substring(16));
sizeOfContent = line.substring(16).toInt();
}
Serial.println(line);
line="";
} else
line += String(test.charAt(i));
}
Serial.println(sizeOfContent);
Serial.println(line.length());
Serial.println(line);
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
Serial.print(".");
}
Serial.println(" Connected!");
WiFiClient WC; // WiFiClient is a wrong name for class, that work also for EthernetClient ?
bool internetAccess = false;
for (int i=0; i<3; i++ ) { // on test un certain nombre de fois si on a echec
if (WC.connect(ServerTest,portTest)) {
Serial.printf("access to %s on port %d\n",ServerTest,portTest);
WC.stop(); // nothing more
internetAccess = true;
break; // casse la boucle for
} else {
Serial.printf("Not access to %s on port %d\n",ServerTest,portTest);
}
}
Serial.println(String("We") + (internetAccess ? "" : " don't") + " have access to web");
Serial.println("That's all !");
}
void loop() {
delay(100); // TODO: Build something amazing!
}