#include "DHT.h"
#include <ThingerESP32.h>
#include <WiFi.h>
#define DHTPIN 12
#define DHTTYPE DHT22 
#define USERNAME "_ricoen"
#define DEVICE_ID "esp32"
#define DEVICE_CREDENTIAL "x3O2jEqIUEV1?cWa"

#define SSID "Wokwi-GUEST"
#define SSID_PASSWORD ""
ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

DHT dht(DHTPIN, DHTTYPE);
void setup() {
  thing.add_wifi(SSID, SSID_PASSWORD);
  
  dht.begin();

  Serial.begin(115200);

  Serial.print("Connecting to WiFi");
  WiFi.begin("Wokwi-GUEST", "", 6);
  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial.print(".");
  }
  Serial.println(" Connected!");

  thing["dht22"] >> [](pson& out){
      out["temperature"] = dht.readTemperature();
      out["humidity"] = dht.readHumidity();
  };
}

void loop() {
  thing.handle();

  thing.stream(thing["dht22"]);
}