Comment on page
Node-RED integration
Node-RED is a powerful flow-based development tool designed for visual programming. It serves as a versatile platform for connecting hardware devices, APIs, and online services, making it an integral part of the Internet of Things ecosystem. With Node-RED, you can effortlessly create JavaScript functions using its user-friendly web browser-based flow editor.
Integrating the Scailable AI Manager with a local Node-RED instance is a straightforward process. By following the steps outlined below, you'll be up and running in just a few minutes..
To install Node-RED, the Scailable AI Manager and a basic Scailable example flow on a clean Debian or RPM based device, Scailable has made the following experimental one-line install available:bash -c "$(wget -q -O - https://get.sclbl.net/sclbl_nodered)"
The script will install the Scailable Edge AI Manager, check whether NodeJS is available and up to date, install NodeJS when necessary, then continue to install NodeRed itself. Finally, the Script will start up both the AI Manager and NodeRed, import an example flow. NodeRED will now be available through a browser on port 1880, the Scailable AI Manager on port 8081.
Before you start, ensure that you have successfully installed Node-RED and registered a Scailable Edge AI device. It is preferable to have both the Node-RED instance and the Scailable Edge AI device connected to the same local network, minimizing network latency. If you have a more powerful device, you can install both Node-RED and the Scailable Edge AI Manager on it. However, please note that both applications can be resource intensive, so make sure the device can handle the workload if you choose to install them together.
After successfully registering a device, the next step is to select a model, choose an input, and test it by browsing to the Scailable Edge AI manager's ip address, port
8081
. For this tutorial, I have chosen the Scailable model called "People detector within a region with alarm," which has an input size of 256x256. For the input, I have selected the option
Local video file location (H264 MP4)
with URL file:///opt/sclbl/www/img/samples/faces.mp4
. A test run should then return something like the following result:[
{
"deviceId": "c5b56d73a68c4d53ad857e97b33e9084-4681952910987",
"modelId": "1ea6a9f8-6ce8-4654-a1b2-354d78a3ad4f",
"sourceId": "input-0",
"sourceName": "",
"timestamp": 1684150178445,
"alarm": 1,
"outputType": "json",
"outputFormat": "namedObject",
"outputDims": [
[
60,
6
],
[
3
],
[
3
]
],
"outputDataTypes": [
1,
7,
9
],
"output": {
"counts-0:person;1:bicycle;2:car": [
3,
0,
0
],
"alarm-0:person;1:bicycle;2:car": [
1,
0,
0
],
"bboxes-format:xyxysc;0:person;1:bicycle;2:car": [
90.66048431396484,
151.0379180908203,
284.4067077636719,
478.7001953125,
0.9841935038566589,
0,
333.23876953125,
182.74752807617188,
486.9934387207031,
478.6065979003906,
0.9319453239440918,
0,
466.89654541015625,
98.28123474121094,
561.5626220703125,
480.2935485839844,
0.7916613221168518,
0
]
}
}
]
This is an example of the JSON output generated from a single inference on a single input. Detailed information about the output format can be found in our output format documentation.
If the test ran successfully, proceed to enter
http://localhost:1880/sclbl-json
as a custom output endpoint. If Node-RED is running on a different device from the AI Manager, replace "localhost" with the IP address of the Node-RED server. Please note that port number 1880
corresponds to the default server port used by Node-RED. In the upcoming step, we will proceed to create the /sclbl-json
REST endpoint within Node-RED, which will be responsible for receiving the output.

Now browse to your Node-RED server, port
1880
. Add a
http-in
node and a debug
node, and connect them together:

Next, double click on the
http-in
node and edit its properties:

Specifically, enter
POST
as the node's method, and set its URL to /sclbl-json
. This will create a POST rest endpoint on the Node-RED server at
http://localhost:1880/sclbl-json
.On deploying your new flow, the Node-RED server will be waiting for JSON output from the Scailable Edge AI Manager to be sent its way.
Go back to the AI Manager device on port
8081
, and start the inference engine by clicking run model
. You should now see the green "Model is running banner".

Now, please reopen the Node-RED flow page on port 1880 and navigate to the debug panel on the right-hand side. If everything has been set up correctly, you should observe the Scailable runtime's output smoothly streaming in:

An obvious next step is to parse the received results, enabling you to utilize it for conditional control of other nodes. However, this topic will be covered in a separate tutorial.
You can download an example of the Flow described above here:
basic-sclbl-flow.json
965B
Code
In this second tutorial, we continue where we left off in our first tutorial. Now that we receive JSON data from Scailable, we can parse it and use it to control other Node-RED nodes.
If you look at the previous description, you can see the output we generate contains, among others, a counter for each of the detected classes:
[
{
...
"output": {
"counts-0:person;1:bicycle;2:car": [
3,
0,
0
],
...
}
]
Lets parse those counts, and send a message when the count is 3 persons. To do so, we take the previous Flow, and build on it. In between the
http-in
node and debug
nodes, add a function
node:

Next, double click the function node, and add the following code in the code field within the "On Message" tab:
const counts = Object.values(msg.payload.output)[0];
if (counts[0]==3) {
msg.logs = 3;
return msg;
}
Then change the
debug
node output field to msg.logs:

Finally, deploy the Flow, and start your model in the Scailable AI Manager. You should now see a "3" pop up every time three people are detected when an inference has completed with the analysis of a frame:

You have just created an Flow that can send a message or alert when exactly three people have been detected.
The flow of this second tutorial can be downloaded here:
parse-sclbl-flow.json
2KB
Code
Welcome to the third and final tutorial on integrating Node-RED with Scailable! In this tutorial, we will delve into the process of fetching video frames from the Scailable AI Manager. Additionally, we will explore the exciting task of overlaying bounding boxes onto these frames. The bounding boxes will be generated based on the parsed JSON inference output. Get ready to enhance your Node-RED workflow with advanced visualizations and unleash the power of Scailable's AI capabilities. Let's dive in!
To get started with this tutorial, you will need to have Node-RED installed on your system along with two essential plugins: "node-red-contrib-image-tools" and "node-red-node-annotate-image". These plugins enhance the capabilities of Node-RED for image processing tasks. Once you have these plugins installed, proceed to with the configuration of the desired flow.

Replace the
function
parser code with the following:const output = Object.values(msg.payload.output)[2];
const color = ["blue", "green", "lime", "maroon", "navy", "orange"];
let annotations = [];
for (let i = 0; i < output.length; i += 6) {
if (output[5 + i] < 0) break;
annotations.push({
type: "rect",
fontSize: 14,
stroke: color[output[5 + i]],
fontColor: color[output[5 + i]],
label: output[4 + i].toFixed(2),
x: output[i],
y: output[1 + i],
w: output[2 + i] - output[i],
h: output[3 + i] - output[1 + i]
});
}
global.set('annotations', annotations);
msg.logs = annotations;
return msg;
Whenever a new JSON result is posted, the "bboxes" array undergoes parsing and conversion into a JS object. Subsequently, this object is pushed into a JavaScript "annotations" array. Finally, this resulting array is made globally available to Node-RED, ensuring the availability of the "annotations" data throughout the Flow.
To visualize the bounding boxes, it is necessary to retrieve the decoded input stream images directly from the running AI Manager. This can be accomplished by adding another dedicated set of nodes into your Node-RED flow. These nodes will periodically inject the global bounding box annotations and facilitate the image retrieval process from the AI Manager. The retrieved images will then be enriched with the corresponding bounding boxes and seamlessly displayed within the Node-RED environment.

To start, create an
inject
node configured to begin after a 0-second delay and repeat every 0.1 seconds. Ensure that this node also injects the global.annotations into the msg.annotations, enabling the necessary data flow to draw bounding boxes later on:

For image retrieval, leverage a node-red-contrib-image-tools
image
node to fetch images from an AI Manager's image URL and convert it into a buffer. For example, if your AI Manager is running on localhost, you can retrieve images using the following URL: http://localhost:8081/img.jpg?id=0
.

Finally, add an
annotate-image
node from the node-red-node-annotate-image plugin and a viewer
node from node-red-contrib-image-tools. Make sure the output of the viewer
node is set to the width of the input images, here 640px:

At this point, publish the Flow and run the Scailable Edge AI Manager. The result should be a live view of the video stream with bounding boxes overlaid, right within the Flow!

In the final step, let's add two basic inject nodes, each equipped with an HTTP request node. Configure the first inject node to call the AI Manager by accessing the URL http://localhost:8081/start.

Similarly, set up the second inject node to call http://localhost:8081/end. If Node-RED and the AI Manager are running on different devices, remember to replace "localhost" with the IP address of the AI Manager.
After making these configurations, don't forget to deploy the flow. With the updated setup, you can now effortlessly initiate or terminate the AI Manager's inference by simply clicking the corresponding start or stop injector. This allows you to control the inference process with ease, right from within your Node-RED flow!
Download the exported Flow of this final tutorial below:
visualize-sclbl-flow.json
8KB
Code