Bonjour, j'aurais besoin d'un renseignement a propos d'un code source d'exemple que j'ai modifié.
En effet j'ai un routeur qui régulierement plante et la connexion internet ne fonctionne plus, donc j'ai bricolé un espece de watch dog qui redemarre avec un relais qui coupe 5 secondes l'alimentation du routeur.
Je teste une adresse internet toutes les minutes, si elle ne marche pas je redemarrer mon routeur en coupant l'alimentation pendant 5 secondes.
J'ai modifié se code fournis en exemple, il fonctionne parfaitement mais il fait une requete mais je ne sais pas sur quel site est fait la requete, j'aurais aimé changer pour mettre l'url de google qui est tres fiable.
Voici le code:
/**
BasicHTTPSClient.ino
Created on: 20.08.2018
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#include "certs.h"
#ifndef STASSID
#define STASSID "wifi"
#define STAPSK "MONMOTDEPASSE"
#endif
ESP8266WiFiMulti WiFiMulti;
int led1 = 4;
void setup() {
Serial.begin(115200);
// Serial.setDebugOutput(true);
Serial.println();
Serial.println();
Serial.println();
WiFi.mode(WIFI_STA);
WiFiMulti.addAP(STASSID, STAPSK);
Serial.println("setup() done connecting to ssid '" STASSID "'");
pinMode(led1, OUTPUT); //led1 en sortie
digitalWrite(led1, LOW); //allumer le relais
}
void loop() {
// wait for WiFi connection
if ((WiFiMulti.run() == WL_CONNECTED)) {
std::unique_ptr<BearSSL::WiFiClientSecure> client(new BearSSL::WiFiClientSecure);
client->setFingerprint(fingerprint_sni_cloudflaressl_com);
// Or, if you happy to ignore the SSL certificate, then use the following line instead:
// client->setInsecure();
HTTPClient https;
Serial.print("[HTTPS] begin...\n");
if (https.begin(*client, jigsaw_host, jigsaw_port)) { // HTTPS
Serial.print("[HTTPS] GET...\n");
// start connection and send HTTP header
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);
Serial.println("connection*******************************");
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
digitalWrite(led1, LOW); // alimenter le relais
Serial.println("Echec connection CODE *******************************");
digitalWrite(led1, HIGH); //eteindre le relais
delay(5000); //attendre 5 secondes pour redemarrer
digitalWrite(led1, LOW); //allumer le relais
}
https.end();
} else {
Serial.printf("[HTTPS] Unable to connect\n");
Serial.println("Echec connection HTTPS *******************************");
digitalWrite(led1, HIGH); //eteindre le relais
delay(5000); //attendre 5 secondes pour redemarrer
digitalWrite(led1, LOW); //allumer le relais
}
}else{
//wifi non connecte
Serial.println("Echec connection WIFI *******************************");
digitalWrite(led1, HIGH); //eteindre le relais
delay(5000); //attendre 5 secondes pour redemarrer
digitalWrite(led1, LOW); //allumer le relais
}
Serial.println("Wait 60s before next round...");
delay(60000);
}
