#include <WiFi.h>
#include <ThingerESP32.h>
#include "DHT.h"
// Replace with your network credentials
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// Thinger.io credentials
#define USERNAME "bang_rayy" //Ganti ke username masing2
#define DEVICE_ID "dht22" //Ganti ke Device id masing2
#define DEVICE_CREDENTIAL "ty6YSO$9qPEhgsH5" //Ganti ke Device credential masing2
// DHT Sensor
#define DHTPIN 33 // GPIO pin where the DHT22 is connected
#define DHTTYPE DHT22 // DHT 22 (AM2302)
// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE);
// Initialize Thinger.io
ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
// Initialize DHT sensor
dht.begin();
// Define the resources for Thinger.io
thing.add_wifi(ssid, password);
thing["temperature"] >> [](pson& out){
float temp = dht.readTemperature();
if (isnan(temp)) {
Serial.println("Failed to read temperature!");
out = 0;
} else {
out = temp;
}
};
thing["humidity"] >> [](pson& out){
float hum = dht.readHumidity();
if (isnan(hum)) {
Serial.println("Failed to read humidity!");
out = 0;
} else {
out = hum;
}
};
}
void loop() {
thing.handle();
}