//arif kurnia rahma 4.33.23.0.05 TI-2A
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
String apiKey = "9adcac043f0ed09e176a4bd545ebae24";
String city = "Jakarta";
String units = "metric";
String server = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "&units=" + units + "&appid=" + apiKey;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(115200);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Cuaca");
WiFi.begin(ssid, password);
lcd.setCursor(0, 1);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
lcd.clear();
lcd.print("Connected!");
delay(2000);
lcd.clear();
}
void loop() {
if ((WiFi.status() == WL_CONNECTED)) {
HTTPClient http;
http.begin(server);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
Serial.println(payload);
int tempIndex = payload.indexOf("temp");
String temp = payload.substring(tempIndex + 6, payload.indexOf(",", tempIndex));
int descIndex = payload.indexOf("description");
String desc = payload.substring(descIndex + 14, payload.indexOf("\"", descIndex + 14));
lcd.setCursor(3, 0);
lcd.print(city);
lcd.setCursor(0, 1);
lcd.print(desc);
lcd.setCursor(8, 1);
lcd.print(temp);
lcd.print(" C");
} else {
Serial.println("Error on HTTP request");
}
http.end();
}
delay(60000);
}