#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi connected!");
Serial.println("Butterfree Abilities\n");
}
void loop() {
String url = "https://pokeapi.co/api/v2/pokemon/butterfree";
HTTPClient http;
http.begin(url.c_str());
int httpCode = http.GET();
if (httpCode > 0) {
// Check the response status code
if (httpCode == 200) {
// Parse JSON data
String payload = http.getString();
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
// Fetching Pokemon abilities
JsonArray abilities = doc["abilities"];
for (int i = 0; i < abilities.size(); i++) {
JsonObject ability = abilities[i];
String abilityName = ability["ability"]["name"];
Serial.print("Ability: ");
Serial.println(abilityName);
delay(2000); // Delay between printing abilities
}
} else {
Serial.print("Failed to fetch Pokemon data. HTTP: ");
Serial.println(httpCode);
}
} else {
Serial.println("Failed to connect to server.");
}
http.end();
delay(2000); // Delay before next request
}