#include <TridentTD_LineNotify.h>
#define SSID "xxxxxxxxx" //ใส่ ชื่อ Wifi ที่จะเชื่อมต่อ
#define PASSWORD "xxxxxxxxx" //ใส่ รหัส Wifi
#define LINE_TOKEN "xxxxxxxxxxxxxxxxxxxxxxxxxx" //ใส่ รหัส TOKEN ที่ได้มาจากข้างบน
void setup() {
Serial.begin(115200); Serial.println();
Serial.println(LINE.getVersion());
WiFi.begin(SSID, PASSWORD);
Serial.printf("WiFi connecting to %s\n", SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(400);
}
Serial.printf("\nWiFi connected\nIP : ");
Serial.println(WiFi.localIP());
// กำหนด Line Token
LINE.setToken(LINE_TOKEN);
// ตัวอย่างส่งข้อความ
LINE.notify("สวัสดีครับ");
LINE.notify("ครูโร สุดหล่อ");
// ตัวอย่างส่งข้อมูล ตัวเลข
LINE.notify(2342); // จำนวนเต็ม
LINE.notify(212.43434, 5); // จำนวนจริง แสดง 5 หลัก
// เลือก Line Sticker ได้จาก https://devdocs.line.me/files/sticker_list.pdf
LINE.notifySticker(3, 240); // ส่ง Line Sticker ด้วย PackageID 3 , StickerID 240
LINE.notifySticker("Hello", 1, 2); // ส่ง Line Sticker ด้วย PackageID 1 , StickerID 2 พร้อมข้อความ
// ตัวอย่างส่ง รูปภาพ ด้วย url
// LINE.notifyPicture("https://preview.ibb.co/j6G51n/capture25610417181915334.png");
//LINE.notifyPicture("จตุธาตุ", "https://www.fotoaparat.cz/storage/pm/09/10/23/670915_a5351.jpg");
}
void loop() {
delay(1);
}
#include <TridentTD_LineNotify.h>
#define SSID "TH Wi-Fi by NBTC" //ใส่ ชื่อ Wifi ที่จะเชื่อมต่อ
#define PASSWORD "" //ใส่ รหัส Wifi
#define LINE_TOKEN "hgZKpQ14FHaOliAv3zOXKCgwGxX22DYND4qfyFEALrX" //ใส่ รหัส TOKEN ที่ได้มาจากข้างบน
void setup() {
Serial.begin(115200); Serial.println();
Serial.println(LINE.getVersion());
WiFi.begin(SSID, PASSWORD);
Serial.printf("WiFi connecting to %s\n", SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(400);
}
Serial.printf("\nWiFi connected\nIP : ");
Serial.println(WiFi.localIP());
// กำหนด Line Token
LINE.setToken(LINE_TOKEN);
// ตัวอย่างส่งข้อความ
LINE.notify("สวัสดีครับ");
LINE.notify("ครูโร สุดหล่อ");
// ตัวอย่างส่งข้อมูล ตัวเลข
LINE.notify(2342); // จำนวนเต็ม
LINE.notify(212.43434, 5); // จำนวนจริง แสดง 5 หลัก
// เลือก Line Sticker ได้จาก https://devdocs.line.me/files/sticker_list.pdf
LINE.notifySticker(3, 240); // ส่ง Line Sticker ด้วย PackageID 3 , StickerID 240
LINE.notifySticker("Hello", 1, 2); // ส่ง Line Sticker ด้วย PackageID 1 , StickerID 2 พร้อมข้อความ
// ตัวอย่างส่ง รูปภาพ ด้วย url
// LINE.notifyPicture("https://preview.ibb.co/j6G51n/capture25610417181915334.png");
//LINE.notifyPicture("จตุธาตุ", "https://www.fotoaparat.cz/storage/pm/09/10/23/670915_a5351.jpg");
}
void loop() {
delay(1);
}
#include <WiFi.h>
#include <WiFiClientSecure.h>
//########## CONFIGURATION : MODIFY HERE ##########
char ssid[] = "TH Wi-Fi by NBTC"; // เครือข่าย Wi-Fi ที่ต้องการเชื่อมต่อ
char pass[] = ""; // รหัสผ่านเครือข่าย
//รหัสเชื่อมต่อ Line token
#define TokenLine "hgZKpQ14FHaOliAv3zOXKCgwGxX22DYND4qfyFEALrX"
// ข้อความ ที่จะแสดงใน Line
String txt1 = "มีผู้บุกรุก!!! ที่อาคาร 5";
//กำหนดขาที่เชื่อมต่อกับเซ็นเซอร์
byte sensorPin = 18;
void setup() {
//กำหนดให้ขาดิจิตอล sensorPin รับข้อมูลจากเซ็นเซอร์
pinMode(sensorPin, INPUT);
//ตั้งค่าคอนโซล
Serial.begin(115200);
//เริ่มการเชื่อมต่อกับวายฟายแม่ข่าย
WiFi.begin(ssid, pass);
//แสดง "WiFi Connecting" ในคอนโซล
Serial.print("WiFi Connecting");
//ตรวจเช็คสถานะการเขื่อมต่อวายฟาย
//ถ้าไม่สำเร็จให้แสดง "." ในคอนโซลจนกว่าจะเขื่อมต่อได้
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
//แสดงสถานะการวายฟายเชื่อมต่อแล้ว
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
}
void loop() {
byte state = digitalRead(sensorPin);
if (state == 1) {
Serial.println("Somebody is in this area!");
NotifyLine(txt1);
}
else if (state == 0) {
Serial.println("No one!");
}
delay(5000);
}
void NotifyLine(String t) {
WiFiClientSecure client;
if (!client.connect("notify-api.line.me", 443)) {
Serial.println("Connection failed");
return;
}
String req = "";
req += "POST /api/notify HTTP/1.1\r\n";
req += "Host: notify-api.line.me\r\n";
req += "Authorization: Bearer " + String(TokenLine) + "\r\n";
req += "Cache-Control: no-cache\r\n";
req += "User-Agent: ESP32\r\n";
req += "Content-Type: application/x-www-form-urlencoded\r\n";
req += "Content-Length: " + String(String("message=" + t).length()) + "\r\n";
req += "\r\n";
req += "message=" + t;
Serial.println(req);
client.print(req);
delay(20);
Serial.println("-------------");
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
break;
}
} //while
} //loop