meteo.ino
The case becomes a useful connected object: real temperature and humidity from open-meteo, no API key, refreshed every 10 minutes. The substring extraction dodges a JSON library for two fields.
Hardware required
An M5Stack Core Basic/Gray (ESP32 in an enclosure with a 320×240 TFT, A/B/C buttons, speaker, microSD slot, 110 mAh battery). A 2.4 GHz Wi-Fi access.
Wiring
No wiring. Check the module's range inside its metal shell if the signal is weak.
How it works
HTTPClient stacks TLS over the Wi-Fi stack; the JSON is tunneled with indexOf/substring — enough for two scalars. The HTTP error code triggers an explicit red screen. In the Arduino IDE (esp32 package), board « M5Stack-Core-ESP32 »; install the « M5Stack » (or M5Unified) library from the Library Manager, then Upload.
Going further
Add tomorrow's forecast, or a drawn pictogram per weather_code (sun, rain, snow).
meteo.ino
// Meteo via open-meteo (API sans cle) -> ecran. 1 rafraichissement / 10 min.
#include <M5Stack.h>
#include <WiFi.h>
#include <HTTPClient.h>
const char *SSID = "votre-wifi";
const char *CLE = "votre-cle";
const char *URL =
"https://api.open-meteo.com/v1/forecast?latitude=48.85&longitude=2.35"
"¤t=temperature_2m,relative_humidity_2m,weather_code";
void setup() {
M5.begin();
Serial.begin(115200);
WiFi.begin(SSID, CLE);
while (WiFi.status() != WL_CONNECTED) { delay(300); Serial.print("."); }
Serial.println(WiFi.localIP());
}
void loop() {
HTTPClient http;
http.begin(URL);
if (http.GET() == HTTP_CODE_OK) {
String j = http.getString();
// Extraction minimale sans bibliotheque JSON :
float t = j.substring(j.indexOf(""temperature_2m":") + 17).toFloat();
int h = j.substring(j.indexOf(""relative_humidity_2m":") + 24).toInt();
M5.Lcd.fillScreen(TFT_BLACK);
M5.Lcd.setTextSize(4);
M5.Lcd.setCursor(10, 40);
M5.Lcd.printf("%4.1f C", t);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(10, 130);
M5.Lcd.printf("Humidite %d %% %lus", h, millis() / 1000);
} else {
M5.Lcd.fillScreen(TFT_RED);
M5.Lcd.setTextColor(TFT_WHITE);
M5.Lcd.drawString("HTTP erreur — reseau ?", 20, 110, 2);
}
http.end();
delay(600000); // 10 min : l'API tolere, l'ecran aussi
}