m5paper_weather_wifi.ino
Connects the M5Paper to Wi-Fi, queries a weather API, and displays the temperature on the e-Ink.
Requires WiFi, HTTPClient, and ArduinoJson libraries. Replace Wi-Fi credentials and API key. The e-Ink is low power but Wi-Fi is energy-intensive: use deep sleep if possible. GC16 refresh ensures good readability.
m5paper_weather_wifi.ino
#include <M5EPD.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASS";
const char* api_url = "http://api.openweathermap.org/data/2.5/weather?q=Paris&appid=YOUR_API_KEY&units=metric";
M5EPD_Canvas canvas(&M5.EPD);
void setup() {
M5.begin();
M5.EPD.SetRotation(90);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { delay(500); }
canvas.createCanvas(540, 960);
canvas.setTextSize(2);
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(api_url);
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 desc = doc["weather"][0]["description"];
canvas.clear();
canvas.setCursor(10, 10);
canvas.printf("Temp: %.1f C\nDesc: %s", temp, desc.c_str());
canvas.pushCanvas(0, 0, UPDATE_MODE_GC16);
}
http.end();
}
delay(600000); // Update every 10 mins
}