#define THINGER_SERIAL_DEBUG
//memberitahu jika ada kesalahan program
#include<ThingerESP32.h>
#include <DHTesp.h>
//memanggil library thiner.io
#define username "dyah_k" //username di thinger.io
#define device_id "iot" //device yg dibuat di thinger.io
#define credential "12345678" //pass device di thinger.io
#define SSID "Wokwi-GUEST" //hotspot wokwi, bawaaan wokwi
#define password "" //tidak ada pass di wokwi hotspot
#define Lampu 18
#define trig 13
#define echo 12
const int DHT_PIN = 15;
DHTesp dhtSensor;
ThingerESP32 thing(username, device_id, credential);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(Lampu, OUTPUT);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
thing.add_wifi(SSID, password);
thing["Lampu"] << digitalPin(Lampu);//output ditandai << thing ke microcontroller
thing["temperature"] >> outputValue(dhtSensor.getTemperature());
thing["humidity"] >> outputValue(dhtSensor.getHumidity());
thing["Ultrasonic"] >> [] (pson& out){
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
long waktu = pulseIn(echo, HIGH);
double jarak = waktu/58;
out = jarak;
};
}
void loop() {
// put your main code here, to run repeatedly:
thing.handle();
}