Bild6.png

How to read a node and all the subnodes in Node-RED

DraganX
Established Member
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

Data LayerData Layer 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. 

The Flow for one IOThe Flow for one IOIf 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. 

The flow for group of input real time dataThe flow for group of input real time dataFollowing 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.

DraganX
DraganX
Hello, I'm Dragan from DCEM/Application, Austria. (Bosch Rexroth)
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