รับ Token line notify + code temp ส่งแจ้งเตือนผ่าน Application Line โดยใช้ Arduino IDE+NodeMCU+DHT22

IOT - Internet of things
ไอโอที (IoT) หมายถึงเครือข่ายของวัตถุ อุปกรณ์ พาหนะ สิ่งปลูกสร้าง และสิ่งของอื่นๆ ที่มีวงจรอิเล็กทรอนิกส์ ซอฟต์แวร์ เซ็นเซอร์ และการเชื่อมต่อกับเครือข่าย ฝังตัวอยู่ และทำให้วัตถุเหล่านั้นสามารถเก็บบันทึกและแลกเปลี่ยนข้อมูลได้

Moderator: mindphp, ผู้ดูแลกระดาน

Patipat
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 996
ลงทะเบียนเมื่อ: 10/06/2019 10:12 am

รับ Token line notify + code temp ส่งแจ้งเตือนผ่าน Application Line โดยใช้ Arduino IDE+NodeMCU+DHT22

โพสต์ที่ยังไม่ได้อ่าน โดย Patipat »

หากเราจะทำการเขียนโปรแกรม เพื่อแจ้งเตือนส่งไลน์ notificion ทำความรู้จักกับ notification ของไลน์ เราต้องมี Token TOKEN เหมือนเป็นรหัสโค๊ดอ้างอิงว่า ให้เราเชื่อมต่อกับ user นี้ เพื่อใช้โปรแกรมทำการแจ้งเตือนผ่านไลน์ และในการเขียนโปรแกรมต้องใช้ อุปกรณ์และ soft คือ Arduino IDE เป็นโปรแกรมสำหรับเขียนคำสั่งในการทำงาน อุปกรณ์หลักๆ ก็มี NodeMCU กับ Sensor DHT22 แล้วก็สายไฟเพื่อต่อกับ ตัวSensor และ บอร์ดแจ้งเตือนผ่านไลน์ดีอย่างไร ดีเพราะว่า ปัจจุบันสมัยนี้ เกือบทุกคนที่มี Smart Phone และ Intenet สามารถดูแจ้งเตือนผ่านไลน์โดยที่ไม่เสียค่าใช้จ่ายใด ๆ
ในวันนี้จะมาแนะนำในการเรียนโปรแกรมแสดงอุณภูมิแจ้งเตือนผ่าน Line Appliacation โดยใช้ NODE MCU และ DHT22


1. วิธีรับ token :arrow: GET TOKEN LINE

2. โหลด Libraries >> TridentTD_LineNotify ที่นี่ :arrow: Libraries TridentTD_LineNotify

3. ทำการติดตั้ง Libraries กดที่ sketch >> include Libraries >> Add.zip ตามรูป แล้วกด OK
Selection_977.png
4 . แล้วเช็ค Libraries ว่าเข้ามาหรือยัง วิธีเช็ค กด Sketch >> include libraries แล้ว เลื่อนดูว่า TridentTD_Linenotify เข้ามาหรือยัง
Menu_993.png
Menu_993.png (40.53 KiB) Viewed 3154 times
5. ลง Libraries ของ DHT22 เป็น Libraries ของ Sensord กด Sketch >> Include Libraries >> Manage Libraries แล้วพิม dht ตามภาพ หรือ โหลดได้ที่Libraries DHT22แล้วก็ทำการ Add.zip เหมือนติดตั้ง Libraries line
Selection_966.png
Selection_966.png (65.31 KiB) Viewed 3154 times
6. โค๊ดในการแสดงอุณภูมิแจ้งเตือนผ่านไลน์

โค้ด: เลือกทั้งหมด

#include <TridentTD_LineNotify.h>
#define SSID        "Wifi"      // บรรทัดที่ 11 ให้ใส่ ชื่อ Wifi ที่จะเชื่อมต่อ
#define PASSWORD    "0000000000"     // บรรทัดที่ 12 ใส่ รหัส Wifi
#define LINE_TOKEN  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"   //  ใส่ รหัส TOKEN ที่ได้มาจากไลน์
#include "DHT.h"
#define DHTPIN D1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
  dht.begin();
  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("myarduino.net");
}

void loop() {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));
  if (t > 40) {  // กำหนดว่า อุณภูมิเกิน 40 เมื่อไหร่ ให้แจ้งเตือนเข้าไลน์
    String LineText;
    String string1 = "อุณหภูมิ เกินกำหนด ";
    String string2 = " °C";
    LineText = string1 + t + string2;
    Serial.print("Line ");
    Serial.println(LineText);
    LINE.notify(LineText);
  }
}

7.การต่อวงจร
[list]V in ต่อกับ ขา +
GND ต่อกับ ขา -
ขา D1 ต่อกับ ขา Out[/list]


อ้างอิง : https://www.myarduino.net/article/126/%E0%B8%AA%E0%B8%AD%E0%B8%99%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-nodemcu-esp8266-%E0%B8%AA%E0%B9%88%E0%B8%87%E0%B8%84%E0%B9%88%E0%B8%B2%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%8A%E0%B8%B7%E0%B9%89%E0%B8%99%E0%B9%81%E0%B8%A5%E0%B8%B0%E0%B8%AD%E0%B8%B8%E0%B8%93%E0%B8%AB%E0%B8%A0%E0%B8%B9%E0%B8%A1%E0%B8%B4-dht11-%E0%B9%81%E0%B8%88%E0%B9%89%E0%B8%87%E0%B9%80%E0%B8%95%E0%B8%B7%E0%B8%AD%E0%B8%99%E0%B8%9C%E0%B9%88%E0%B8%B2%E0%B8%99-line


http://arduinoprojects.in.th/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-water-flow-sensor-%E0%B8%81%E0%B8%B1%E0%B8%9A-arduino/

https://www.9arduino.com/article/60/%E0%B8%95%E0%B8%B1%E0%B8%A7%E0%B8%AD%E0%B8%A2%E0%B9%88%E0%B8%B2%E0%B8%87-nodemcu-%E0%B8%94%E0%B8%B6%E0%B8%87%E0%B8%84%E0%B9%88%E0%B8%B2%E0%B8%95%E0%B8%B1%E0%B8%A7%E0%B9%81%E0%B8%9B%E0%B8%A3-json-%E0%B8%A1%E0%B8%B2%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99

https://www.ab.in.th/article/6/nodemcu-esp8266-%E0%B8%81%E0%B8%B1%E0%B8%9A%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%AA%E0%B9%88%E0%B8%87%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%81%E0%B8%88%E0%B9%89%E0%B8%87%E0%B9%80%E0%B8%95%E0%B8%B7%E0%B8%AD%E0%B8%99%E0%B9%80%E0%B8%82%E0%B9%89%E0%B8%B2-line-%E0%B8%AA%E0%B9%88%E0%B8%87%E0%B8%82%E0%B9%89%E0%B8%AD%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1-%E0%B8%A0%E0%B8%B2%E0%B8%9E-%E0%B9%81%E0%B8%A5%E0%B8%B0%E0%B8%AA%E0%B8%95%E0%B8%B4%E0%B8%81%E0%B9%80%E0%B8%81%E0%B8%AD%E0%B8%A3%E0%B9%8C
Kor ma di kub. :)
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 33