Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *****************************************************************************
- *
- * Tempo EDF ESP32 TTGO Display V1.1
- *
- *****************************************************************************
- Change ton mot de passe wifi et ton ssid dans le code.
- * Web : https://www.makertronic-yt.com
- * copyright 2024
- */
- // include des librairies
- #include <Arduino.h>
- #include <WiFi.h>
- #include "time.h"
- #include <HTTPClient.h>
- #include <ArduinoJson.h>
- #include <TFT_eSPI.h>
- TFT_eSPI tft = TFT_eSPI();
- // connexion wifi
- const char* ssid = "xxxxxxxxxxx";
- const char* password = "xxxxxxxxxxxxxxxxxx";
- // serveur NTP
- const char* ntpServer = "pool.ntp.org";
- const long gmtOffset_sec = 3600 * 1;
- const int daylightOffset_sec = 3600 * 0;
- void setup(){
- Serial.begin(9600);
- delay(1000);
- tft.init();
- tft.setRotation(1);
- tft.fillScreen(TFT_BLACK); // Remplit l'écran en noir
- tft.setTextSize(3);
- WiFi.mode(WIFI_STA); //Optional
- WiFi.begin(ssid, password);
- tft.print("connecting");
- while (WiFi.status() != WL_CONNECTED) {
- delay(400);
- tft.print(".");
- }
- tft.print("CONECTED!!");
- delay(1000);
- tft.fillScreen(TFT_BLACK);
- // On configure le seveur NTP
- configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
- }
- void loop() {
- // recup du jour de l'année format AAAA/MM/JJ
- struct tm timeinfo;
- if (!getLocalTime(&timeinfo)) {
- tft.print("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);
- // 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"];
- // Affichage des LEDs du jour
- if (strcmp(couleurJourJ, "TEMPO_BLEU") == 0) {
- tft.setCursor(10, 20); // Position du premier texte
- tft.setTextColor(TFT_BLUE);
- tft.print("Jour Bleu");
- }
- if (strcmp(couleurJourJ, "TEMPO_BLANC") == 0) {
- tft.setCursor(10, 20); // Position du premier texte
- tft.setTextColor(TFT_WHITE);
- tft.print("Jour Blanc");
- }
- if (strcmp(couleurJourJ, "TEMPO_ROUGE") == 0) {
- tft.setCursor(10, 20); // Position du premier texte
- tft.setTextColor(TFT_RED);
- tft.print("Jour Rouge");
- }
- // Affichage des LEDs du lendemain
- tft.setCursor(10, 10); // Position du texte
- if (strcmp(couleurJourJ1, "TEMPO_BLEU") == 0) {
- tft.setCursor(10, 70);
- tft.setTextColor(TFT_BLUE);
- tft.print("Demain Bleu");
- }
- if (strcmp(couleurJourJ1, "TEMPO_BLANC") == 0) {
- tft.setCursor(10, 70);
- tft.setTextColor(TFT_WHITE);
- tft.print("Demain Blanc");
- }
- if (strcmp(couleurJourJ1, "TEMPO_ROUGE") == 0) {
- tft.setCursor(10, 70);
- tft.setTextColor(TFT_RED);
- tft.print("Demain Rouge");
- }
- } // fin if (httpCode == HTTP_CODE_OK) {
- } else {
- tft.print("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
Add Comment
Please, Sign In to add comment
Advertisement