#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL3XvWT_aYr"
#define BLYNK_TEMPLATE_NAME "poject3"
#define BLYNK_AUTH_TOKEN "gJy4oWMLQLVd3f0k3yRpeGFlszSQ7sMx"

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

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

BlynkTimer timer;

const byte LED1 = 13; // Merah
const byte LED2 = 12; // Kuning
const byte LED3 = 14; // Hijau


DHTesp dhtSensor1, dhtSensor2;
const int DHT1_PIN = 15;
const int DHT2_PIN = 21;

#define Trig 18
#define Echo 19
float jarak = 0;
float ketinggian_air = 0;



void setup()
{
  dhtSensor1.setup(DHT1_PIN, DHTesp::DHT22);
  dhtSensor2.setup(DHT2_PIN, DHTesp::DHT22);

  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(Trig, OUTPUT);
  pinMode(Echo, INPUT);
  Serial.begin(9600);
  //Blynk.begin(auth, ssid, pass);
  Blynk.begin(auth, ssid, pass, "iot.serangkota.go.id", 8080);
}

void loop()
{
  TempAndHumidity  data1 = dhtSensor1.getTempAndHumidity();
  TempAndHumidity  data2 = dhtSensor2.getTempAndHumidity();
  baca_jarak();
  Blynk.virtualWrite(V12, data1.temperature);
  Blynk.virtualWrite(V13, data1.humidity);
  Blynk.virtualWrite(V14, data2.temperature);
  Blynk.virtualWrite(V15, data2.humidity);

  Blynk.virtualWrite(V16, ketinggian_air);

  Blynk.run();
  timer.run();
}