/*
Blynk example
You should get Auth Token in the Blynk App.
You need to write the right wifiCredentials.
*/
/* Comment this out to disable prints and save space */
#define BLYNK_TEMPLATE_ID "TMPL6aZTAF55M"
#define BLYNK_TEMPLATE_NAME "LED Temperature Humidity"
#define BLYNK_AUTH_TOKEN "jSqK7R1hQ2zgrKZvC6WgRtoDx42HQ8ZP"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST"; //nama hotspot yang digunakan
char pass[] = ""; //password hotspot yang digunakan
#define DHTPIN 12 // Mention the digital pin where you connected
#define DHTTYPE DHT22 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
BLYNK_WRITE(V0)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
if (pinValue == 1)
{
digitalWrite(4, HIGH);
}
else {
digitalWrite(4, LOW);
}
// process received value
}
void setup()
{
// Debug console
Serial.begin(115200);
pinMode(4, OUTPUT);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
dht.begin();
timer.setInterval(2500L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
void sendSensor(){
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V2, h);
Blynk.virtualWrite(V1, t);
Serial.print("Temperature : ");
Serial.print(t);
Serial.print(" Humidity : ");
Serial.println(h);
if(t > 30){
// Blynk.email("[email protected]", "Alert", "Temperature over 28C!");
Blynk.logEvent("temp_alert","Temp above 30 degrees");
}
}