Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BLYNK_PRINT Serial // กำหนด BYNK_PRINT = เท่ากับ Serail
- #include <ESP8266WiFi.h> // เรียกใช้ library ESP8266WiFi8266.h เป็น library Wifi ESP8266
- #include <BlynkSimpleEsp8266.h> // เรียกใช้ library BlynkSimpleEsp8266.h เป็น library app Blynk
- #define SERVER_PORT 80 //กำหนด SERVER_PORT = 80
- #include <LiquidCrystal.h> // // เรียกใช้ library LiquidCrystal.h เป็น library จอ LCD
- #define LINE_TOKEN "NEO6NR0SJ6huFOOJfE4zcyntIRli0nXgougXSsHJ6SS" // รหัส LINE Notify token
- void Weather_display(); //กำหนด ฟังก์ชัน Weather_display
- void Line_Notify1(String message1) ; //กำหนด ฟังก์ชัน Line_Notify1
- void Line_Notify2(String message2) ; //กำหนด ฟังก์ชัน Line_Notify2
- void Line_Notify3(String message3) ; //กำหนด ฟังก์ชัน Line_Notify3
- void Line_Notify4(String message4) ; //กำหนด ฟังก์ชัน Line_Notify4
- void Line_Notify5(String message5) ; //กำหนด ฟังก์ชัน Line_Notify5
- void Line_Notify6(String message6) ; //กำหนด ฟังก์ชัน Line_Notify6
- void Line_Notify7(String message7) ; //กำหนด ฟังก์ชัน Line_Notify7
- String str_get1 = "GET /data/2.5/weather?q="; // กำหนดค่าคำสั่ง GET
- String str_get2 = "&APPID=0da75c9e4dbd2d567f43307b7236f9fb&mode=xml&units=metric HTTP/1.1\r\n"; // กำหนดคำสั่ง HTTP
- String str_host = "Host: api.openweathermap.org\r\n\r\n"; // กำหนด Server
- String Value ; // กำหนด Value เป็น String
- String city ; // กำหนด city เป็น String
- String message1 = "%E0%B9%80%E0%B8%A1%E0%B8%86%E0%B8%99%E0%B9%89%E0%B8%AD%E0%B8%A2%20%E0%B8%95%E0%B8%AD%E0%B8%99%E0%B8%A1%E0%B8%B5%E0%B9%81%E0%B8%94%E0%B8%94%E0%B8%99%E0%B9%88%E0%B8%B2%E0%B8%88%E0%B8%B0%E0%B9%81%E0%B8%A3%E0%B8%87%E0%B8%99%E0%B8%B0%20%20%E0%B8%96%E0%B9%89%E0%B8%B2%E0%B8%81%E0%B8%A5%E0%B8%B1%E0%B8%A7%E0%B9%81%E0%B8%94%E0%B8%94%E0%B8%9E%E0%B8%81%E0%B8%A3%E0%B9%88%E0%B8%A1%E0%B9%84%E0%B8%9B%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B8%81%E0%B9%87%E0%B9%84%E0%B8%94%E0%B9%89%E0%B8%99%E0%B8%B0";
- String message2 = "%E0%B8%81%E0%B9%89%E0%B8%AD%E0%B8%99%E0%B9%80%E0%B8%A1%E0%B8%86%E0%B8%9B%E0%B8%A3%E0%B8%B0%E0%B8%9B%E0%B8%A3%E0%B8%B2%E0%B8%A2%20%E0%B9%83%E0%B8%99%E0%B8%95%E0%B8%AD%E0%B8%99%E0%B9%80%E0%B8%8A%E0%B9%89%E0%B8%B2%E0%B8%96%E0%B9%89%E0%B8%B2%E0%B8%81%E0%B8%A5%E0%B8%B1%E0%B8%A7%E0%B9%81%E0%B8%94%E0%B8%94%E0%B8%81%E0%B9%87%E0%B8%9E%E0%B8%81%E0%B8%A3%E0%B9%88%E0%B8%A1%E0%B9%84%E0%B8%9B%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2";
- String message3 = "%E0%B8%81%E0%B9%89%E0%B8%AD%E0%B8%99%E0%B9%80%E0%B8%A1%E0%B8%86%E0%B8%A1%E0%B8%B5%E0%B8%AA%E0%B8%B5%E0%B8%84%E0%B8%A5%E0%B9%89%E0%B8%B3%20%E0%B8%9D%E0%B8%99%E0%B8%AD%E0%B8%B2%E0%B8%88%E0%B8%88%E0%B8%B0%E0%B8%95%E0%B8%81%E0%B8%84%E0%B8%A7%E0%B8%A3%E0%B8%95%E0%B8%B4%E0%B8%94%E0%B8%A3%E0%B9%88%E0%B8%A1%E0%B9%84%E0%B8%9B%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B8%81%E0%B9%87%E0%B8%94%E0%B8%B5%E0%B8%99%E0%B8%B0";
- String message4 = "%E0%B9%80%E0%B8%A1%E0%B8%86%E0%B8%A1%E0%B8%B7%E0%B8%94%E0%B8%84%E0%B8%A3%E0%B8%B6%E0%B9%89%E0%B8%A1%20%E0%B9%83%E0%B8%AB%E0%B9%89%E0%B8%84%E0%B8%B2%E0%B8%94%E0%B8%A7%E0%B9%88%E0%B8%B2%E0%B8%9D%E0%B8%99%E0%B8%95%E0%B8%81%E0%B9%81%E0%B8%99%E0%B9%88%E0%B8%99%E0%B8%AD%E0%B8%99%20%E0%B8%95%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%95%E0%B8%B4%E0%B8%94%E0%B8%A3%E0%B9%88%E0%B8%A1%E0%B9%84%E0%B8%9B%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B8%99%E0%B8%B0";
- String message5 = "%E0%B8%9D%E0%B8%99%E0%B8%95%E0%B8%81%E0%B8%9B%E0%B8%A3%E0%B8%AD%E0%B8%A2%E0%B9%86%20%E0%B8%AD%E0%B8%A2%E0%B9%88%E0%B8%B2%E0%B8%A5%E0%B8%B7%E0%B8%A1%E0%B9%80%E0%B8%AD%E0%B8%B2%E0%B8%A3%E0%B9%88%E0%B8%A1%E0%B9%84%E0%B8%9B%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B8%99%E0%B8%B0";
- String message6 = "%E0%B8%9D%E0%B8%99%E0%B8%95%E0%B8%81%E0%B8%9B%E0%B8%B2%E0%B8%99%E0%B8%81%E0%B8%A5%E0%B8%B2%E0%B8%87%20%E0%B9%80%E0%B8%AD%E0%B8%B2%E0%B8%A3%E0%B9%88%E0%B8%A1%E0%B9%84%E0%B8%9B%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B8%99%E0%B8%B0";
- String message7 = "%E0%B8%9D%E0%B8%99%E0%B8%95%E0%B8%81%E0%B9%81%E0%B8%99%E0%B9%88%E0%B8%99%E0%B8%AD%E0%B8%99%20%E0%B8%95%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B9%80%E0%B8%AD%E0%B8%B2%E0%B8%A3%E0%B9%88%E0%B8%A1%E0%B9%84%E0%B8%9B%E0%B8%99%E0%B8%B0%20%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99%E0%B8%AB%E0%B9%88%E0%B8%A7%E0%B8%87";
- LiquidCrystal lcd(D6, D5, D4, D3, D2, D1); //ฟังก์ชั่นแรกกำหนดPins ที่ใช้ในการเชื่อมต่อ
- WiFiServer server(SERVER_PORT); //เปิดใช้งาน TCP Port 80
- WiFiClient client; //ประกาศ WiFiClient client
- char auth[] = "0aba9c3e70804ef7afb41a9ff816beeb"; // รหัส app Blynk
- const char* server_ip = "api.openweathermap.org"; //กำหนดชื่อ Server ที่ต้องการเชื่อมต่อ
- const long interval = 30000; //กำหนดค่าตัวแปร ให้ทำงานทุกๆ 30 วินาที
- unsigned long previousMillis = 0; //กำหนดตัวแปรเก็บค่า เวลาสุดท้ายที่ทำงาน
- unsigned long timer0 = 0 ; // กำหนด timer0 = 0
- unsigned long timer1 = 0 ; // กำหนด timer0 = 1
- void setup()
- {
- lcd.begin(16, 2); // ให้ LCD เริ่มทำงาน
- Serial.begin(115200); // กำหนดความเร็วให้รับส่ง-ข้อมูลความเร็ว 115200
- Blynk.begin(auth, "PHONE2541", "0812393668"); // ใส่รหัส Blynk และรหัส WiFi
- lcd.print("Welcome"); // แสดงผล Welcome ใน จอ LCD
- lcd.setCursor(0, 1); // ให้แสดงผลที่ บรรทัดที่ 1
- lcd.print("My Project"); // แสดงผล My Project
- }
- BLYNK_WRITE(V0)
- {
- Serial.println(param.asStr()); // ให้แสดงค่า ที่พิมพ์ใน Blynk ออก Serail Monitor
- Value = param.asStr(); // กำหนดให้ Value = param.asStr
- delay(200); // Delay 200
- }
- void loop()
- {
- Blynk.run(); // สั่งให้ Blynk ทำงาน
- city = Value ; // กำหนดให้ city = Value
- Weather_display();
- unsigned long currentMillis = millis(); //อ่านค่าเวลาที่ ESP เริ่มทำงานจนถึงเวลาปัจจุบัน
- if (currentMillis - previousMillis >= interval) //ถ้าหากเวลาปัจจุบันลบกับเวลาก่อหน้านี้ มีค่า มากกว่าค่า interval ให้คำสั่งภายใน if ทำงาน
- {
- previousMillis = currentMillis; //ให้เวลาปัจจุบัน เท่ากับ เวลาก่อนหน้าเพื่อใช้คำนวณเงื่อนไขในรอบถัดไป
- Client_Request(); //เรียกใช้ฟังก์ชันClient_Request
- }
- }
- void Weather_display()
- {
- while (client.available()) //ตรวจเช็คว่ามีการส่งค่ากลับมาจาก Server หรือไม่
- {
- String line = client.readStringUntil('\n'); //อ่านค่าที่ Server ตอบกลับมาทีละบรรทัด
- String get_data = cut_string(line, "city", "name"); //ตัด string ข้อมูลส่วนชื่อจังหวัด
- if (get_data != "NULL") // ถ้า get_data ไม่เท่ากับ ค่าว่างเปล่า ให้คำสั่งภายใน if ทำงาน
- {
- Serial.println("City"); // ให้แสดง City ใน Serial Monitor
- Serial.println(get_data); // ให้แสดงค่า get_data ใน Serial Monitor
- lcd.clear(); // clear LCD
- lcd.print(get_data); // แสดงค่า get_data ในจอ LCD
- }
- get_data = cut_string(line, "weather", "value"); //ตัด string ข้อมูลส่วน ความดัน
- if (get_data != "NULL") // ถ้า get_data ไม่เท่ากับ ค่าว่างเปล่า ให้คำสั่งภายใน if ทำงาน
- {
- Serial.println("Weather"); // ให้แสดง Weather ใน Serial Monitor
- Serial.println(get_data); // ให้แสดงค่า get_data ใน Serial Monitor
- lcd.setCursor(0, 1); // ให้แสดงในบรรทัดที่ 1 จอ LCD
- lcd.print(get_data); // แสดงค่า get_data ในจอ LCD
- if (get_data == "few clouds") // ถ้า get_data ท่ากับ few clouds ให้คำสั่งภายใน if ทำงาน
- {
- Serial.println("Weather"); // ให้แสดง Weather ใน Serial Monitor
- Serial.println(get_data); // ให้แสดงค่า get_data ใน Serial Monitor
- lcd.setCursor(0, 1); // ให้แสดงในบรรทัดที่ 1 จอ LCD
- lcd.print(get_data); // แสดงค่า get_data ในจอ LCD
- Line_Notify1(message1); // เรียกใช้ฟังก์ชัน Line_Notify1
- }
- if (get_data == "scattered clouds") // ถ้า get_data ท่ากับ scattered clouds ให้คำสั่งภายใน if ทำงาน
- {
- Serial.println("Weather"); // ให้แสดง Weather ใน Serial Monitor
- Serial.println(get_data); // ให้แสดงค่า get_data ใน Serial Monitor
- lcd.setCursor(0, 1); // ให้แสดงในบรรทัดที่ 1 จอ LCD
- lcd.print(get_data); // แสดงค่า get_data ในจอ LCD
- Line_Notify2(message2); // เรียกใช้ฟังก์ชัน Line_Notify2
- }
- if (get_data == "broken clouds") // ถ้า get_data ท่ากับ broken clouds ให้คำสั่งภายใน if ทำงาน
- {
- Serial.println("Weather"); // ให้แสดงค่า get_data ใน Serial Monitor
- Serial.println(get_data); // ให้แสดงค่า get_data ใน Serial Monitor
- lcd.setCursor(0, 1); // ให้แสดงในบรรทัดที่ 1 จอ LCD
- lcd.print(get_data); // แสดงค่า get_data ในจอ LCD
- Line_Notify3(message3); // เรียกใช้ฟังก์ชัน Line_Notify3
- }
- if (get_data == "overcast clouds") // ถ้า get_data ท่ากับ overcast clouds ให้คำสั่งภายใน if ทำงาน
- {
- Serial.println("Weather"); // ให้แสดง Weather ใน Serial Monitor
- Serial.println(get_data); // ให้แสดงค่า get_data ใน Serial Monitor
- lcd.setCursor(0, 1); // ให้แสดงในบรรทัดที่ 1 จอ LCD
- lcd.print(get_data); // แสดงค่า get_data ในจอ LCD
- Line_Notify4(message4); // เรียกใช้ฟังก์ชัน Line_Notify4
- }
- if (get_data == "light rain") // ถ้า get_data ท่ากับ light rain ให้คำสั่งภายใน if ทำงาน
- {
- Serial.println("Weather"); // ให้แสดง Weather ใน Serial Monitor
- Serial.println(get_data); // ให้แสดงค่า get_data ใน Serial Monitor
- lcd.setCursor(0, 1); // ให้แสดงในบรรทัดที่ 1 จอ LCD
- lcd.print(get_data); // แสดงค่า get_data ในจอ LCD
- Line_Notify5(message5); // เรียกใช้ฟังก์ชัน Line_Notify5
- }
- if (get_data == "moderate rain") // ถ้า get_data ท่ากับ moderate rain ให้คำสั่งภายใน if ทำงาน
- {
- Serial.println("Weather"); // ให้แสดง Weather ใน Serial Monitor
- Serial.println(get_data); // ให้แสดงค่า get_data ใน Serial Monitor
- lcd.setCursor(0, 1); // ให้แสดงในบรรทัดที่ 1 จอ LCD
- lcd.print(get_data); // แสดงค่า get_data ในจอ LCD
- Line_Notify6(message6); // เรียกใช้ฟังก์ชัน Line_Notify6
- }
- if (get_data == "heavy intensity rain") // ถ้า get_data ท่ากับ heavy intensity rain ให้คำสั่งภายใน if ทำงาน
- {
- Serial.println("Weather"); // ให้แสดง Weather ใน Serial Monitor
- Serial.println(get_data); // ให้แสดงค่า get_data ใน Serial Monitor
- lcd.setCursor(0, 1); // ให้แสดงในบรรทัดที่ 1 จอ LCD
- lcd.print("heavy rain"); // แสดงค่า get_data ในจอ LCD
- Line_Notify7(message7); // เรียกใช้ฟังก์ชัน Line_Notify7
- }
- if (get_data == "light intensity shower rain") // ถ้า get_data ท่ากับ light intensity shower rain ให้คำสั่งภายใน if ทำงาน
- {
- Serial.println("Weather"); // ให้แสดง Weather ใน Serial Monitor
- Serial.println(get_data); // ให้แสดงค่า get_data ใน Serial Monitor
- lcd.setCursor(0, 1); // ให้แสดงในบรรทัดที่ 1 จอ LCD
- lcd.print("shower rain"); // แสดงค่า get_data ในจอ LCD
- Line_Notify7(message7); // เรียกใช้ฟังก์ชัน Line_Notify7
- }
- }
- }
- }
- void Client_Request()
- {
- Serial.println("Connect TCP Server"); // ให้แสดง Connect TCP Server ใน Serial Monitor
- int cnt = 0; // ประกาศตัวแปร cnt = 0
- while (!client.connect(server_ip, SERVER_PORT)) // เชื่อมต่อกับ Server และรอจนกว่าเชื่อมต่อสำเร็จ
- {
- Serial.print("."); // แสดง . ใน Serial Monitor
- delay(100); // delay เวลา 100
- cnt++; // cnt = cnt + 1
- if (cnt > 50) // ถ้าหากใช้เวลาเชื่อมต่อเกิน 5 วินาที ให้ออกจาก ฟังก์ชั่น
- return; // return กลับไป
- }
- Serial.println("Success"); // แสดง Success ใน Serial Monitor
- delay(500); // delay เวลา 500
- client.print(str_get1 + city + str_get2 + str_host); // ส่งคำสั่ง HTTP GET ไปยัง Server
- Serial.print(str_get1 + city + str_get2 + str_host); // แสดงค่าคำสั่ง HTTP GET ไปยัง Server ใน Serial Monitor
- delay(100); // delay เวลา 100
- }
- String cut_string(String input, String header, String get_string) // ประกาศตัวแปร cut_string มี Array ที่ประกอบด้วย input header get_string
- {
- if (input.indexOf(header) != -1) //ตรวจสอบว่าใน input มีข้อความเหมือนใน header หรือไม่
- {
- int num_get = input.indexOf(get_string, input.indexOf(header)); //หาตำแหน่งของข้อความ get_string ใน input
- if (num_get != -1) //ตรวจสอบว่าตำแหน่งที่ได้ไม่ใช่ -1 (ไม่มีข้อความ get_string ใน input)
- {
- int start_val = input.indexOf("\"", num_get) + 1; // หาตำแหน่งแรกของ “
- int stop_val = input.indexOf("\"", start_val); // หาตำแหน่งสุดท้ายของ “
- return (input.substring(start_val, stop_val)); //ตัดเอาข้อความระหว่า “แรก และ ”สุดท้าย
- }
- else // ถ้าเงื่อนไขไม่ตรงให้ทำในคำสั่ง else
- {
- return ("NULL"); //Return ข้อความ NULL เมื่อไม่ตรงเงื่อนไข
- }
- }
- return ("NULL"); //Return ข้อความ NULL เมื่อไม่ตรงเงื่อนไข
- }
- void Line_Notify1(String message1)
- {
- digitalWrite(D7,HIGH);
- WiFiClientSecure client; // ประกาศ WiFiClientSecure client
- if (!client.connect("notify-api.line.me", 443)) // ถ้าเชื่อมต่อไม่ได้ให้ไปทำงานในฟังก์ชัน
- {
- Serial.println("connection failed"); // แสดงค่า connection failedconnection ใน Serial Monitor
- return; //Return กลับไป
- }
- String req = ""; // ประกาศตัวแปร req
- req += "POST /api/notify HTTP/1.1\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Host: notify-api.line.me\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Authorization: Bearer " + String(LINE_TOKEN) + "\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Cache-Control: no-cache\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "User-Agent: ESP8266\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Connection: close\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Content-Type: application/x-www-form-urlencoded\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Content-Length: " + String(String("message=" + message1).length()) + "\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "message=" + message1; // req ก่อนหน้านี้มาบวกประโยคกัน
- client.print(req); // ส่งข้อความ req ผ่าน Serial Monitor
- delay(20); // Delay เวลา 20
- while (client.connected()) // ถ้า client.connected ให้ทำงานใน while ถ้าไม่ ออกนอก while
- {
- String line = client.readStringUntil('\n'); // ประกาศตัวแปร line = client.readStringUntil
- if (line == "\r") // ถ้า line = เริ่มบรรทัดหม่ ให้ทำงานใน if
- digitalWrite(D7,HIGH);
- {
- break; // หยุด
- }
- }
- }
- void Line_Notify2(String message2)
- {
- digitalWrite(D7,HIGH);
- WiFiClientSecure client; // ประกาศ WiFiClientSecure client
- if (!client.connect("notify-api.line.me", 443)) // ถ้าเชื่อมต่อไม่ได้ให้ไปทำงานในฟังก์ชัน
- {
- Serial.println("connection failed"); // แสดงค่า connection failedconnection ใน Serial Monitor
- return; //Return กลับไป
- }
- String req = ""; // ประกาศตัวแปร req
- req += "POST /api/notify HTTP/1.1\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Host: notify-api.line.me\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Authorization: Bearer " + String(LINE_TOKEN) + "\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Cache-Control: no-cache\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "User-Agent: ESP8266\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Connection: close\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Content-Type: application/x-www-form-urlencoded\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Content-Length: " + String(String("message=" + message2).length()) + "\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "message=" + message2; // req ก่อนหน้านี้มาบวกประโยคกัน
- client.print(req); // ส่งข้อความ req ผ่าน Serial Monitor
- delay(20); // Delay เวลา 20
- while (client.connected()) // ถ้า client.connected ให้ทำงานใน while ถ้าไม่ ออกนอก while
- {
- String line = client.readStringUntil('\n'); // ประกาศตัวแปร line = client.readStringUntil
- if (line == "\r") // ถ้า line = เริ่มบรรทัดหม่ ให้ทำงานใน if
- digitalWrite(D7,HIGH);
- {
- break; // หยุดแล้วออกคำสั่ง
- }
- }
- }
- void Line_Notify3(String message3)
- {
- digitalWrite(D7,HIGH);
- WiFiClientSecure client; // ประกาศ WiFiClientSecure client
- if (!client.connect("notify-api.line.me", 443)) // ถ้าเชื่อมต่อไม่ได้ให้ไปทำงานในฟังก์ชัน
- {
- Serial.println("connection failed"); // แสดงค่า connection failedconnection ใน Serial Monitor
- return; //Return กลับไป
- }
- String req = ""; // ประกาศตัวแปร req
- req += "POST /api/notify HTTP/1.1\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Host: notify-api.line.me\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Authorization: Bearer " + String(LINE_TOKEN) + "\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Cache-Control: no-cache\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "User-Agent: ESP8266\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Connection: close\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Content-Type: application/x-www-form-urlencoded\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "Content-Length: " + String(String("message=" + message3).length()) + "\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "\r\n"; // req ก่อนหน้านี้มาบวกประโยคกัน
- req += "message=" + message3; // req ก่อนหน้านี้มาบวกประโยคกัน
- client.print(req); // ส่งข้อความ req ผ่าน Serial Monitor
- delay(20); // Delay เวลา 20
- while (client.connected()) // ถ้า client.connected ให้ทำงานใน while ถ้าไม่ ออกนอก while
- {
- String line = client.readStringUntil('\n'); // ประกาศตัวแปร line = client.readStringUntil
- if (line == "\r") // ถ้า line = เริ่มบรรทัดหม่ ให้ทำงานใน if
- {
- break; // หยุดแล้วออกคำสั่ง
- }
- }
- }
- void Line_Notify4(String message4)
- {
- digitalWrite(D7,HIGH);
- WiFiClientSecure client; // ประกาศ WiFiClientSecure client
- if (!client.connect("notify-api.line.me", 443)) // ถ้าเชื่อมต่อไม่ได้ให้ไปทำงานในฟังก์ชัน
- {
- Serial.println("connection failed"); // แสดงค่า connection failedconnection ใน Serial Monitor
- return; //Return กลับไป
- }
- String req = ""; // ประกาศตัวแปร req
- req += "POST /api/notify HTTP/1.1\r\n"; // ประกาศตัวแปร req
- req += "Host: notify-api.line.me\r\n"; // ประกาศตัวแปร req
- req += "Authorization: Bearer " + String(LINE_TOKEN) + "\r\n"; // ประกาศตัวแปร req
- req += "Cache-Control: no-cache\r\n"; // ประกาศตัวแปร req
- req += "User-Agent: ESP8266\r\n"; // ประกาศตัวแปร req
- req += "Connection: close\r\n"; // ประกาศตัวแปร req
- req += "Content-Type: application/x-www-form-urlencoded\r\n"; // ประกาศตัวแปร req
- req += "Content-Length: " + String(String("message=" + message4).length()) + "\r\n"; // ประกาศตัวแปร req
- req += "\r\n"; // ประกาศตัวแปร req
- req += "message=" + message4; // ประกาศตัวแปร req
- client.print(req); // ส่งข้อความ req ผ่าน Serial Monitor
- delay(20); // Delay เวลา 20
- while (client.connected()) // ถ้า client.connected ให้ทำงานใน while ถ้าไม่ ออกนอก while
- {
- String line = client.readStringUntil('\n'); // ประกาศตัวแปร line = client.readStringUntil
- if (line == "\r") // ถ้า line = เริ่มบรรทัดหม่ ให้ทำงานใน if
- {
- break; // หยุดแล้วออกคำสั่ง
- }
- }
- }
- void Line_Notify5(String message5)
- {
- digitalWrite(D7,HIGH);
- WiFiClientSecure client; // ประกาศ WiFiClientSecure client
- if (!client.connect("notify-api.line.me", 443)) // ถ้าเชื่อมต่อไม่ได้ให้ไปทำงานในฟังก์ชัน
- {
- Serial.println("connection failed"); // แสดงค่า connection failedconnection ใน Serial Monitor
- return; //Return กลับไป
- }
- String req = ""; // ประกาศตัวแปร req
- req += "POST /api/notify HTTP/1.1\r\n"; // ประกาศตัวแปร req
- req += "Host: notify-api.line.me\r\n"; // ประกาศตัวแปร req
- req += "Authorization: Bearer " + String(LINE_TOKEN) + "\r\n"; // ประกาศตัวแปร req
- req += "Cache-Control: no-cache\r\n"; // ประกาศตัวแปร req
- req += "User-Agent: ESP8266\r\n"; // ประกาศตัวแปร req
- req += "Connection: close\r\n"; // ประกาศตัวแปร req
- req += "Content-Type: application/x-www-form-urlencoded\r\n"; // ประกาศตัวแปร req
- req += "Content-Length: " + String(String("message=" + message5).length()) + "\r\n"; // ประกาศตัวแปร req
- req += "\r\n"; // ประกาศตัวแปร req
- req += "message=" + message5; // ประกาศตัวแปร req
- client.print(req); // ส่งข้อความ req ผ่าน Serial Monitor
- delay(20); // Delay เวลา
- while (client.connected()) // ถ้า client.connected ให้ทำงานใน while ถ้าไม่ ออกนอก while
- {
- String line = client.readStringUntil('\n'); // ประกาศตัวแปร line = client.readStringUntil
- if (line == "\r") // ถ้า line = เริ่มบรรทัดหม่ ให้ทำงานใน if
- {
- break; // หยุดแล้วออกคำสั่ง
- }
- }
- }
- void Line_Notify6(String message6)
- {
- digitalWrite(D7,HIGH);
- WiFiClientSecure client; // ประกาศ WiFiClientSecure client
- if (!client.connect("notify-api.line.me", 443)) // ถ้าเชื่อมต่อไม่ได้ให้ไปทำงานในฟังก์ชัน
- {
- Serial.println("connection failed"); // แสดงค่า connection failedconnection ใน Serial Monitor
- return; //Return กลับไป
- }
- String req = ""; // ประกาศตัวแปร req
- req += "POST /api/notify HTTP/1.1\r\n"; // ประกาศตัวแปร req
- req += "Host: notify-api.line.me\r\n"; // ประกาศตัวแปร req
- req += "Authorization: Bearer " + String(LINE_TOKEN) + "\r\n"; // ประกาศตัวแปร req
- req += "Cache-Control: no-cache\r\n"; // ประกาศตัวแปร req
- req += "User-Agent: ESP8266\r\n"; // ประกาศตัวแปร req
- req += "Connection: close\r\n"; // ประกาศตัวแปร req
- req += "Content-Type: application/x-www-form-urlencoded\r\n"; // ประกาศตัวแปร req
- req += "Content-Length: " + String(String("message=" + message6).length()) + "\r\n"; // ประกาศตัวแปร req
- req += "\r\n"; // ประกาศตัวแปร req
- req += "message=" + message6; // ประกาศตัวแปร req
- client.print(req); // ส่งข้อความ req ผ่าน Serial Monitor
- delay(20); // Delay เวลา
- while (client.connected()) // ถ้า client.connected ให้ทำงานใน while ถ้าไม่ ออกนอก while
- {
- String line = client.readStringUntil('\n'); // ประกาศตัวแปร line = client.readStringUntil
- if (line == "\r") // ถ้า line = เริ่มบรรทัดหม่ ให้ทำงานใน if
- {
- break; // หยุดแล้วออกคำสั่ง
- }
- }
- }
- void Line_Notify7(String message7)
- {
- digitalWrite(D7,HIGH);
- WiFiClientSecure client; // ประกาศ WiFiClientSecure client
- if (!client.connect("notify-api.line.me", 443)) // ถ้าเชื่อมต่อไม่ได้ให้ไปทำงานในฟังก์ชัน
- {
- Serial.println("connection failed"); // แสดงค่า connection failedconnection ใน Serial Monitor
- return; //Return กลับไป
- }
- String req = ""; // ประกาศตัวแปร req
- req += "POST /api/notify HTTP/1.1\r\n"; // ประกาศตัวแปร req
- req += "Host: notify-api.line.me\r\n"; // ประกาศตัวแปร req
- req += "Authorization: Bearer " + String(LINE_TOKEN) + "\r\n"; // ประกาศตัวแปร req
- req += "Cache-Control: no-cache\r\n"; // ประกาศตัวแปร req
- req += "User-Agent: ESP8266\r\n"; // ประกาศตัวแปร req
- req += "Connection: close\r\n"; // ประกาศตัวแปร req
- req += "Content-Type: application/x-www-form-urlencoded\r\n"; // ประกาศตัวแปร req
- req += "Content-Length: " + String(String("message=" + message7).length()) + "\r\n"; // ประกาศตัวแปร req
- req += "\r\n"; // ประกาศตัวแปร req
- req += "message=" + message7; // ประกาศตัวแปร req
- client.print(req); // ส่งข้อความ req ผ่าน Serial Monitor
- delay(20); // Delay เวลา
- while (client.connected()) // ถ้า client.connected ให้ทำงานใน while ถ้าไม่ ออกนอก while
- {
- String line = client.readStringUntil('\n'); // ประกาศตัวแปร line = client.readStringUntil
- if (line == "\r") // ถ้า line = เริ่มบรรทัดหม่ ให้ทำงานใน if
- {
- break; // หยุดแล้วออกคำสั่ง
- }
- }
- }
Add Comment
Please, Sign In to add comment