#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
// Replace with your network credentials (STATION)
#define ssid "Wokwi-GUEST"
#define password ""
void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
// WiFi.begin("Wokwi-GUEST", "");
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.println(WiFi.status());
Serial.print('.');
delay(1000);
}
Serial.println("Connected");
Serial.println(WiFi.status());
Serial.println(WiFi.localIP());
Serial.print("RRSI: ");
Serial.println(WiFi.RSSI());
}
void setup() {
Serial.begin(115200);
initWiFi();
}
void loop() {
WiFiClientSecure *client = new WiFiClientSecure;
client->setInsecure();
HTTPClient https;
Serial.println("HTTP request...");
if(https.begin(*client, "https://haixena-default-rtdb.asia-southeast1.firebasedatabase.app/master_NMaWVYZZeWhVfcR4Tw4VEjKe5zFyBEQ5APL.json")){
Serial.println("[HTTP] GET...");
int httpCode = https.GET();
if(httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY){
String payload = https.getString();
Serial.println(payload);
} else {
Serial.printf("error : %s \n", https.errorToString(httpCode).c_str());
}
} else {
Serial.printf("error");
}
https.end();
// put your main code here, to run repeatedly:
}