0% found this document useful (0 votes)
47 views35 pages

Node-RED Course

Node-RED course

Uploaded by

brisketmadrid
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)
47 views35 pages

Node-RED Course

Node-RED course

Uploaded by

brisketmadrid
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/ 35

Node-RED

Siemens
PLC IIoT
Delta
PLC

made Easy Arduino

Section 2

Understanding Raspberry pi

nodes MQTT

www.codeandcompile.com
Node-RED made Easy

Inject and Debug node


Inject node
Used to inject any of the following information
• String
• Number
• Boolean
• Array
• JSON

Debug node
Used to read the payload

www.codeandcompile.com
Node-RED made Easy

Link-in and Link-out


Create virtual wires between flows.

The node can be connected to any link


out node that exists on any tab. Once
connected, they behave as if they were
wired together.

The wires between link nodes are only


displayed when a link node is selected. If
there are any wires to other tabs, a virtual
node is shown that can be clicked on to
jump to the appropriate tab.

Note: Links cannot be created going into,


or out of, a sub-flow

www.codeandcompile.com
Node-RED made Easy

Function node

A JavaScript function block to run against


the messages being received by the node.
The messages are passed in as a JavaScript
object called msg.

By convention it will have


a msg.payload property containing the body
of the message.

The function is expected to return a message


object (or multiple message objects), but
can choose to return nothing in order to halt
a flow.

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

The topic of the end result should be “Result”


If the result is more than 100 take another payload which is “True” else it should be “false”

2. Write a function to have the following multiple output:


Output1: Hello World
Output2: Node-RED is fun
Output3: Thank you Dr. Code for this exercise
Output4: Let’s start with next lesson

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.

Optionally, the node can be set to stop evaluating rules once it


finds one that matches.

The rules can be evaluated against an individual message


property, a flow or global context property or the result of a JSON
data expression.

www.codeandcompile.com
Node-RED made Easy

Change node
Set, change, delete or move
properties of a message, flow
context or global context.

The node can specify multiple


rules that will be applied in the
order they are defined.

The available operations are:

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

Split and Join node


Split
Splits a message into a sequence
of messages.

Join
Joins sequences of messages into a
single message.

Automatic: When paired with


the split node, it will automatically join
the messages to reverse the split that
was performed.
Manual: Join sequences of messages in
a variety of ways.
Reduce sequence: Apply an expression
against all messages in a sequence to
reduce it to 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

Sort and batch node


Sort
A function that sorts message property or a sequence of messages.

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.

The sorting order can be:


• Ascending
• Descending

Batch
Creates sequences of messages based on various rules.
• Number of messages
• Time interval
• Concatenate Sequences

www.codeandcompile.com
Node-RED made Easy

Delay and Trigger node


Delay
Delays each message passing through the node
or limits the rate at which they can pass.

Trigger
When triggered, can send a message, and then
optionally a second message, unless extended
or reset.

www.codeandcompile.com
Node-RED made Easy

rbe and Random node


rbe
Report by Exception node - only passes on data if
the payload has changed.

It can also block until the value changes by a


specified amount - deadband modes.

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%

50% Read only if there is change in input

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

made Easy Arduino

Section 3

How to store Raspberry pi

Data? MQTT

www.codeandcompile.com
Node-RED made Easy

Understanding context data


Set
This is used to save the data in the variables within the
flow which cannot be accessed outside the flow.

Set function is used to store the data

Retrieve Context data Get function is used to retrieve the


data stored in the context variable

www.codeandcompile.com
Node-RED made Easy

Understanding global variables


Set Global variables
Sometimes it‘s required to save the data in the variables
which can be aceessed outside the flow.

In this case, we can store data in the global variables

Retrieve Global variables


Get function is used to retrieve the data stored in the global
variable

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

Using global variable


Solve the equation as below:
x = a + 2b + 3c
y = 3a + 2b – 3c

Set value of a randomly within the range 1 to 10


Set value of b randomly within the range 20 to 30
Set value of c randomly within the range 1 to 5

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

made Easy Arduino

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

made Easy Arduino

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

• Control and monitor the conveyor in the plant


• Display the status of inputs, outputs of the panel
on Node-RED
• Count the number of small, medium and big boxes
• Show the box count using bar graph
• Use slider to control the speed of conveyor
• Use led to show the status of motor on the
dashboard

Note: The control operation should be able to


switched between Panel and Node-RED via switch on
the panel

www.codeandcompile.com
Node-RED made Easy

Node-RED interfacing with Delta 12SE PLC via MODBUS

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

made Easy Arduino

Section 6

Interfacing with Raspberry pi

Siemens S7-1200 PLC MQTT

www.codeandcompile.com
Node-RED made Easy

Initial TIA Configuration

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

Reading from PLC


Step 1
Define S7-Communication in Node-RED
Note: Required S7-Comm node
https://flows.nodered.org/node/node-
red-contrib-s7comm

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

You might also like