0% found this document useful (0 votes)
25 views30 pages

TM5022 T9 NodeRed2

Uploaded by

leechinglam.lcl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views30 pages

TM5022 T9 NodeRed2

Uploaded by

leechinglam.lcl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Logistics Automation Project

TM5022
Node-RED Part 2
Instructor : Louis Wong
Industrial Centre
The Hong Kong Polytechnic University

1
An IoT Framework
Logistics automation systems

Sensor …….. Sensor AS/RS

RFID …….. Controller Actuator


Controller
Device layer

Smart Middleware
Industry
http

SQL
Smart
Logistics
CoA
P

Smart
Warehous MQTT

Application Layer Service Layer Coordination Layer

2
Node RED

 Visual Tool for Wiring the Internet of Things (IOT)


 Develop by IBM Emerging Technology and open
source community
 Wire up input, output and processing nodes to
create flows to process data, control things, or send
alerts

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

Please save the file with the name of the


format as below:
Module_Topic_StudentName.doc Code Output Message
e.g. TM5022_NR2_ChanTaiMan.doc

Dashboard

8
Task 7: Subscribe to MQTT topics

a) Place 1 "mqtt node" from input session and 1


"debug node" on the flow
b) Wire the nodes together

c) Double-click the "mqtt input node" to open the


"Edit mqtt node" view
d) Input the mqtt server and topic

9
Task 7: Subscribe to MQTT topics 10 mins

e) Click "Done" button


f) Click "Deploy" button.
g) If connected, a small green connected
indicator is underneath the MQTT node

h) Publish the message by instructor to see the


output

10
Task 8: Publish to MQTT topics

a) Place 1 "mqtt node" from output session and 1


"inject node" on the flow
b) Wire the nodes together

c) Double-click the "mqtt output node" to open the


"Edit mqtt node" view
d) Input the mqtt server and topic

11
Task 8: Publish to MQTT topics

e) Click "Done" button


f) Click "Deploy" button
g) If connected, a small green connected indicator
is underneath the MQTT node

h) Click the "inject node’s" button to send the


current time to mqtt server
i) See the output

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.

k) Double-click the "function node" to open the "Edit


Function node" view
l) Copy and paste the following JavaScript code into the
Function field
// Create a Date object from the payload
var date = new Date(msg.payload);
// Change the payload to be a formatted Date string
msg.payload = date.toString();
// Return the message so it can be sent on
return msg;

13
Task 8: Publish to MQTT topics 10 mins

m) Click "Done" button


n) Click "Deploy" button
o) Click the "inject node’s" button to see the
output

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

 A module that provides a set of nodes in


Node-RED to quickly create a live data
dashboard

20
Node-RED dashboards

 Nodes from the dashboard


section provide widgets that
show up in your application
user interface (UI)

21
User Interface

 The layout of the UI screen can be


controlled in the dashboard tab Tab

 Organize in tabs and groups


 Tabs are different pages on your
user interface, like several tabs in
a browser
 Inside each tab you have groups
that divide the tabs in different
sections so that you can organize
your widgets Group

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.

d) Click the "edit" button to edit the tab's name

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

g) Click the "edit" button to edit the group name.

h) Change the group's name to "Smart Sensors" and click "Update"


button

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

o) Click "Deploy" button


p) Go to the Node-RED UI http://localhost:1880/ui and
refresh it

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

t) Click "Done" button and "Deploy" button


u) Go to the Node-RED UI and refresh it
v) Publish the message by instructor to see the output

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

You might also like