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
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.Â
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.