Last active
April 13, 2025 19:10
-
-
Save maxpromer/7e5c8e0753e1766c5cfe56254c142037 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <WiFiManager.h> // นำเข้าไลบรารี่ WiFiManager | |
| #include <AmAlert.h> // นำเข้าไลบารี่ AmAlert | |
| #define ROOM_TOKEN "your ROOM token" // Room Token | |
| WiFiManager wm; | |
| void setup() { | |
| Serial.begin(115200); // เริ่มต้นใช้ Serial ที่ความเร็ว 115200 | |
| wm.resetSettings(); // ล้างการตั้งค่า WiFi ก่อนหน้านี้ (ใช้งานจริงต้องลบบรรทัดนี้ออก) | |
| bool res = wm.autoConnect("ESP32_Notify"); // กำหนด ESP32 กระจาย WiFi รออุปกรณ์อื่นเข้ามาตั้งค่า | |
| if (!res) { // ถ้ารับการตั้งค่าไม่สำเร็จ | |
| Serial.println("Failed to connect"); // | |
| ESP.restart(); // รีเซ็ตบอร์ด | |
| } | |
| Alert.begin(ROOM_TOKEN); // เริ่มต้นใช้ LINE Notify | |
| } | |
| void loop() { | |
| if (digitalRead(0) == LOW) { // ถ้ากดปุ่ม IO0 | |
| if (Alert.send("แจ้งเตือนกดปุ่ม")) { // ส่งข้อความ "แจ้งเตือนกดปุ่ม" ไปที่ Am Alert | |
| Serial.println("Send notify successful"); // ส่งข้อความ "Send notify successful" ไปที่ Serial Monitor | |
| } else { // ถ้าส่งไม่สำเร็จ | |
| Serial.printf("Send notify fail. check your token (code: %d)\n", Alert.status_code); // ส่งข้อความ "Send notify fail" ไปที่ Serial Monitor | |
| } | |
| while(digitalRead(0) == LOW) delay(10); // รอจนกว่าจะปล่อยสวิตช์ IO0 | |
| } | |
| delay(10); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment