Dear Community User! We are updating our platform to a new system.
Read more: Important information on the platform change.

Picture2.png

Creating a dynamic Data Layer Node from Node-RED using Key Value Database App

kuldeepM
Long-established Member

 

Introduction

Throughout this article, you will get a step by step description of how to create a new implicit Data Layer node from Node-RED using the Key Value Data Base App.

Prerequisites

Configuration

Step 1: Download Key Value Database App

At the bottom of the Key Value Database App description in ctrlX Store you can find a section as shown in the screenshot below, where you can get the app and its license.

DOWNLOAD KVD APP DOWNLOAD KVD APP

Step 2: Install Key Value Database App on ctrlX CORE

After downloading the file, we need to access the ctrlX CORE web interface. Check out this Quick Start Guide. Watch this YouTube video tutorial on how to install the app. 

Step 3: Download and install Node-RED App

You can download and install Node-RED App in the same way we did for KVD app. To get to know more functionality about Node-RED please refer to this GitHub page.

Create a flow in Node-RED

Step 1: Open Node-RED 

One can open a Node-RED via ctrlX CORE web interface as shown in the picture below.

ACCESS NODE-RED THROUGH WEN INTERFACE OF CTRLX CORE ACCESS NODE-RED THROUGH WEN INTERFACE OF CTRLX CORE

Step 2: Create a flow

Click on the button 'flow editor' in the Node-RED dropdown menu in the sidebar and it will pop-up a new tab of Node-RED for ctrlX in your browser.

There are two options for creating the desired flow in Node-RED

Option 1: Just copy the code below in the import option, which can be found on the right side menu button as shown in the picture below or simply press ctrl+i.

IMPORT OPTION FOR GIVEN JSON FILEIMPORT OPTION FOR GIVEN JSON FILE

In this import dialogue box copy the code below. the flow will be automatically generated after importing the code. More information about 'Import-Export of flows' can be found in this YouTube tutorial.

[
{
"id": "82282753db553715",
"type": "inject",
"z": "f04e731774fc039c",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 320,
"y": 180,
"wires": [
[
"3ef625bef274f06c"
]
]
},
{
"id": "b44320cd0f26b4cc",
"type": "ctrlx-datalayer-request",
"z": "f04e731774fc039c",
"device": "c4dd1202caa979a1",
"method": "WRITE",
"path": "samples/kvd/implicit/xyz/abc",
"payloadFormat": "value_type",
"name": "",
"x": 330,
"y": 300,
"wires": [
[
"12a27f6d2313a243"
]
]
},
{
"id": "3ef625bef274f06c",
"type": "function",
"z": "f04e731774fc039c",
"name": "function 4",
"func": "const data = {\n type: 'int32',\n value: 50\n}\nmsg.path = 'samples/kvd/implicit/xyz/abc';\nmsg.payload = data;\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 320,
"y": 240,
"wires": [
[
"b44320cd0f26b4cc"
]
]
},
{
"id": "12a27f6d2313a243",
"type": "debug",
"z": "f04e731774fc039c",
"name": "debug 4",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 320,
"y": 380,
"wires": []
},
{
"id": "c4dd1202caa979a1",
"type": "ctrlx-config",
"name": "localhostsub",
"hostname": "192.168.1.1",
"debug": false
}
]


Option 2:
You can manually drag and drop nodes, like shown below.

1. Inject node from common
2. Function node from function
3. Data Layer Request node from ctrlX AUTOMATION
4. Debug node from common

Insert the above nodes into the environment and connect them.

GENERATED FLOW IN NODE-REDGENERATED FLOW IN NODE-RED

In this flow, we only need to configure two nodes

1. Configuration of Function Node
After double-clicking on the function node a dialogue box for "Edit function node"  will open, in which you can type in code as shown in the screenshot below and then click on the "DONE" button. in the picture below data, the variable represents which kind of variable we want to create, in our case it will be an integer.

DIALOGUE BOX FOR EDITING FUNCTION NODEDIALOGUE BOX FOR EDITING FUNCTION NODE

2. Configuration of Data Layer Request Node
By double clicking on the data layer request node a dialogue box for " Edit data layer request node" will open.

First thing is to configure a device for that. Click on the "pencil" icon, a properties dialogue box will open as shown below. Enter the respective data about username and password and click on "update".

POP-UP FOR EDITING CONFIGURATION OF DATA LAYER REQUEST NODEPOP-UP FOR EDITING CONFIGURATION OF DATA LAYER REQUEST NODE

Now we have configured the device and we are back to "Edit data layer request node". Enter data as shown in the screenshot below and click on "Done" and the flow is ready to deploy.

note: If you have already define msg.path in function node then you are not required to define it in picture below.

POP-UP FOR DATA LAYER REQUEST NODE TO CONFIGURE PROPERTIES OF NODEPOP-UP FOR DATA LAYER REQUEST NODE TO CONFIGURE PROPERTIES OF NODE


Explanation about choosing methods and path

The Key Value Database app acts as an easy to setup NO-CODE data provider for the ctrlX CORE with high-performance persistence.
We can configure dynamic (virtual implicit) nodes via client by using a wildcarded root node. 

There are two kinds of Implicit root nodes as highlighted in the picture.

JSON FILE FOR SAMPLES NODE IN ACTIVE DATAJSON FILE FOR SAMPLES NODE IN ACTIVE DATA

Basically, with an implicit root node we can create nodes on all hierarchical levels(samples/kvd/implicit/**) but with implicit_one_level creation is allowed only on the next hierarchical level(samples/kvd/implicit_one_level/*). In my example, I have used an implicit node and created abc child node within xyz.

And it only supports 'create-on-write' (Method CREATE not allowed), which creates a variable when the first time writing a value to it. After the creation of the node there are four operations "read, write, delete and browse".

The simplest way is to use Node-RED in combination with node-red-contrib-ctrlX-automation nodes (READ, WRITE), but you can use all kinds of clients supported by our ctrlX SDK.

We can deploy our flow by clicking on the deploy button, which can be found in the top-right corner of the Node-RED environment. Then press injects button in flow and a new abc child-node with a xyz node will be created in the Data Layer.

GENERATED NODES IN DATA LAYERGENERATED NODES IN DATA LAYER

I have attached a readme pdf file at the end of this article, where you can find further information about which further changes you can execute in Key Value Database app.

I hope this article was useful. If you have any suggestions or questions, do not hesitate to contact me.

1 Comment
Must Read
Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist