3. Confidential
www.vitalpointz.net
Flow Processing signifies the processing of messages
received from Devices / Fog Nodes
In flow processing, users can implement their own
functions, one or more to process the messages.
Functions are invoked to incoming messages
Functions can be implemented in two ways
Using Hosted NodeRED, the built-in NodeRED tool
with vitalpointz helper nodes
Using Workload Containers
Deployment of end-to end flow processing in vitalpointz
IoT Core is largely of 2 steps, no specific order
Specify the function name while Adding Devices
Define the Function
3
Overview
4. Confidential
www.vitalpointz.net
Receiving messages from Devices into Function
Navigate to NodeRED tab, scroll down left-hand
pane
Under vitalpointz directory, helper nodes are
provided
Use Service In node and double click to enter
the function names
4
Writing Function in NodeRED – (1)
Double
Click
Function
Name
5. Confidential
www.vitalpointz.net
Sending a message from a Functions to Devices
Step1: create a message
Navigate to NodeRED
Create a function node with below Code
{
topic:’<device allowed device topic>’,
payload:"Message to be sent to Device”
};
Wire to vitalpointz Service Out Node
Provide name & Source name
Step2: create a Rule to forward the message
to Device
See Next Slide
5
Writing Function in NodeRED – (2)
Connect
Service-Out
to Function
Node
Write the js
code into
the function
node
6. Confidential
www.vitalpointz.net
Sending messages from Functions to Devices
Navigate to Rules Engine, click Add New
Rule
Select Events to Forward ‘User Defined’
Enter custom Event = device topic entered in
Node RED function
Enter Source= Source name entered in Node
RED Service Out Node
Select Forward to ‘User Defined Service
Name’
Enter Service name = ‘TO_DEVICE’
6
Writing Function in NodeRED – (2)
7. Confidential
www.vitalpointz.net
Broadcasting to all Devices/FogNodes
When a function generated event needed to be received by all device or all fog nodes or both, follow
below mentioned procedure
Step 1: Create a Function that generates message to be broadcasted
Step 2: Wire it to Service Out Node in NodeRED
Step 3: Create a Rule to Broadcast
7
Writing Function in NodeRED – (3)
8. Confidential
www.vitalpointz.net
Step 1: Create a Function that generates a
message to be broadcasted
Message must be in JSON format
Topic: define your own topic, starting with ‘app/abcde’
Payload: this could be JSON object or a String.
If payload is a string, all devices and fog nodes will
receive this message as is
If payload is a JSON object and if a key called
‘broadcast’ is found, the message broadcast can be
controlled
broadcast:’device’ - forces broadcast service to send
the message only to devices (i.e, No Fog Node will
receive this message)
broadcast:’fognode’ - forces broadcast service to send
the message only to devices (i.e, no Device will receive
this message)
If this key is missing or the payload is JSON, the
message is delivered to every device and fog nodes
Note: The device will receive this message in their
<allowed device topic>/fromcloud
8
Broadcasting
Payload
defined in
the function
10. Confidential
www.vitalpointz.net
Step 3: Create a Rule to Broadcast
Navigate to Rules Engine, click ‘Add a
new Rule’
Select Events to Forward ‘User Defined’
Enter custom Event = topic entered in
Node RED function e.g, ‘app/abcde’
Enter Source= Source name entered in
Node RED Service Out Node
Select Forward to ‘Broadcast Service’
10
Broadcasting
Forward To:
Broadcast
Service
11. Confidential
www.vitalpointz.net
Pro
Easy to write and test a function
Quick to debug or visualize the device
messages
User can leverage the community NodeRED
nodes to quickly build dashboards, write
business logics & much more
Cons
Hosted NodeRED is not multi-user supported,
this means flows created by one user is visible
to others
JavaScript is the primary language to develop
over NodeRED
11
Caveats of Hosted NodeRED
Recommended Best practice
NodeRED container image identical to in-built
Hosted NodeRED is available in Workload
By spinning up one or many NodeRED
containers, user can create their own container
to process their data in an isolated manner
This way multi-user problem can be solved
User can leverage the community NodeRED
nodes to quickly build dashboards or business
logics etc
12. Confidential
www.vitalpointz.net
Functions can be implemented in following
workload containers
VPZ-nodered
helloworld-js
helloworld-py
Spinning a vpz-nodered workload brings up
another NodeRed instance
helloworld-js / hellowold-py
This container implements basic hello world
program that listens on a specific user defined topic
(called Topic In)
Sends the message back using user defined topic
called Topic Out
This container also implements a REST server that
listens on 3005 port
This port runs configuration service
Configuration service accepts 3 parameters namely
SSH to be enabled or not , Topic IN and Topic Out
This can be invoked using ‘Configure’ menu item
on workload tab
12
Writing Function in workload containers
13. Confidential
www.vitalpointz.net
User can enable SSH access on configure
menu
Login to container using ‘SSH Access’ menu
item
User can modify the code, save and commit
as new image
Then spin up their own container as
production workload
See quick guide in workload tab from details
13
Writing Function in workload containers
14. Confidential
www.vitalpointz.net
Device messages can be connected to a
function in Device Add form
When a Group of devices is added, all the
messages from the devices will be sent to the
same function
Navigate to Device Tab, click on Add IoT
Device
Enter a name of function in Message
Decoder/Processing Function
Writing Function using
NodeRED Option: Use Service In Node under
vitalpointz directory, enter the same function
name entered in above step
Workload option : use helloworld-js/helloworld-
py and enter the same function name in TopicIn
14
Connecting Device to Functions