Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
การประยกุตใ์ช ้Node-Red กบัระบบ IoTWUNCA 39th
Burapha University
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
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/.
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.
MQTT
• Lightweight IoT ProtocolPublish
Subscribe
Simple communication between multiple devices
Simple messaging protocol
MQTT Basic Concepts
• Publish/Subscribe
• Messages
• Topics
• Broker
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
MQTT – Messages
• Messages are the information that you want to exchange between your devices. Whether it’s a command or data.
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.
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/
MQTT
• https://www.hivemq.com/blog/how-to-get-started-with-mqtt/
MQTT
Broker
Publish
Subscribe
Pu
blish
Sub
scribe
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)
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
Installing MQTT Broker
• Mosquitto https://mosquitto.org/download/
• สามารถติดตัง้ได้ทัง้ Windows, Mac, Linux
• Linux ท่ีนิยมน ามาติดตัง้ เช่น Debian, Raspbian on Raspberry Pi, Ubuntu
• Workshop จะติดตัง้ Mosquitto บน Ubuntu Server เพื่อท าการทดสอบ
• เอกสารการติดตัง้ คือ “1_การติดตัง้MQTT_MosquittoBrokerLinux”
MQTT ProjectMQTT
Mosquittobroker
Publish
Subscribe
Pu
blish
Sub
scribe
send a command to control an output
MQTT broker
MQTT MQTT
read data from a sensor and publish it
MQTT broker
MQTT MQTT
MQTT Project Parts Required
• Mosquitto Broker on Ubuntu Server
• 1xESP32
• 1xDHT11
• 1x 5mm LED
• 1x 330 Ohm resistor
• Breadboard
• Jumper wires
ติดตั้ง ESP32 หรือ ESP8266 พร้อม Sensor เพื่อทดสอบ
• เอกสารการติดตัง้ คือ “2_Basic_Esp_Dht_ArduinoIDE”
• และเอกสาร “3_ทดสอบESP32_MQTT”
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.
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
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
Useful Node RED nodes
• การใช้งาน Node-RED คูก่บั NETPIE
• https://netpie.gitbooks.io/node-red/content/
Installing Node RED and Node RED Dashboard
• เอกสารการติดตัง้ คือ “4_การติดตัง้Node-Red_Ubuntu”
Node-RED Overview
• http://YOUR_RPi_IP_ADDRESS:1880
• Creating a Simple Flow (ดเูอกสาร Lab_Node-RED_Overview)
• การควบคมุ LED บน RaspberryPI ด้วย Node-RED
• ดเูอกสาร “5_Node-RED_Overview”
Connect IoT Device to Node RED using MQTT
• เอกสาร
• “6_ทดสอบESP_MQTT_NodeRed”
Line Notify/ Email/ Twitter with Node RED
• เอกสาร
• “7_ทดสอบEmailด้วยNodeRed”
• “8_ทดสอบLineNortifyNodeRed”
• “9_ทดสอบTwitterNodeRed”