In order to process Sensor data sent by IOT Device or IOT Fog Node, vitalpointz IoT Core/Core Lite bundles its own Node RED tool. Node RED itself comprises of a visual graphical editor with drag and drop components and the back end to run the code expressed on the editor UI. Node RED in Vitalpointz IoT Core/Core Lite is pre-installed with vitalpointz’ own custom nodes that help IoT App developer to quickly view, process the messages sent by their devices.
Custom Nodes
Vitalpointz provides two custom nodes namely ‘service-in’ and ‘service-out’. Service-In Node is used to receive messages from the platform and deliver to user defined functions.
Service-Out node takes a message as input. This message is sent inside the Platform. Using Rules engine, the message can be either sent to Device or to OutPort.
Whenever a new device is registered in the platform using ‘Device Add’ process (see: Device Registration) a device decoder can be provided. The Decoder has to be implemented in this NodeRED tool using vitalpointz custom nodes.
For Example, bunch of devices are registered using ‘Device Add’ process with decoder name provided is ‘moistureproc_func’. This sets up rules such a way that whenever any of these devices sent data, the messages are routed and handed over to function named ‘moistureproc_func’.
In order to implement the ‘moistureproc_func’, user should navigate to NodeRED tab, add vitalpointz service-in component and give a name ‘moistureproc_func’. The outpout of the node can be connected to Debug node to view the data on debug panel of NodeRED.
In order to process the sensor data, drag and drop a ‘function’ node and user can input the code. This way, the messages from IoT Devices can be processed in Node RED.
Click on top right-hand corner button “Deploy” to make the code deployed and run.
It is a two step process to produce message and send to device.
Step1: Create Node RED Flow with a function that actually generates data meant for device.
Step2: Create a Rule to route the message to Device
Step1 - Generating message
Navigate to NodeRed Tab. Include a trigger node, function node and Service Out Node under vitalpointz custom node section.
Connect them in a flow as shown below.
Function Node should emit 2 fields namely, msg.topic and msg.payload
Use allocated Device Topic associated with the intended recepient device as msg.topic
msg.topic is the actual message that needs to be sent to device.
Step2 - Routing message using Rules Engine
Next step is to create a rule to send the message generated by the user defined function to the device.
Navigate to Rules Engine -> click Add New Rule.
Enter name of your choice.
Select 'Event to Forward' to 'User Defined'. Enter Device's allocated topic as 'Custom Event'.
Enter 'HOSTED_NODERED' as 'source'
Select 'Forward to' to 'User Defined Service Name'. Enter 'TO_DEVICE' as 'service name'.
Click submit.