#include <WiFi.h>
#include <HTTPClient.h>
const char* token = "qYI7U0spfgf0n3TcB5zy3QVU3ZF1LDyAZxPuMnZIvhh";
int ledPin = 13;
int inputPin = 2;
int pirState = LOW;
int val = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
Serial.begin(9600);
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println("Connected!");
}
void loop () {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin ("https://notify-api.line.me/api/notify");
http.addHeader ("Authorization", "Bearer " + String(token));
http.addHeader ("Content-Type", "application/x-www-form-urlencoded");
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
http.POST ("message = แจ้งเดือนผู้บุกรุก") ;
Serial.println("ส่งข้อความ : แจ้งเตือนผู้บุกรุก !");
Serial.println ("================================");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH) {
// we have just turned of
http.POST ("message = เหตุการณ์ปกติ") ;
Serial. println("ส่งข้อความ : เหตุการณ์ปกติ !") ;
Serial.println ("================================");
// We only want to print on the output change, not state
pirstate = LOW;
}
}
delay(1000);
}
}