Node-RED Course
Node-RED Course
Siemens
PLC IIoT
Delta
PLC
Section 2
Understanding Raspberry pi
nodes MQTT
www.codeandcompile.com
Node-RED made Easy
Debug node
Used to read the payload
www.codeandcompile.com
Node-RED made Easy
www.codeandcompile.com
Node-RED made Easy
Function node
www.codeandcompile.com
Node-RED made Easy
Exercise 1.0
1. Write a function to make the following arithmetic operation Hello, I am
Result = (2A + 50) Dr. Code
Note: A is an inject node. Use any number you want
www.codeandcompile.com
Node-RED made Easy
Switch node
Route messages based on their property values or sequence
position.
Details
When a message arrives, the node will evaluate each of the
defined rules and forward the message to the corresponding
outputs of any matching rules.
www.codeandcompile.com
Node-RED made Easy
Change node
Set, change, delete or move
properties of a message, flow
context or global context.
Set: set a property. The value can be a variety of different types, or can be taken from an existing message or
context property.
Change: search & replace parts of the property. Replace will only change the type if there is a complete match.
Delete: delete a property.
Move: move or rename a property.
www.codeandcompile.com
Node-RED made Easy
Range node
Maps a numeric value to a
different range.
Input
The payload must be a number. Anything else will try to be
parsed into a number and rejected if that fails.
Output
The value mapped to the new range.
www.codeandcompile.com
Node-RED made Easy
Join
Joins sequences of messages into a
single message.
www.codeandcompile.com
Node-RED made Easy
Exercise 1.1
Write some nodes to perform the following operation
Time to
practice
• Make an array of three JSON object as payload1, payload2 and
payload3 with the information shown in the table
• Define the topic of combined payload as “Info”
• Extract the names, age and city from the combined payload and put them in three
individual arrays with elements as [Name, age, city] with correction of David’s age as 30
Topic Payload 1 Payload 2 Payload 3
Name John Jessica David
City London Australia Germany
Age 26 27 25
Education
Master Mechatronics Chemistry Automotive
Bachelors Instrumentation Medical Science Production
Diploma Automation - Electronics
www.codeandcompile.com
Node-RED made Easy
When configured to sort message property, the node sorts array data pointed
to by specified message property.
When configured to sort a sequence of messages, it will reorder the
messages.
Batch
Creates sequences of messages based on various rules.
• Number of messages
• Time interval
• Concatenate Sequences
www.codeandcompile.com
Node-RED made Easy
Trigger
When triggered, can send a message, and then
optionally a second message, unless extended
or reset.
www.codeandcompile.com
Node-RED made Easy
Random
Generates a random number between a low and high value.
• If set to return an integer it can include both the low and high values. min <= n <= max
• If set to return a floating point value it will be from the low value, up to, but not including the high value. min <= n <
max
www.codeandcompile.com
Node-RED made Easy
Exercise 1.2
1. Write nodes to accept 5 random values between 1 and 10 and sort it based Time to
on ascending order practice
2. Design nodes considering to take the input only if there is change in the
input. Take different inputs in the payload for testing. Simulate input coming
from the sensor (0 to 100) at the rate of 1msg/100ms. Filter this input to
receive only 1msg/3s
100%
0%
Trigger an output (Boolean) when the value changes where the Trigger should have True state for 1 second
www.codeandcompile.com
Node-RED made Easy
Thank you
Code and Compile
Get free/paid courses in our e-learning school at
http://learn.codeandcompile.com
www.codeandcompile.com
Node-RED
Siemens
PLC IIoT
Delta
PLC
Section 3
Data? MQTT
www.codeandcompile.com
Node-RED made Easy
www.codeandcompile.com
Node-RED made Easy
www.codeandcompile.com
Node-RED made Easy
Exercise 1.3
Let try
Using context variable
some
Design an increment and decrement counter which is limited as follows:
examples
Min. Value = 10
Max. Value = 20
There should be a way to reset the counter to value 10
www.codeandcompile.com
Node-RED made Easy
Thank you
Code and Compile
Get free/paid courses in our e-learning school at
http://learn.codeandcompile.com
www.codeandcompile.com
Node-RED
Siemens
PLC IIoT
Delta
PLC
Section 4
Understanding Raspberry pi
Dashboard MQTT
www.codeandcompile.com
Node-RED made Easy
Exercise 1.4
Let try
Include dashboard for all the tasks in Exercise
some
1.0, 1.1, 1.2 and 1.3 from the last sections
examples
Use as much visual elements as required in the
tasks
www.codeandcompile.com
Node-RED made Easy
Thank you
Code and Compile
Get free/paid courses in our e-learning school at
http://learn.codeandcompile.com
www.codeandcompile.com
Node-RED
Siemens
PLC IIoT
Delta
PLC
Section 5
Understanding Raspberry pi
MODBUS MQTT
www.codeandcompile.com
Node-RED made Easy
Understanding MODBUS
Let try
some
examples
www.codeandcompile.com
Node-RED made Easy
Exercises
Task 1
Let try
Control FACTORY IO Tank level environment via Node-RED to achieve the following: some
• Use slider to decide the set point, Proportional Gain, Integral gain and manual examples
draining of tank level
• Show the level status via gauge and error status via graph
• Show the status of filling and draining valve via gauges
www.codeandcompile.com
Node-RED made Easy
Exercises
Task 2
Let try
Control FACTORY IO Conveyor environment via Node- some
RED to achieve the following: examples
www.codeandcompile.com
Node-RED made Easy
www.codeandcompile.com
Node-RED made Easy
Thank you
Code and Compile
Get free/paid courses in our e-learning school at
http://learn.codeandcompile.com
www.codeandcompile.com
Node-RED
Siemens
PLC IIoT
Delta
PLC
Section 6
www.codeandcompile.com
Node-RED made Easy
Step 1 Step 2
Check Permit access with... Uncheck Optimize block access
Step 3
Download the
code
Siemens PLC
S7-1200
AC/DC/Rly
www.codeandcompile.com
Node-RED made Easy
Step 2
Define the tags which you want to read
Step 3
Make flows to read the value from PLC
Step 4
Deploy and test!
More details:
https://github.com/Hilscher/node-red-contrib-s7comm/blob/master/USAGE.md
www.codeandcompile.com
Node-RED made Easy
Writing to PLC
Step 1
Define S7-Communication in Node-RED
Note: Required S7-Comm node
Step 2
Define the tags which you want to write
Step 3
Make flows to write the value from PLC
Note: data should be written in JSON
format Bool INT Real
Step 4
Deploy and test!
More details:
https://github.com/Hilscher/node-red-contrib-s7comm/blob/master/USAGE.md
www.codeandcompile.com
Node-RED made Easy
Exercise 1.5
Task 1
Let try
Design a dashboard to perform the following: some
examples
• Make a switch to turn ON/OFF with time
delay Q0.0. Enter the delay using numeric
entry in the dashboard.
• Make two push buttons to turn ON/OFF with
time delay Q0.1. Enter the delay using
numeric entry in the dashboard.
• Read the status of current time and output
status of Q0.0 and Q0.1.
• Read the number of times output Q0.0 and
Q0.1 is turned ON
www.codeandcompile.com
Node-RED made Easy
Thank you
Code and Compile
Get free/paid courses in our e-learning school at
http://learn.codeandcompile.com
www.codeandcompile.com