#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPLghpwYzOc"
#define BLYNK_DEVICE_NAME "Petani"
#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(34);
  //float voltage = analogValue * 5/4095.0;
  //float resistance = 2000 * voltage / (1 - voltage / 5);
  //int keba = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
 // String (lux);
  int kebasahan = analogValue;
  Serial.print("kebasahan: ");
  Blynk.virtualWrite(V8, kebasahan);
  Serial.println(kebasahan);
 //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
}
GND5VSDASCLSQWRTCDS1307+