TM5022 T9 NodeRed2
TM5022 T9 NodeRed2
TM5022
Node-RED Part 2
Instructor : Louis Wong
Industrial Centre
The Hong Kong Polytechnic University
1
An IoT Framework
Logistics automation systems
Smart Middleware
Industry
http
SQL
Smart
Logistics
CoA
P
Smart
Warehous MQTT
2
Node RED
Ref: http://developers.sensetecnic.com/article/tutorial-connecting-device-node-red-to-cloud-node-red/
3
MQTT (Message Queuing Telemetry
Transport)
ISO standard (ISO/IEC PRF 20922)
Publish-subscribe-based messaging protocol
Designed for connections with remote locations
where a "small code footprint" is required or the
network bandwidth is limited
Applications
Amazon Web Services announced Amazon IoT based on
MQTT in 2015
McAfee OpenDXL is based on MQTT with enhancements
to the messaging brokers
Microsoft Azure IoT Hub uses MQTT as its main protocol
for telemetry messages
Node-RED supports MQTT nodes
Ref: https://en.wikipedia.org/wiki/MQTT
4
MQTT
Light weight and efficient protocol for the
Internet of Things (IoT) devices to communicate
with each other
The broker is used to filter messages based on
topic and then distribute them to subscribers
No direct connection between a publisher and
subscriber
Contains a broker (server) and clients
The broker accepts messages from clients and then
delivers them to any interested clients. Messages
belong to a topic
The client "device" that either publishes a message to
Any address?
a topic, subscribes to a topic, or both
Publish
A client sending a message to the broker, using a topic
name
Subscribe
A client tells the broker which topics interest it
Ref: https://www.baldengineer.com/mqtt-introduction.html
http://www.steves-internet-guide.com/mqtt/ 5
6 MQTT clients over WiFi
Link: https://youtu.be/nIE5j-L1vLc
Each client is both publisher & subscriber
6
RemotePC
Create account from the invitation
email
Go to the remotePC with Chrome
Browser
https://www.remotepc.com
Login to RemotePC
Click "Connect" button to remotely
access the computer
Answer sheet
Download the answer sheet from Blackboard Student Name
Screen Capture
Code
Dashboard
Dashboard
8
Task 7: Subscribe to MQTT topics
9
Task 7: Subscribe to MQTT topics 10 mins
10
Task 8: Publish to MQTT topics
11
Task 8: Publish to MQTT topics
12
Task 8: Publish to MQTT topics
j) The number is not readable time stamps. Add the
"function node" and wire it in between inject and mqtt
output nodes.
13
Task 8: Publish to MQTT topics 10 mins
14
Exercise 5: Publish the sensor status 25 mins
when request is received
Create the flow based on the following
requirements.
Subscribe to MQTT topics "NodeRED"
Instructor publish the MQTT message. The sample of
MQTT message is
{"PC":"IARWL01","sensor":""}
where IARWL01 is the PC name
If the PC is equal to your PC name (e.g. "IARWL01") and
the value of sensor is empty,
Publish the sensor's status to MQTT topics "NodeRED"
The sample of MQTT message {"PC":"IARWL01","sensor":"on"}
Also, output it in the debug tab
Otherwise, ignore it and no message will be shown.
15
10 Minutes Break
16
In-Class Questions – NodeRED 2
10
mins
Password: 2203142
17
In-Class Questions – NodeRED 2
18
In-Class Questions – NodeRED 2
19
Node-RED dashboards
20
Node-RED dashboards
21
User Interface
22
User Interface
Tab
Tab
Group
23
Task 9: MQTT dashboard to display
MQTT devices
a) Select the Node-RED dashboard
b) Select the Layout tab
c) Click the "+tab" button to add a tab to the user interface.
e) Change the tab's name to "Station 01" and click "Update" button
24
Task 9: MQTT dashboard to display
MQTT devices
f) After creating a tab, the next step is to create several groups under
the tab. Click the "+group" button to add a group to the user interface
25
Task 9: MQTT dashboard to display
MQTT devices
i) Click "Deploy" button
j) To access the Node-RED UI, open another tab in the browser and type the
address http://localhost:1880/ui
k) Since no widgets was not added to the dashboard, it is empty. Next, place 1
"text node" from dashboard session
l) Double-click the "text node" to open the "Edit text node" view
m) Select "Smart Sensors [Station 01]" as the group and click "Done" button
26
Task 9: MQTT dashboard to display
MQTT devices
n) Type "Sensors: " as the Label and click "Done"
button
Text node
27
Task 9: MQTT dashboard to display 20 mins
MQTT devices
q) After adding the widgets, you need to subscribe to an MQTT broker and display messages on a
text node in UI. Place 1 "mqtt node" from input session and 1 "debug node" on the flow. Wire
the nodes together
r) Double-click the "mqtt input node" to open the "Edit mqtt node" view
s) Input the mqtt server and topic
28
Exercise 6: Dashboard for publishing
20 mins
message
Create dashboard for user to submit a "request"
message to the topic " NodeRED "
Add a button node "REQUEST" in the dashboard
Assign the button node to "Exercise 06" as tab and
"Publish Msg" as group
When the button "REQUEST" is pressed, the
message as below is published to MQTT topic
"NodeRED"
{"PC":"IARWL01","action":"request"}
where IARWL01 is the PC name
Also, output it in the debug tab
29
Exercise 7: Dashboard for displaying
30 mins
pallet information
Receive the pallet information from JSON message
via MQTT and display the pallet no. and location in
the dashboard. The MQTT topic is "carrier"
Add 2 "text" node in the dashboard. E.g. Location and pallet
No.
Assign the "text" nodes to "Exercise 07" as tab and "Pallet
Information" as group
Subscribe to MQTT topic "carrier" and save the information
into flow.location and flow.pallet. The sample MQTT
message is as below and also output it in the debug tab
{"location":"HMT","pallet":"2"}
30