#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPLLvxSOLGZ"
#define BLYNK_DEVICE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "DgY_zJDgBbDOjVNxZxSckZqXy3_Nz1-r"
#define LED 2

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


//#define BLYNK_TEMPLATE_ID "TMPL5EYssrpf"
//#define BLYNK_AUTH_TOKEN "nBs9gfFUTbxedF2Q5Eav43UqUZZZlgzG"


const int DHT_PIN = 15;
DHTesp dhtSensor;

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

BlynkTimer timer;
const float GAMMA = 0.7;
const float RL10 = 50;



void sendSensor()
{
  int analogValue = analogRead(32);
  float voltage = analogValue * 5/4095.0;
  float resistance = 2000 * voltage / (1 - voltage / 5);
  int lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
 // String (lux);
  Serial.print("Lux: ");
   Blynk.virtualWrite(V8, lux);
  Serial.println(lux);
 TempAndHumidity  data = dhtSensor.getTempAndHumidity();
 Serial.println("Temp: " + String(data.temperature, 2) + "°C");
 Serial.println("Humidity: " + String(data.humidity, 1) + "%");
 Serial.println("---");
 Blynk.virtualWrite(V5, data.temperature); 
 Blynk.virtualWrite(V7, data.humidity);//mengirimkan data ke Virtual pin di Blynk Cloud

}


void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);
 Serial.println("Hello, ESP32!");
  Blynk.begin(auth, ssid, pass);
  pinMode(LED, OUTPUT);
  dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
  timer.setInterval(1000L, sendSensor);
  
}

void loop() {
  // put your main code here, to run repeatedly:
   Blynk.run();
  timer.run();
  //delay(10); // this speeds up the simulation
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND
servo1:GND
servo1:V+
servo1:PWM
ldr1:VCC
ldr1:GND
ldr1:DO
ldr1:AO