/*
Data dari Blynk::
Template:
#define BLYNK_TEMPLATE_ID "TMPL1_D3O1KN"
#define BLYNK_DEVICE_NAME "DHT22"
Device:
#define BLYNK_TEMPLATE_ID "TMPL1_D3O1KN"
#define BLYNK_DEVICE_NAME "WokwikuDHT22"
#define BLYNK_AUTH_TOKEN "5mxv5VFJ-Gw68FpAg07Wygw9n5kAvuL5"
https://www.dropbox.com/s/v7e9dabfprvovgg/blynk_dht22_esp32.txt?dl=0
*/
#define BLYNK_PRINT Serial
//#define BLYNK_TEMPLATE_ID "TMPL1_D3O1KN"
#define BLYNK_TEMPLATE_ID "TMPL1_D3O1KN"
#define BLYNK_DEVICE_NAME "WokwikuDHT22"
#define BLYNK_AUTH_TOKEN "5mxv5VFJ-Gw68FpAg07Wygw9n5kAvuL5"
#define LED 2
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHTesp.h"
const int DHT_PIN = 15;
DHTesp dhtSensor;
char auth[] = "5mxv5VFJ-Gw68FpAg07Wygw9n5kAvuL5";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
BLYNK_WRITE(V0)
{
int pinValue = param.asInt();
digitalWrite(LED,pinValue);
}
void sendSensor()
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
Blynk.virtualWrite(V0, data.temperature); //mengirimkan data ke Virtual pin di Blynk Cloud
// Ganti dari V1 ke V0
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(LED, OUTPUT);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
timer.setInterval(2000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}