#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6VAFvOJys"
#define BLYNK_TEMPLATE_NAME "Sensor Suhu dan Kelembaban"

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

const int DHT_PIN = 15;
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHTesp dhtSensor;
char auth[] = "NuB_9x43bAZe-W5I1MGYlNoBJ6wRvEAK";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;

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

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

void sendSensor() {
  TempAndHumidity data = dhtSensor.getTempAndHumidity();
  Blynk.virtualWrite(V0, data.temperature);
  Blynk.virtualWrite(V1, data.humidity);
  lcd.setCursor(0, 0);
  lcd.print("Temp = ");
  lcd.print(data.temperature);
  lcd.print(" C");
  lcd.setCursor(0, 1);
  lcd.print("Hum = ");
  lcd.print(data.humidity);
  lcd.print(" %");
  delay(1000);
}