Advertisement
Makertronic

ESP32 TTGO DISPLAY S1

Jan 3rd, 2024
1,827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.98 KB | Software | 0 0
  1. /*
  2. *****************************************************************************
  3. *
  4. *                   Tempo EDF ESP32 TTGO Display V1.1
  5. *
  6. *****************************************************************************
  7.  
  8. Change ton mot de passe wifi et ton ssid dans le code.
  9.  
  10. * Web : https://www.makertronic-yt.com
  11. * copyright 2024
  12. */
  13.  
  14. // include des librairies
  15. #include <Arduino.h>
  16. #include <WiFi.h>
  17. #include "time.h"
  18. #include <HTTPClient.h>
  19. #include <ArduinoJson.h>
  20. #include <TFT_eSPI.h>
  21.  
  22. TFT_eSPI tft = TFT_eSPI();
  23.  
  24. // connexion wifi
  25. const char* ssid = "xxxxxxxxxxx";
  26. const char* password = "xxxxxxxxxxxxxxxxxx";
  27.  
  28. // serveur NTP
  29. const char* ntpServer = "pool.ntp.org";
  30. const long  gmtOffset_sec = 3600 * 1;
  31. const int   daylightOffset_sec = 3600 * 0;
  32.  
  33.  
  34.  
  35. void setup(){
  36.     Serial.begin(9600);
  37.     delay(1000);
  38.     tft.init();
  39.     tft.setRotation(1);
  40.     tft.fillScreen(TFT_BLACK); // Remplit l'écran en noir
  41.     tft.setTextSize(3);
  42.  
  43.     WiFi.mode(WIFI_STA); //Optional
  44.     WiFi.begin(ssid, password);
  45.     tft.print("connecting");
  46.  
  47.   while (WiFi.status() != WL_CONNECTED) {
  48.     delay(400);
  49.     tft.print(".");
  50.    }
  51.   tft.print("CONECTED!!");
  52.   delay(1000);
  53.   tft.fillScreen(TFT_BLACK);
  54.  
  55.     // On configure le seveur NTP
  56.     configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  57. }
  58.  
  59.  
  60. void loop() {
  61.  
  62.   // recup du jour de l'année format AAAA/MM/JJ
  63.   struct tm timeinfo;
  64.   if (!getLocalTime(&timeinfo)) {
  65.    tft.print("Erreur de recup de l'heure");
  66.   }
  67.  
  68.   char strftime_buf[20];
  69.   strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%d", &timeinfo);
  70.   //Serial.println(strftime_buf); // debug date du jour
  71.  
  72.   // Construire l'URL avec la date formatée
  73.   String url = "https://particulier.edf.fr/services/rest/referentiel/searchTempoStore?dateRelevant=" + String(strftime_buf);
  74.  
  75.   // Effectuer la requête HTTP
  76.   HTTPClient http;
  77.   http.begin(url);
  78.  
  79.   int httpCode = http.GET();
  80.   if (httpCode > 0) {
  81.     if (httpCode == HTTP_CODE_OK) {
  82.       String payload = http.getString();
  83.  
  84.       // Parse JSON avec ArduinoJSON
  85.       const size_t capacity = JSON_OBJECT_SIZE(2) + 100;
  86.       DynamicJsonDocument doc(capacity);
  87.       deserializeJson(doc, payload);
  88.  
  89.       // Extraire les valeurs
  90.       const char* couleurJourJ = doc["couleurJourJ"];
  91.       const char* couleurJourJ1 = doc["couleurJourJ1"];
  92.  
  93.    
  94.  
  95.       // Affichage des LEDs du jour
  96.       if (strcmp(couleurJourJ, "TEMPO_BLEU") == 0) {
  97.           tft.setCursor(10, 20); // Position du premier texte
  98.           tft.setTextColor(TFT_BLUE);
  99.           tft.print("Jour Bleu");
  100.          
  101.      
  102.       }
  103.       if (strcmp(couleurJourJ, "TEMPO_BLANC") == 0) {
  104.           tft.setCursor(10, 20); // Position du premier texte
  105.           tft.setTextColor(TFT_WHITE);
  106.           tft.print("Jour Blanc");
  107.          
  108.  
  109.       }
  110.       if (strcmp(couleurJourJ, "TEMPO_ROUGE") == 0) {
  111.            tft.setCursor(10, 20); // Position du premier texte
  112.            tft.setTextColor(TFT_RED);
  113.            tft.print("Jour Rouge");
  114.          
  115.    
  116.       }
  117.  
  118.       // Affichage des LEDs du lendemain
  119.       tft.setCursor(10, 10); // Position du texte
  120.       if (strcmp(couleurJourJ1, "TEMPO_BLEU") == 0) {
  121.           tft.setCursor(10, 70);
  122.           tft.setTextColor(TFT_BLUE);
  123.           tft.print("Demain Bleu");
  124.          
  125.  
  126.       }
  127.       if (strcmp(couleurJourJ1, "TEMPO_BLANC") == 0) {
  128.           tft.setCursor(10, 70);
  129.           tft.setTextColor(TFT_WHITE);
  130.           tft.print("Demain Blanc");
  131.          
  132.  
  133.    
  134.       }
  135.       if (strcmp(couleurJourJ1, "TEMPO_ROUGE") == 0) {
  136.           tft.setCursor(10, 70);
  137.           tft.setTextColor(TFT_RED);
  138.           tft.print("Demain Rouge");
  139.          
  140.      
  141.       }
  142.      
  143.     } // fin if (httpCode == HTTP_CODE_OK) {
  144.  
  145.   } else {
  146.     tft.print("Erreur de connexion au serveur EDF");
  147.   } //if (httpCode > 0) {
  148.  
  149.   http.end();
  150.  
  151.   delay(300000); // Attendre 5 minutes avant de recommencer
  152.   //delay(10000); // Attendre 10 secondes avant de recommencer (pour debug)
  153.  
  154. }
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement