การประยุกต์ใช้ node-red กบัระบบ...

35
การประยุกต์ใช้ Node-Red กับระบบ IoT WUNCA 39th Burapha University

Upload: others

Post on 19-Jun-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

การประยกุตใ์ช ้Node-Red กบัระบบ IoTWUNCA 39th

Burapha University

Page 2: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

Outline

• Introducing MQTT

• Installing MQTT Broker

• MQTT Project

• Introduction and Review of Node RED

• Useful Node RED nodes

• Installing Node RED and Node RED Dashboard

• Connect IoT Device to Node RED using MQTT

• Line Notify/ Email/ Twitter with Node RED

Page 3: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

Introducing MQTT

• MQTT — (Message Queuing Telemetry Transport) MQ Telemetry Transport

• MQTT is a lightweight publish/subscribe messaging protocol. It is useful for use with low power sensors, but is applicable to many scenarios.

• MQTT version v5.0 and v3.1.1, Information on MQTT, see http://mqtt.org/.

Page 4: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

MQTT

• MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.

• MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.

Page 5: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

MQTT

• Lightweight IoT ProtocolPublish

Subscribe

Simple communication between multiple devices

Simple messaging protocol

Page 6: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

MQTT Basic Concepts

• Publish/Subscribe

• Messages

• Topics

• Broker

Page 7: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

MQTT – Publish/Subscribe

• In a publish and subscribe system, a device can publish a message on a topic, or it can be subscribed to a particular topic to receive messages

Page 8: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

MQTT – Messages

• Messages are the information that you want to exchange between your devices. Whether it’s a command or data.

Page 9: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

MQTT – Topics

• Topics are the way you register interest for incoming messages or how you specify where you want to publish the message.

• Topics are represented with strings separated by a forward slash. Each forward slash indicates a topic level.

Page 10: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

MQTT – Broker

• The broker is primarily responsible for receiving all messages, filtering the messages, decide who is interested in them and then publishing the message to all subscribed clients.

• https://mosquitto.org/

Page 11: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

MQTT

• https://www.hivemq.com/blog/how-to-get-started-with-mqtt/

Page 12: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

MQTT

Broker

Publish

Subscribe

Pu

blish

Sub

scribe

Page 13: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED
Page 14: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

Public MQTT Broker

• https://test.mosquitto.org/

• https://iot.eclipse.org/getting-started/#sandboxes

• https://www.hivemq.com/public-mqtt-broker/

• https://www.cloudmqtt.com/

• https://netpie.io/ (MQTT in Microgear Library)

Page 15: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

MQTT Brokers/Servers

• Mosquitto https://mosquitto.org/

• Mosca https://github.com/mcollina/mosca

• Emqttd https://github.com/emqtt/emqttd

• Python Test Broker https://github.com/eclipse/paho.mqtt.testing/tree/master/interoperability

Page 16: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

Installing MQTT Broker

• Mosquitto https://mosquitto.org/download/

• สามารถติดตัง้ได้ทัง้ Windows, Mac, Linux

• Linux ท่ีนิยมน ามาติดตัง้ เช่น Debian, Raspbian on Raspberry Pi, Ubuntu

• Workshop จะติดตัง้ Mosquitto บน Ubuntu Server เพื่อท าการทดสอบ

Page 17: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

• เอกสารการติดตัง้ คือ “1_การติดตัง้MQTT_MosquittoBrokerLinux”

Page 18: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

MQTT ProjectMQTT

Mosquittobroker

Publish

Subscribe

Pu

blish

Sub

scribe

Page 19: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

send a command to control an output

MQTT broker

MQTT MQTT

Page 20: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

read data from a sensor and publish it

MQTT broker

MQTT MQTT

Page 21: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

MQTT Project Parts Required

• Mosquitto Broker on Ubuntu Server

• 1xESP32

• 1xDHT11

• 1x 5mm LED

• 1x 330 Ohm resistor

• Breadboard

• Jumper wires

Page 22: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

ติดตั้ง ESP32 หรือ ESP8266 พร้อม Sensor เพื่อทดสอบ

Page 23: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

• เอกสารการติดตัง้ คือ “2_Basic_Esp_Dht_ArduinoIDE”

• และเอกสาร “3_ทดสอบESP32_MQTT”

Page 24: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

Introduction and Review of Node-RED

• Flow-based programming for the Internet of Things

• Latest version: v0.20.6 (npm)

• Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.

• It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.

Page 25: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED
Page 26: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

Node-RED

• Node-RED เป็นซอฟต์แวร์โอเพ็นซอส เป็นเคร่ืองมือส าหรับพฒันาโปรแกรมในการเช่ือมตอ่อปุกรณ์ฮาร์ดแวร์เข้ากบั APIsและ Service ไมต้่องเขียน API Server เอง

• Node-RED เป็นโปรแกรมแบบ Flow-Based Programming สามารถออกแบบ API ในการรับคา่ ค านวณ แปลงข้อมลู เก็บข้อมลู หรือเช่ือมตอ่กบับริการอ่ืน ๆ

• Node-RED เป็น Browser-based Flow Editor

• ท าให้ Node เช่ือมตอ่ ควบคมุ input /output ตา่ง ๆ ได้

• Node-RED มี Node ให้เลือกใช้งานเพ่ือท าให้เกิด Flow แล้วก าหนดค่าการท างาน จากนัน้ก็สามารถเช่ือมตอ่เช่ือมโยงข้อมลูโดยท่ีไมต้่อง Code

Page 27: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

Useful Node RED nodes

• Node-RED is open source and developed by IBM

• The Raspberry Pi and Other Platform runs Node-RED perfectly.

• Access your RPi GPIOs

• Establish an MQTT connection with other boards (Arduino, ESP8266, etc)

• Create a responsive graphical user interface for your projects

• Communicate with third-party services (IFTTT.com, Adafruit.io, Thing Speak, etc)

• Retrieve data from the web (weather forecast, stock prices, emails. etc)

• Store and retrieve data from a database

Page 28: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

Useful Node RED nodes

• การใช้งาน Node-RED คูก่บั NETPIE

• https://netpie.gitbooks.io/node-red/content/

Page 29: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

Installing Node RED and Node RED Dashboard

• เอกสารการติดตัง้ คือ “4_การติดตัง้Node-Red_Ubuntu”

Page 30: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

Node-RED Overview

• http://YOUR_RPi_IP_ADDRESS:1880

Page 31: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED
Page 32: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

• Creating a Simple Flow (ดเูอกสาร Lab_Node-RED_Overview)

• การควบคมุ LED บน RaspberryPI ด้วย Node-RED

• ดเูอกสาร “5_Node-RED_Overview”

Page 33: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

Connect IoT Device to Node RED using MQTT

• เอกสาร

• “6_ทดสอบESP_MQTT_NodeRed”

Page 34: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED

Line Notify/ Email/ Twitter with Node RED

• เอกสาร

• “7_ทดสอบEmailด้วยNodeRed”

• “8_ทดสอบLineNortifyNodeRed”

• “9_ทดสอบTwitterNodeRed”

Page 35: การประยุกต์ใช้ Node-Red กบัระบบ IoTwunca.uni.net.th/wunca_regis/wunca39_doc/28/009-BUU-IoT-WUNCA… · •Installing Node RED and Node RED