#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
// Click here to get the library: http://librarymanager/All#DHTesp
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const String url = "https://api.thingspeak.com/channels/2374608/feeds.json?api_key=6KRLN9QVHQAS6API&results=2";
String myApikey = "6KRLN9QVHQAS6API";
HTTPClient http ;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Wifi Connected");
http.begin(url);
Serial.println("HTTP Started");
}
void loop() {
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
Serial.print("HTTP ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.print("Json file ");
Serial.println(payload);
// Disconnect
http.end();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
Serial.println(":-(");
}
delay(1000);
}