As discussed in a previous post, scriptr.io provides a set of node-red compatible nodes allowing for definition of complex scripts running on the cloud.
While the installation was a hassle back then, requiring access to the file system, installation through npm or even an understanding of other tools like CloudFoundry and Orion on IBM BLUEMIX®, it is now made simple thanks to the Palette management interface added in node-red.
To install the node you will have to:
- Open “Manage Palette”
- Go to the Install tab
- Search for scriptr and click Install
The Palette is now updated and 2 new nodes are made available.
The Input node is used to get data from scriptr.io into your node-red flow. This node will listen to a scriptr.io channel and make all messages available to the flow.
Required setup includes the channel you want to subscribe to and a device token (the token to use in order to subscribe to the specified channel). As all other nodes, you can also specify an optional name for the node.
The output node is where all the action happens as this is the node that extends your flows by giving them access to the powerful scripting that scriptr.io provides.
This node can do two operations:
- Run a script
- Publish a message to a channel
Running a script requires specifying the script name to run while publishing a message requires specifying the channel to publish to.
In both situations, you will be able to:
- Specify the protocol (http vs ws)
- Select the token of the device that will execute this operation
- Provide an optional node name
This output node is a “chainable” node, meaning that it has:
- an “in” side which provides the data to the node: this will be the message sent to the channel or the body of the request sent to the endpoint.
- an “out” side which delivers the output of the request. In the case of a scriptr.io endpoint, this will be the output of the script.
In this example, a simple scriptr.io script named “echo” will be invoked. echo is a one line script that just returns the request it receives, as is.
The flow will generate test message using the “inject” node, configured to send a “timestamp”, invoke the echo script and print the msg.payload response using the “debug” node.
Available nodes are now: