#define BLYNK_TEMPLATE_ID "TMPL6c1AliCrN"
#define BLYNK_TEMPLATE_NAME "NUT"
#define BLYNK_AUTH_TOKEN "4vCUqARQGMemeM5zIKdxIFAaq02K7vRZ"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <HTTPClient.h>
#include <ESP32Servo.h>
Servo myservo;
int ldr = 14;
int buttonPin1 = 12;
String LINE_TOKEN = "jH8iDpmcIfkhrme2PNO29vIlL24hq2RFD5iTO5dBDwJ"; // LINE Token
char auth[] = "cXoMLWAamGzzQDyS27NMA4Syg_V_xF5X"; // Blynk authentication token
char ssid[] = "Wokwi-GUEST"; // Wi-Fi SSID
char pass[] = ""; // Wi-Fi password
BlynkTimer timer;
void sendLineNotification(const char* message) {
HTTPClient http;
http.begin("https://notify-api.line.me/api/notify");
http.addHeader("Authorization", "Bearer " + LINE_TOKEN);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = http.POST("message=" + String(message));
String payload = http.getString();
Serial.println("HTTP Response Code: " + String(httpCode));
Serial.println("Response: " + payload);
http.end();
}
void setup() {
myservo.attach(12); // D22 (กำหนดขาควบคุม Servo)
Serial.begin(9600);
pinMode(ldr, INPUT);
Blynk.begin(auth, ssid, pass);
timer.setInterval(10000L, []() {
Blynk.virtualWrite(V1, millis() / 5000);
});
}
void loop() {
int val = analogRead(ldr);
Serial.print("ความเข้มแสง = ");
Serial.println(val);
Blynk.virtualWrite(V7,val);
if(val < 100 ){
sendLineNotification("ปิดการทำงาน");
delay(1000);
}
myservo.write(0);
if(val > 100 ){
sendLineNotification("เปิดการทำงาน");
delay(1000);
myservo.write(360);
}
Blynk.run();
timer.run();
}