source
/*
* source : https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266HTTPClient/examples/BasicHttpsClient/BasicHttpsClient.ino
* attention, normalement il faudrait le « fingerprint » du certificat ssl de la page à charger dans le code
* ici on utilise le mode insecure qui ne vérifie pas le certificat en face
*/
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
// la librairie suivante fait partie de la librairie ESP8266HTTPClient (appremment ?)
#include <WiFiClientSecureBearSSL.h>
// Network SSID
const char* ssid = "le-SSID";
const char* password = "le-mot-de-passe";
WiFiClient wifiClient;
void setup() {
Serial.begin(115200);
delay(10);
// Connect WiFi
Serial.println();
Serial.println();
Serial.print("Tentative de connexion à ");
Serial.println(ssid);
WiFi.hostname("D1MINI"); // le nom sur le réseau ?
WiFi.begin(ssid, mot_de_passe);
// tant qu'on est pas connecté
while (WiFi.status() != WL_CONNECTED) {
// un « . » dans le monteur toutes les 0.5 secondes
delay(500);
Serial.print(".");
}
// une fois connecté
Serial.println("");
Serial.println("connexion WiFi établie");
// impression de l'adresse IP
Serial.print("Adresse IP : ");
Serial.print(WiFi.localIP());
}
void loop() {
// on attend la connexion WiFi
if (WiFi.status() == WL_CONNECTED) {
// ?
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
// on ne vérifie pas l'empreinte (fingerprint)
// l'exemple source le fait, mais cela veut dire qu'il faut chercher à l'avance l'empreinte du site
// et la mettre ici, la changer quand elle change
client->setInsecure();
HTTPClient https;
Serial.print("[HTTPS] début de la requête...\n");
if (https.begin(*client, "https://smsapi.free-mobile.fr/sendmsg?user=14700273&pass=wBTxb3VRGGHQPb&msg=je+suis+un+test%0D%0Asaut+de+ligne")) { // HTTPS
Serial.print("[HTTPS] GET...\n");
// on début la connexion et on envoie l'en-tête HTTP
int httpCode = https.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
} else {
Serial.printf("[HTTPS] Impossible de se connecter\n");
}
}
Serial.println("30 secondes avant le prochain essai...");
delay(30000);
}