OL Connect Startup flow
A Startup flow is used in Node-RED projects for OL Connect to initialize global variables and to deploy OL Connect resources (templates, data mapping configurations, job presets, output presets) for the project to OL Connect's File Store.
A typical startup flow has the following nodes:
-
inject
-
folder listing
-
split
-
file store upload.
The file store upload and folder listing nodes are OL Connect nodes.
The inject and split nodes are standard nodes. Other standard nodes that may be useful are the read file, JSON, change, and debug node (see Nodes used in OL Connect flows).
Tip: An example Startup flow is provided by OL Connect Automate, once installed. The example appears in the flows folder in the Import dialog in Node-RED which allows you to import an example flow into a new or existing flow; see Importing and Exporting Flows in the Node-RED documentation.
Instructions are given in the Comment node.
Triggering a startup flow
The inject node can trigger a flow in Node-RED. It can be set to do that when the flow is deployed or when Node-RED is started, by selecting the Inject once after option in its Properties window.
In order to validate the setup you could add a debug node and connect this to the inject node (i.e. join the output port of the inject node with the input port of the debug node). Deploying the flow triggers the inject node, which by default adds a timestamp to the payload
of the msg
object which is passed between nodes in a flow. The timestamp becomes visible on the debug tab when you click the Debug icon in the sidebar.
When the flow is deployed for the first time, a suffix appears after the inject node's name, e.g. "1". The suffix indicates the number of times the flow has been triggered.
Initializing global variables
Variables stored in the global context of Node-RED are visible to all nodes, in all flows on all tabs. The values could be set in a change node or scripted in a function node, for example (see Using variables).
Instead of hard-coding the values, they could be read from a JSON file. The flow would need a read file node and a JSON node to read the JSON file and transform the keys in the JSON into properties of the msg.payload
. Next, a change node can 'Set' global variables to those properties.
Tip: OL Connect's capture folder node can read the name of the folder to be monitored for incoming files from a global variable.
Deploying OL Connect resources
OL Connect's folder listing node returns an array of file paths in `msg.payload`.
To iterate over this array and upload the resources one by one, place a split node before the file store upload node. (See Iterating over items in an array.)
OL Connect's file store upload node uploads a single file to the File Store. This node requires the path to the resource. This should be the full path to the resource or a path relative to either the Node-RED installation or a path relative to the current Node-RED project.
Make sure to check the Mark as permanent option. A file marked as permanent will not be removed by OL Connect's Clean-Up Service.
Also make sure to select the OL Connect Server to which the resources must be uploaded in the settings of the node, or enter the connection details (see Connection settings for OL Connect Server).
Tip:
-
Set the mask of the folder listing node to *.OL-* to get all OL Connect resources in the selected folder.
-
The split node only works on
msg.payload
, not on its child objects. If you are not using the folder listing node, you may need to move an array that contains resource names to thepayload
. See Setting and moving msg properties. -
To construct the path you may need to concatenate strings. See Concatenating strings.