#include <WiFi.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SdFat.h>
#include <Adafruit_SPIFlash.h>
#include <Adafruit_ImageReader.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const String endpoint = "http://api.openweathermap.org/data/2.5/weather?q=Lisbon,pt&APPID=";
const String key = "a43366d269246847b16ceac0e9fc3e3d";
#define BTN_PIN 5
#define TFT_DC 2
#define TFT_CS 15
#define SD_CS 21
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
SdFat SD;
Adafruit_ImageReader reader(SD);
void setup() {
pinMode(BTN_PIN, INPUT_PULLUP);
if (!SD.begin(SD_CS)){
Serial.println("SD card not initialized");
for(;;);
}
WiFi.begin(ssid, password, 6);
tft.begin();
tft.setRotation(1);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(100);
tft.print(".");
}
tft.print("\nOK! IP=");
tft.println(WiFi.localIP());
// ImageReturnCode stat; // Not sure what this is for
// stat = reader.drawBMP("/purple.bmp", tft, 0, 0); // Image rendering, not used in the loop
}
void loop() {
HTTPClient http;
http.begin(endpoint + key);
int httpcode = http.GET();
if (httpcode > 0){
String payload = http.getString();
tft.print(httpcode); // Corrected variable name
tft.print(payload);
}
else {
Serial.println("Error on HTTP request");
}
http.end(); // Free the resources
delay(30000);
}