#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "WOKWI-GUEST";
const char* password = "";
// Token API dari ThingsBoard
const String apiToken = "dChrWQBx8iN5pzjYTLDK";
// URL REST API ThingsBoard untuk mendapatkan telemetry
const String thingsboardServer = "https://demo.thingsboard.io/api/v1/dChrWQBx8iN5pzjYTLDK/telemetry";
const String deviceId = "dChrWQBx8iN5pzjYTLDK";
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("\nConnected to WiFi!");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url = thingsboardServer + "/api/v1/" + apiToken + "/telemetry?keys=key1,key2"; // Ganti dengan keys yang relevan
http.begin(url);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
String payload = http.getString();
Serial.println("Telemetry Data:");
Serial.println(payload);
} else {
Serial.print("Error in GET request: ");
Serial.println(httpResponseCode);
}
http.end();
}
delay(10000);
}