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 for the project.
A typical startup flow involves the following standard nodes: inject, read file, JSON, change, split, and debug (see OL Connect automation with Node-RED), and one OL Connect node: file upload (see OL Connect nodes).
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 Node-RED: nodes and common techniques).
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.
Deploying OL Connect resources
OL Connect's file 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.
If not configured in the node's properties, the node expects this information in msg.filename
.
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 correct OL Connect server, or enter the connection details (see Connection settings for OL Connect Server).
A few tips:
-
You may need to iterate over an array that contains the names of the resources and upload them one by one. This can be done by adding a split node before the file upload node. See Iterating over items in an array.
-
The split node only works on
msg.payload
, not on its child objects. You may need to move the array that contains the resource names to thepayload
. See Setting and moving msg properties. -
To construct the path you may need to concatenate strings. See Concatenating strings.