//#include #include #include #include #include // Time to sleep (in seconds): const int sleepTimeS = 10; // ======================= // WIFI // ======================= #include #include #include // Your WiFi credentials. // Set password to "" for open networks. const char* ssid = "Livebox-37cc"; const char* pass = "8A6060920A8A86896F770F2C47"; IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 0, 0); IPAddress DNS(192, 168, 1, 1); ESP8266WebServer server(80); const char* host = "192.168.1.3"; const int port = 81; const char* apiEndpoint = "/json.htm?type=command¶m=getSunRiseSet"; unsigned long lastUpdateTime = 0; const unsigned long updateInterval = 5 * 60 * 1000; // 5 minutes en millisecondes String currentTime = ""; String sunriseTime = ""; String sunsetTime = ""; String error = ""; String date = ""; String heure = ""; #define PIN_1 0 #define PIN_2 2 void setup() { // initialize digital pin LED_BUILTIN as an output. Serial.begin(115200); pinMode(PIN_1, OUTPUT); pinMode(PIN_2, OUTPUT); delay(10); // Connectez-vous au réseau WiFi WiFi.begin(ssid, pass); Serial.println("Connexion au WiFi en cours."); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(""); Serial.println("Connecté au réseau WiFi"); Serial.println(WiFi.localIP()); // Définissez les gestionnaires pour les différentes URL server.on("/", HTTP_GET, handleRoot); server.on("/allumer", HTTP_GET, handleAllumer); server.on("/eteindre", HTTP_GET, handleEteindre); // server.on("/stop", HTTP_GET, handleStop); // server.on("/reset", HTTP_GET, handleReset); // server.on("/setFinCourse", HTTP_GET, handleFinCourse); // server.on("/add", HTTP_GET, handleAdd); // server.on("/sub", HTTP_GET, handleSub); // server.on("/data", HTTP_GET, handleData); // Démarrer le serveur server.begin(); Serial.println("Serveur Web démarré"); /////////////////////////////////// // UPDATE OTA /////////////////////////////////// // Port defaults to 8266 ArduinoOTA.setPort(8266); // Hostname defaults to esp8266-[ChipID] //ArduinoOTA.setHostname("ESP8266_VELUX_NORD_1"); // No authentication by default // ArduinoOTA.setPassword("admin"); // Password can be set with it's md5 value as well // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3 // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3"); ArduinoOTA.onStart([]() { Serial.println("Start"); }); ArduinoOTA.onEnd([]() { Serial.println("\nEnd"); }); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { Serial.printf("Progress: %u%%\r", (progress / (total / 100))); }); ArduinoOTA.onError([](ota_error_t error) { Serial.printf("Error[%u]: ", error); if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); else if (error == OTA_END_ERROR) Serial.println("End Failed"); }); ArduinoOTA.begin(); handleEteindre(); } void loop() { // getJson(); ArduinoOTA.handle(); // Gérez les requêtes du serveur server.handleClient(); if (millis() - lastUpdateTime >= updateInterval) { // Mettre à jour le temps de la dernière mise à jour lastUpdateTime = millis(); } } void handleRoot() { // Générer la page HTML avec CSS String html = ""; html += ""; html += ""; html += ""; html += ""; html += ""; // html += ""; html += ""; html += "

Controle des batteries

"; html += "

" + String(WiFi.localIP().toString()) + "

"; html += "
    "; html += "
  • "; // html += ""; html += ""; html += "
  • "; html += "
  • "; html += ""; html += "
  • "; html += "
"; if (error != "") { html += "

" + error + "

"; } html += "
"; html += ""; // Envoyer la page HTML au client server.send(200, "text/html", html); } void handleAllumer() { Serial.println("avance"); digitalWrite(PIN_2, HIGH); delay(200); digitalWrite(PIN_1, HIGH); // Rediriger vers la page principale après le traitement server.sendHeader("Location", "/"); server.send(302, "text/plain", "Redirection vers la page principale"); } void handleEteindre() { digitalWrite(PIN_2, LOW); delay(200); digitalWrite(PIN_1, LOW); // turn the LED on (HIGH is the voltage level) delay(200); // Vous pouvez ajouter ici le code pour traiter la vitesse comme vous le souhaitez // Rediriger vers la page principale après le traitement server.sendHeader("Location", "/"); server.send(302, "text/plain", "Redirection vers la page principale"); }