Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Created March 3, 2025 18:38
Show Gist options
  • Save maxpromer/2d33125f681063dbeeb7fa8fb740e0a7 to your computer and use it in GitHub Desktop.
Save maxpromer/2d33125f681063dbeeb7fa8fb740e0a7 to your computer and use it in GitHub Desktop.
#include <WiFi.h> // นำเข้าไลบรารี่ WiFi
#include <ArtronShop_LineMessaging.h> // นำเข้าไลบารี่ ArtronShop_LineMessaging
const char* ssid = "WiFi Name"; // ชื่อ WiFi
const char* password = "WiFi Password"; // รหัสผ่าน WiFi
#define LINE_TOKEN "LINE Notify Token" // Channel access token
#define PIR_PIN (27) // กำหนดขาต่อเซ็นเซอร์ PIR
void setup() {
pinMode(PIR_PIN, INPUT); // กำหนดขาต่อ PIR เป็นอินพุตดิจิทัล
Serial.begin(115200); // เริ่มต้นใช้ Serial ที่ความเร็ว 115200
while (!Serial) { delay(100); }
// We start by connecting to a WiFi network
Serial.println();
Serial.println("******************************************************");
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password); // เริ่มต้นเชื่อมต่อ WiFi
while (WiFi.status() != WL_CONNECTED) { // วนลูปหากยังเชื่อมต่อ WiFi ไม่สำเร็จ
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
LINE.begin(LINE_TOKEN); // เริ่มต้นใช้ LINE Notify
}
bool send_finish = false; // ประกาศตัวแปร send_finish
void loop() {
if (digitalRead(PIR_PIN) == HIGH) { // ถ้า PIR ตรวจพบความเคลื่อนไหว
if (!send_finish) { // ถ้าตัวแปร send_finish ยังมีค่าเป็น false
LINE_Messaging_Massage_Option_t option; // สร้างตัวแปร option
option.map.service = LONGDO_MAP; // เลือกใช้ Longdo Map
option.map.lat = 13.91024; // ละติจูด
option.map.lng = 100.51108; // ลองจิจูด
option.map.zoom = 20; // ระยะซูม กำหนดได้ 1 - 20
if (LINE.send("User ID/Group ID", "ตรวจพบความเคลื่อนไหว", &option)) { // ส่งข้อความ "ตรวจพบความเคลื่อนไหว" ไปที่ LINE
Serial.println("Send notify successful"); // ส่งข้อความ "Send notify successful" ไปที่ Serial Monitor
send_finish = true; // กำหนดตัวแปร send_finish เป็น true
} else { // ถ้าส่งไม่สำเร็จ
Serial.printf("Send notify fail. check your token (code: %d)\n", LINE.status_code); // ส่งข้อความ "Send notify fail" ไปที่ Serial Monitor
}
}
} else { // ถ้าไม่ใช่
send_finish = false; // กำหนดตัวแปร send_finish เป็น false
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment