#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Wire.h>
#include <SPI.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <Adafruit_ImageReader.h>
// Replace with your WiFi credentials
const char *ssid = "Wokwi-GUEST";
const char *password = "";
// Replace with your OpenWeatherMap API key
const char *apiKey = "f35a205df5b5b99f9ca991ab6b890e3b";
// Replace with your city ID
const int cityId = 1174872;
// Display and pins setup
Adafruit_ILI9341 tft = Adafruit_ILI9341(15, 2);
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(3);
tft.fillScreen(ILI9341_BLACK);
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Get image data from the internet
HTTPClient http;
http.begin("https://openweathermap.org/img/wn/10d.png");
int httpCode = http.GET();
if (httpCode != 200) {
Serial.println("Error getting image data");
} else {
int contentLength = http.getSize();
if (contentLength < 0) {
Serial.println("Failed to get content length");
} else {
// Allocate buffer for image data
uint8_t* buffer = new uint8_t[contentLength];
http.getStream().readBytes(buffer, contentLength);
// Decode image data
Adafruit_Image image = Adafruit_Image(buffer, contentLength);
if (!image.isValid()) {
Serial.println("Failed to decode image data");
} else {
// Display image on ILI9341
int x = (tft.width() - image.width()) / 2;
int y = (tft.height() - image.height()) / 2;
tft.drawImage(x, y, image);
}
}
}
http.end();
}
void loop() {
}