m5paper_weather_wifi.ino
Conecta el M5Paper a Wi-Fi, consulta una API del clima y muestra la temperatura en la pantalla e-Ink.
Requiere las bibliotecas WiFi, HTTPClient y ArduinoJson. Reemplace las credenciales de Wi-Fi y la clave API. La pantalla e-Ink consume poca energía pero el Wi-Fi es intensivo: use sueño profundo si es posible. El refresco GC16 asegura buena legibilidad.
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
}