wifi_weather_dashboard.ino

M5Stack PaperDIY Complete Kit · File : wifi_weather_dashboard.ino · Language : C++ (Arduino) · Use case : Connecter la carte au WiFi et récupérer des données météo via une API pour affichage partiel.

Connects to WiFi, queries a weather API, and updates the e-paper display.

Requires WiFi, HTTPClient, ArduinoJson, and GxEPD2 libraries. Replace WiFi credentials and API key. The screen refreshes slowly; avoid too frequent updates to save battery.

wifi_weather_dashboard.ino

#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <GxEPD2_BW.h>
#include <GxEPD2_4G01.h>

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
GxEPD2_4G01 epd;
GxEPD2_BW<GxEPD2_4G01, GxEPD2_4G01::HEIGHT> display(epd);

void setup() {
  Serial.begin(115200);
  display.init(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWiFi connected");
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    http.begin("http://api.openweathermap.org/data/2.5/weather?q=Paris&appid=YOUR_API_KEY");
    int httpCode = http.GET();
    if (httpCode > 0) {
      String payload = http.getString();
      DynamicJsonDocument doc(2048);
      deserializeJson(doc, payload);
      float temp = doc["main"]["temp"];
      
      display.clearScreen();
      display.setFont(&FreeSansBold12pt7b);
      display.setCursor(20, 50);
      display.print(String(temp, 1) + " C");
      display.display();
    }
    http.end();
  }
  delay(60000); // Update every minute
}

← Back to the board