#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const int channel = 6;
const char* serverName = "https://pokeapi.co";
void setup() {
Serial.begin(9600);
Serial.print("Menghubungkan ke WiFi");
WiFi.begin(ssid, password, channel);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Terhubung!");
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
Serial.println("Mengakses API PokeAPI...");
http.begin(serverName);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
Serial.print("Kode Respon: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println("Respon API:");
Serial.println(payload);
} else {
Serial.print("Error pada permintaan: ");
Serial.println(http.errorToString(httpResponseCode).c_str());
}
http.end();
}
}
void loop() {
delay(100);
}