m5paper_wifi_weather.ino

M5Paper: IoT Development Kit with Tactile e-Ink Display · File : m5paper_wifi_weather.ino · Language : Arduino · Use case : Afficher la météo en temps réel sur l'écran e-Ink via Wi-Fi.

Connects to a Wi-Fi network, fetches weather data via API, and displays it on the screen.

Requires WiFi, HTTPClient, and ArduinoJson libraries. The M5Paper uses its ESP32 Wi-Fi module. The e-Ink display is ideal for this use case as it only consumes power during refresh. Replace credentials with your own.

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
}

← Back to the board