- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Introduction
Utilizing Node-RED to extract data from our Data Layer is a well-known method for observing, storing, and interacting with the data. Sometimes, we may need to work with only one data point, while at other times, we require handling multiple data points.
Requirements
- ctrlX CORE - X3 or X7 or a ctrlX OS installation
- Node-RED
Solution
In the first part, we will extract only from one IO, the XI110116.
If we look in the Data Layer, we see that XI110116 only has the operation option of "browse". Using Node-RED Data Layer Request node set with Method "BROWSE" gives us the opportunity to further manipulate the data. Next, we need a function node that can load the addresses of all the channels within that address. The following code allows us to do that:
var payload = [];
for (var i = 0; i < msg.payload.length; i++) {
var data = {
path: msg.topic + "/" + msg.payload[i]
};
node.send(data);
}
Following this, we'll forward the newly generated addresses to the Data Layer Request node (configured to READ, with the Path left empty!) for value retrieval. Afterwards, the data will be organized and stored within an array.
If we aim to extract an entire group of real-time input or output data, adjustments to both the flow and the code are necessary. In this demo, we'll extract input data from 3 CtrlX IOs: XI110116, XC811201, XI342204, and the Master.
Following the same logic as before, we need to include an additional Data Layer Request node set to BROWSE, along with a slightly modified function node.
var payload = [];
for (var i = 0; i < msg.payload.value.length; i++) {
var data = {
path: msg.topic + "/" + msg.payload.value[i]
};
node.send(data);
}
The output of this flow once again consists of a large array containing the names and values of XI110116, XC811201, XI342204, and the Master. To adjust the output, the Batch and Join nodes need to be modified.
To give it a try, please copy the content from the attachment and paste it into Node-RED.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.