#define BLYNK_TEMPLATE_ID "TMPL6qG6EHv6W"
#define BLYNK_TEMPLATE_NAME "lab"
#define BLYNK_AUTH_TOKEN "pVrmTenxdJ0KocbRyq3CTEtVERv9riM7"
#include"DHTesp.h"
#include"WiFi.h"
#include"BlynkSimpleEsp32.h"
#include "HTTPClient.h"
DHTesp dht;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
char token[]="O2NnIj7tTIG8n7w4mgYZr8BFONjPMknzJ0oFpgONC2v";
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// Serial.println("Hello, ESP32!");
pinMode(0, OUTPUT);
dht.setup(14,DHTesp::DHT22);
Serial.println("Start Connecting WiFi...");
WiFi.begin(ssid,pass);
while(WiFi.status() != WL_CONNECTED){
delay(250);
Serial.print(".");
}
Serial.println("WiFi Connected...");
Serial.println("IP Address = ");
Serial.println(WiFi.localIP());
Blynk.config(BLYNK_AUTH_TOKEN);
}
void loop() {
Blynk.run();
float t = dht.getTemperature();
float h = dht.getHumidity();
Serial.print("Temperature = ");
Serial.print(t);
Serial.print(",Humidity = ");
Serial.println(h);
Blynk.virtualWrite(V0,t);
Blynk.virtualWrite(V1,h);
// HTTPClient http;
// http.begin("https//notify-api.line.me/api/notify");
// http.addHeader("Authorization","Bearer "+String(token));
// http.addHeader("Content-Tpye","application/x-www-from-urlencoded");
// http.POST("messege=test");
// delay(1000);
//int x = digitalRead(26);
//int
//int ldr = analogRead(27);
// Serial.println(ldr);
//if(ldr>1500){
// digitalWrite(0, HIGH);
//}
//else{
//digitalWrite(0, LOW);
//}
if(t > 30){
notify("แจ้งเตือนอุณหภูมิสูง");
}
if(h > 80){
notify("แจ้งเตือนชื้นสูง!!!");
}
delay(100); // this speeds up the simulation
}
BLYNK_WRITE(V2){
if(param.asInt()==1) { //`5hk sw gxbf
digitalWrite(0, HIGH);
}
else{
digitalWrite(0, LOW);
}
}
void notify (String s){
HTTPClient http;
http.begin("https//notify-api.line.me/api/notify");
http.addHeader("Authorization","Bearer "+String(token));
http.addHeader("Content-Tpye","application/x-www-from-urlencoded");
http.POST("messege="+String(s));
}