#include <WiFi.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* host = "pokeapi.co";
const char* path = "/api/v2/pokemon/1";
void setup() {
Serial.begin(115200);
// Connect to WiFi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected!");
}
void loop() {
// Create an HTTP client object
WiFiClient client;
// Connect to the server
if (client.connect(host, 80)) {
// Send an HTTP GET request
client.print("GET ");
client.print(path);
client.print(" HTTP/1.1");
client.println();
client.println("Host: " + String(host));
client.println("Connection: close");
client.println();
// Wait for the server's response
while (client.connected()) {
while (client.available()) {
char c = client.read();
Serial.write(c);
}
delay(1);
}
// Close the connection
client.stop();
} else {
Serial.println("Failed to connect to server");
}
delay(1000);
}