#define BLYNK_PRINT Serial

#define BLYNK_TEMPLATE_ID "TMPL6OwQ4AoOA"
#define BLYNK_TEMPLATE_NAME "DHT22"
#define BLYNK_AUTH_TOKEN "ZLPHXQzVzyA8qxt1Hw2J1UA50lrn52UG"

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHTesp.h"

int DHT_PIN = 15;
DHTesp dhtSensor;

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";

BlynkTimer timer;

void sendSensor()
{
 TempAndHumidity  data = dhtSensor.getTempAndHumidity();
 Serial.print("Temp: ");
 Serial.print(data.temperature);
 Serial.println(" °C");
 Serial.print("Humidity: ");
 Serial.print(data.humidity);
 Serial.println(" %");
 Serial.println("---");
 Blynk.virtualWrite(V1, data.temperature); 
 Blynk.virtualWrite(V2, data.humidity);//mengirimkan data ke Virtual pin di Blynk Cloud
}

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run();
  timer.run();
}