m5paper_wifi_weather.ino

M5Paper : Kit de développement IoT à écran e-Ink tactile · Fichier : m5paper_wifi_weather.ino · Langage : Arduino · Usage : Afficher la météo en temps réel sur l'écran e-Ink via Wi-Fi.

Se connecte à un réseau Wi-Fi, récupère des données météo via API et les affiche sur l'écran.

Requiert les bibliothèques WiFi, HTTPClient et ArduinoJson. Le M5Paper utilise son module Wi-Fi ESP32. L'affichage e-Ink est idéal pour ce type d'usage car il ne consomme d'énergie que lors du rafraîchissement. Remplacez les identifiants par les vôtres.

m5paper_wifi_weather.ino

#include <M5EPD.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
const char* apiURL = "http://api.openweathermap.org/data/2.5/weather?q=Paris&appid=YOUR_API_KEY&units=metric";

M5EPD m5;

void setup() {
  m5.begin();
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nConnected");
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    http.begin(apiURL);
    int httpCode = http.GET();
    
    if (httpCode == HTTP_CODE_OK) {
      String payload = http.getString();
      DynamicJsonDocument doc(1024);
      deserializeJson(doc, payload);
      
      float temp = doc["main"]["temp"];
      String weather = doc["weather"][0]["main"];
      
      m5.clear();
      m5.drawCentreString("Weather Paris", 480, 100, 4);
      m5.drawCentreString("Temp: " + String(temp) + " C", 480, 200, 4);
      m5.drawCentreString("Cond: " + weather, 480, 250, 4);
      m5.updateFrame();
    }
    http.end();
  }
  delay(60000); // Update every minute
}

← Retour à la fiche