Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *****************************************************************************
- *
- * Tempo EDF ESP32 LED
- *
- *****************************************************************************
- Il vous faut : 6 led pour le projet (2 bleu, 2 blanches, 2 rouges),
- 2 résistances de 220 ohms,
- 1 ESP32 S1,
- 1 breadboard,
- des fils de connexion.
- Change ton mot de passe wifi et ton ssid dans le code( ligne 32 et 33).
- Vous pouvez aussi passer par un écran LCD pour afficher la couleur du jour et de demain.
- Deux leds RGB ca ferais aussi bien le job.
- Merci de regarder ma petite chaine =)
- * Web : https://www.makertronic-yt.com
- * version : 1.2
- * Copyright 2024
- */
- // include des librairies
- #include <Arduino.h>
- #include <WiFi.h>
- #include "time.h"
- #include <HTTPClient.h>
- #include <ArduinoJson.h>
- // connexion wifi
- const char* ssid = "xxxxxxxxxxxxxx";
- const char* password = "xxxxxxxxxxxxx";
- // serveur NTP
- const char* ntpServer = "pool.ntp.org";
- const long gmtOffset_sec = 3600 * 1;
- const int daylightOffset_sec = 3600 * 0;
- // leds
- const int ledJourBleu = 4;
- const int ledJourBlanc = 16;
- const int ledJourRouge = 17;
- const int ledDemainBleu = 25;
- const int ledDemainBlanc = 26;
- const int ledDemainRouge = 27;
- void setup(){
- Serial.begin(9600);
- delay(1000);
- WiFi.mode(WIFI_STA); //Optional
- WiFi.begin(ssid, password);
- Serial.println("\nConnection Wifi ...");
- while(WiFi.status() != WL_CONNECTED){
- Serial.print(".");
- delay(100);
- }
- Serial.println("\nConnecté au réseau Wifi !");
- Serial.print("IP locale: ");
- Serial.println(WiFi.localIP());
- // On configure le seveur NTP
- configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
- // leds en sortie
- pinMode(ledJourBleu, OUTPUT);
- pinMode(ledJourBlanc, OUTPUT);
- pinMode(ledJourRouge, OUTPUT);
- pinMode(ledDemainBleu, OUTPUT);
- pinMode(ledDemainBlanc, OUTPUT);
- pinMode(ledDemainRouge, OUTPUT);
- }
- void loop() {
- // recup du jour de l'année format AAAA/MM/JJ
- struct tm timeinfo;
- if (!getLocalTime(&timeinfo)) {
- Serial.println("Erreur de recup de l'heure");
- }
- char strftime_buf[20];
- strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%d", &timeinfo);
- //Serial.println(strftime_buf); // debug date du jour
- // Construire l'URL avec la date formatée
- String url = "https://particulier.edf.fr/services/rest/referentiel/searchTempoStore?dateRelevant=" + String(strftime_buf);
- Serial.println(url); // debug url
- // Effectuer la requête HTTP
- HTTPClient http;
- http.begin(url);
- int httpCode = http.GET();
- if (httpCode > 0) {
- if (httpCode == HTTP_CODE_OK) {
- String payload = http.getString();
- // Parse JSON avec ArduinoJSON
- const size_t capacity = JSON_OBJECT_SIZE(2) + 100;
- DynamicJsonDocument doc(capacity);
- deserializeJson(doc, payload);
- // Extraire les valeurs
- const char* couleurJourJ = doc["couleurJourJ"];
- const char* couleurJourJ1 = doc["couleurJourJ1"];
- // DEBUG
- //Serial.print("CouleurJourJ: ");
- //Serial.println(couleurJourJ);
- //Serial.print("CouleurJourJ1: ");
- //Serial.println(couleurJourJ1);
- // Affichage des LEDs du jour
- Serial.print("CouleurJourJ: ");
- if (strcmp(couleurJourJ, "TEMPO_BLEU") == 0) {
- Serial.println("bleu");
- digitalWrite(ledJourBleu, HIGH);
- digitalWrite(ledJourBlanc, LOW);
- digitalWrite(ledJourRouge, LOW);
- }
- if (strcmp(couleurJourJ, "TEMPO_BLANC") == 0) {
- Serial.println("blanc");
- digitalWrite(ledJourBleu, LOW);
- digitalWrite(ledJourBlanc, HIGH);
- digitalWrite(ledJourRouge, LOW);
- }
- if (strcmp(couleurJourJ, "TEMPO_ROUGE") == 0) {
- Serial.println("rouge");
- digitalWrite(ledJourBleu, LOW);
- digitalWrite(ledJourBlanc, LOW);
- digitalWrite(ledJourRouge, HIGH);
- }
- // Affichage des LEDs du lendemain
- Serial.print("CouleurJourJ1: ");
- if (strcmp(couleurJourJ1, "TEMPO_BLEU") == 0) {
- Serial.println("bleu");
- digitalWrite(ledDemainBleu, HIGH);
- digitalWrite(ledDemainBlanc, LOW);
- digitalWrite(ledDemainRouge, LOW);
- }
- if (strcmp(couleurJourJ1, "TEMPO_BLANC") == 0) {
- Serial.println("blanc");
- digitalWrite(ledDemainBleu, LOW);
- digitalWrite(ledDemainBlanc, HIGH);
- digitalWrite(ledDemainRouge, LOW);
- }
- if (strcmp(couleurJourJ1, "TEMPO_ROUGE") == 0) {
- Serial.println("rouge");
- digitalWrite(ledDemainBleu, LOW);
- digitalWrite(ledDemainBlanc, LOW);
- digitalWrite(ledDemainRouge, HIGH);
- }
- } // fin if (httpCode == HTTP_CODE_OK) {
- } else {
- Serial.println("Erreur de connexion au serveur EDF");
- } //if (httpCode > 0) {
- http.end();
- delay(300000); // Attendre 5 minutes avant de recommencer
- //delay(10000); // Attendre 10 secondes avant de recommencer (pour debug)
- }
Advertisement
Advertisement