Bonjour à vous tous.
J'ai récupéré un bout de code pour se connecter et envoyer une information sur un site web en https.
Le voici :
if ((WiFiMulti.run() == WL_CONNECTED)) {
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setFingerprint(fingerprint);
HTTPClient https;
Serial.print("[HTTPS] début...\n");
if (https.begin(*client, "https://www.test.ojjo.ca/HTTP/light.json")) {
Serial.print("[HTTPS] GET...\n");
// Démarre la connexion et envoie l'entête (header) HTTP
int httpCode = https.GET();
// httpCode aura une valeur négative en cas d'erreur
if (httpCode > 0) {
// L'entête HTTP a été envoyée et l'entête de la réponse du Serveur a été reçue
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
// Fichier non trouvé sur le Serveur
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
Serial.println(payload);
int start = payload.indexOf("light\":");
int end = payload.indexOf('\"', start + 11 );
String positionString = "";
for (int i= start + 9; i < end; i++)
positionString += payload.charAt(i);
// gestion de la LED
if (positionString == "on") {
Serial.print("LED Allumée \n");
digitalWrite(13, HIGH);
}
if (positionString == "off") {
Serial.print("LED Eteinte \n");
digitalWrite(13, LOW);
}
}
} else {
Serial.printf("[HTTPS] GET... échoué, error: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
} else {
Serial.printf("[HTTPS] Connexion impossible \n");
}
}
Serial.println("Attendre 1s avant de lire le fichier...");
delay(1000);
}
Je n'arrive pas à le transformer pour lire accéder à mon site web en http. Je n'ai par exemple pas besoin du finger print. mon site est www.test.ojjo.ca
merci de votre aide
pouvez vous me guider ?