#include <WiFi.h>
#include <HTTPClient.h>
class Rezz {
private:
String networkSSID;
String networkPWD;
boolean bing = false;
WiFiClient client;
HTTPClient http;
public:
Rezz(const String& ssid, const String& pwd) : networkSSID(ssid), networkPWD(pwd) {
WiFi.begin(networkSSID, networkPWD);
Serial.println("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
bing = !bing;
digitalWrite(2, bing);
}
Serial.println("Connected to WiFi");
digitalWrite(2, false);
}
String get(const String& endpoint) {
digitalWrite(2, true);
http.begin(client, endpoint);
int httpCode = http.GET();
String response = "-";
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
response = http.getString();
Serial.println("HTTP GET request successful");
}
} else {
Serial.println("HTTP GET request failed");
}
http.end();
digitalWrite(2, false);
return response;
}
};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Rezz rezz("Wokwi-GUEST", "");
String response = rezz.get("https://altablogs.vercel.app/api/bmkg-now");
Serial.println("Response:");
Serial.println(response);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}