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:

  1. Open “Manage Palette”
    manage-palette
  2. Go to the Install tab
    install
  3. Search for scriptr and click Install
    search

 

The Palette is now updated and 2 new nodes are made available.

Input Node

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.

Output 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:

  1. Run a script
  2. 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:

  1. Specify the protocol (http vs ws)
  2. Select the token of the device that will execute this operation
  3. Provide an optional node name

Sample

This output node is a “chainable” node, meaning that it has:

  1. 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.
  2. 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.

sampleAvailable nodes are now:

new-nodes