NodeMCU ESP8266 สัปดาห์ที่ 1
NodeMCU ESP8266 ส่งค่าความชื้นและอุณหภูมิ DHT11 แจ้งเตือนผ่าน LINE
| #include <TridentTD_LineNotify.h> | |
| #define SSID "MY2G" // บรรทัดที่ 11 ให้ใส่ ชื่อ Wifi ที่จะเชื่อมต่อ | |
| #define PASSWORD "927566556" // บรรทัดที่ 12 ใส่ รหัส Wifi | |
| #define LINE_TOKEN "gdevxvWWVOURNrnMoT9fc8s5PCBxIp70a4UWZkj" // บรรทัดที่ 13 ใส่ รหัส 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) { | |
| String LineText; | |
| String string1 = "อุณหภูมิ เกินกำหนด "; | |
| String string2 = " °C"; | |
| LineText = string1 + t + string2; | |
| Serial.print("Line "); | |
| Serial.println(LineText); | |
| LINE.notify(LineText); | |
| } | |
| } |
ใช้งาน NodeMCU ESP8266 ส่งค่า อุณหภูมิ และความชื้น Sensor DHT11 แจ้งเตือนผ่าน Line เมื่ออุณหภูมิเกินค่าที่กำหนด
LINE Notify เป็นบริการของ LINE ที่ทำให้เราสามารถส่งข้อความหาผู้ที่ขอใช้ หรือกลุ่มที่ผู้ขอใช้เป็นสมาชิก โดยผ่าน API ทาง HTTP POST
ลิ้งเว็บ
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
ความคิดเห็น
แสดงความคิดเห็น