Using FlowFuse Project Nodes for Faster and More Efficient Communication
Easy Communication Between Node-RED Instances with FlowFuse
Node-RED is a powerful tool for IoT application development, connecting various services and devices. However, establishing communication between different Node-RED instances—whether for monitoring or control—can be complex. This often requires detailed configurations and protocols like MQTT, HTTP, or CoAP, despite its seamless integration with many protocols.
FlowFuse addresses this challenge with project nodes designed for easy and efficient communication between Node-RED instances. This guide will show you how to use FlowFuse project nodes to enhance communication and integration, complete with practical demonstrations.
# What Are FlowFuse Project Nodes?
FlowFuse is a platform that helps manage multiple Node-RED instances in one place. This centralized management makes it easier for teams to collaborate and share resources while simplifying scaling and enhancing project security.
To facilitate communication between these centrally organized instances, FlowFuse introduces specific project nodes that enable easy and secure message exchange without complex setup. Behind the scenes, these project nodes utilize MQTT, ensuring that communication is lightweight and fast.
These project nodes include three main types:
Left :Project-in node, Middle: Project-out node, Right: Project-call node
- Project In: Listens for messages being broadcast by other Node-RED instances or for messages sent directly to this instance.
- Project Out: Sends messages to other Node-RED instances.
- Project Call:Sends messages to other Node-RED instances to trigger specific flows and waits for a response that can be sent using the project out node.
# Using FlowFuse Project nodes
In this section, we will explore how to use the FlowFuse project nodes. We’ll begin by explaining the Project In and Project Out nodes, followed by a detailed look at the Project Call node.
# Using Project in and out nodes
To demostrate this nodes, we will use an example where a central instance monitors the CPU performance of multiple Node-RED instances every 10 seconds.
Before we start, let’s understand their configurations:
# Project In Node
- Name: A descriptive label for the node.
- Source:
- Receive: Select this option to receive messages sent specifically to this instance.
- Receive Broadcast From: Choose this option to listen for messages broadcast from other instances. A dropdown will include the names of all instances within your team.
- Topic: This field allows you to specify a topic, similar to MQTT, to categorize the messages.
# Project Out Node
- Name: A descriptive label for the node.
- Mode:
- Send Specified Project Node: This option allows you to send a specific message or payload to the selected instance. Use this for one-way communication.
- Return Project Link Call: This option sends used to sent response back using a Project Out node project call node.
- Target:
- Send Message To Instance: A dropdown to select the instance.
- Broadcast Messages: Option to send messages to all instances.
- Topic: This field allows you to specify a topic, similar to MQTT, to categorize the messages.
# Example: Monitoring CPU Performance Of Node-RED Instances
# Prerequisites
Before we begin, ensure you have installed the following nodes via the Palette Manager:
- node-red-contrib-cpu: This node is essential for monitoring CPU performance. Install it on the instances that you want to monitor.
- @flowfuse/node-red-dashboard: This node is used for creating a dashboard interface. Install it on the central instance, as we will be visualizing the CPU performance data collected from the monitored instances.
# Creating the Flow on the Instances to Monitor
In this section, we will learn how to create a flow that monitors CPU performance and sends data using Project out. We will also discuss how to make this flow reusable, allowing you to apply the same setup across multiple instances without editing the flow each time.
- Drag the Inject node onto the canvas and set the repeat interval to "2 seconds". This will trigger the flow after every 2 seconds.
- Drag the CPU node onto the canvas. Double-click it to configure, enable the option "Send message for overall usage," and click "Done".
- Drag the Change node onto the canvas. Configure it to add metadata, including the instance name, instance ID, using default environment variablesand and the CPU data received from the CPU node.
- Drag the Project Out node onto the canvas. Double-click it to set the Mode to "Send to specified project node." For the Target, select "Send message to instance" and choose the name of your centralized instance.
- Next, Enter the topic as "cpu-performance".
- Connect the output of the Inject node to the input of the CPU node, the output of the CPU node to the input of the Change node, and finally, connect the Change node to the Project Out node.
By utilizing environment variables, this flow becomes reusable, allowing you to copy and paste flow to monitor multple instances.
# Receiving Data to Monitor and Visualize
Image: Line chart visualizing CPU performance of all instances.
To receive the CPU data from monitored instances, follow these steps in your centralized Node-RED instance:
- Open the editor for your central instance.
- Drag the Project In node onto the canvas.
- Double-click the Project In node and set the Source to "Listen for broadcast messages from." Select the name of the instances you want to monitor from the dropdown. If you want data from all instances, select "All instances and devices."
- Enter the Topic as "cpu-performance" (or the topic you configured in the Project Out nodes).
- Drag a ui-chart widget onto the canvas. Set the chart type to "line" and configure the series to
msg.payload
. - Connect the output of the Project In node to the input of the ui-chart node.
- Click the "deploy" button.
Once deployed, open the dashboard to view an interactive live line chart displaying the CPU performance of all monitored devices.
# Visualizing Data for Specific Devices
Image: Gauges visualizing the CPU performance of different devices.
To visualize CPU data for specific devices separately, configure the Project In node to "Listen for broadcast messages from" and select the desired instance name that you want to monitor.
In the instance sending the CPU data for monitoring, set the Project Out node to "Broadcast messages." This will send CPU data to all instances within your team, allowing the centralized instance to capture and display the information.
If you prefer not to use broadcasting, configure the Project Out node with specific topics. This will ensure that receiving nodes capture only specific instance data based on the topic. You can then connect these nodes to gauge nodes to distinctly display the CPU performance for each instance.
This example showcases one of many powerful use cases for FlowFuse project nodes. By utilizing these capabilities, you can transform how your Node-RED instances communicate, enabling efficient workflows and innovative solutions.
# Using Project Call Nodes
Project Call nodes are ideal for triggering flows deployed on another Node-RED instance and retrieving the final result as a response. While they function similarly to webhooks, they utilize MQTT as their underlying mechanism instead of HTTP. In this section, we will demonstrate the use of a Project Call node through an example of making an on-demand temperature request.
# How Project Call Nodes Work
The Project Call node does not operate in isolation; it requires both Project In and Project Out nodes to function properly. The Project Call node triggers the Project In node deployed on the specified target instance, while the Project Out node handles the response. This means the flow that needs to be triggered should start with a Project In node and end with a Project Out node.
# Example: On-Demand Temperature Request
In this example, we will trigger a flow on a Raspberry Pi instance that reads the temperature using a DHT11 sensor and sends the response back to the instance where we use the Project Call node.
Before we start, let’s review the configuration options for the Project Call node:
# Project Call Node Configuration
- Name: A descriptive label for the node.
- Timeout: Set the duration to wait for a response before timing out.
- Target: Specify the target instance where the flow is deployed.
- Topic: This field allows you to specify a topic, similar to MQTT, to categorize the messages.
# Prerequisites
Before we begin, ensure you have the following prepared:
- node-red-contrib-dht-sensor: Install this node via the palette manager. This node is used to manage the connection to a DHT11 or DHT22 sensor on a Raspberry Pi.
- FlowFuse Device Agent Setup: Ensure you have set up and are running the FlowFuse device agent on your Raspberry Pi, and it is connected to the platform.
# Developing a Flow to Handle On-Demand Data Requests
Throughout this section, we will explore how to utilize the Project Call node along with Project In and Project Out nodes to trigger a flow that retrieves temperature readings from a Raspberry Pi on demand.
Note: Before proceeding, make sure your device is assigned to an instance. If the device is assigned to an application, you cannot use Project nodes, as they are designed to work with instances.
- Copy/download the flow above and import/upload it into your Raspberry Pi Node-RED instance. Ensure you have correctly interfaced the DHT11 sensor with your Raspberry Pi. For more information, refer to our guide on Setting Up Node-RED on Raspberry Pi 4, which explains how to install the device agent on the Raspberry Pi and read temperature data from the DHT11 sensor.
- Deploy the flow.
Once you deploy the flow, you will see the temperature data displayed on the Debug panel if everything was done correctly. Now, let’s add the project nodes to trigger the temperature reading flow on demand and retrieve the data accordingly.
- Drag the Project In node onto the canvas, double-click on it, and set the source to "Receive messages sent to this instance." Next, enter the topic.
- Replace the Inject node with the Project In node.
- Next, you can add a Change node to format the data received by the DHT node.
- Drag the Project Out node onto the canvas, double-click on it, and set the mode to "Return to project link call."
Once the flow is ready, deploy it. The final flow should look like the one below:
Now that we have added the Project In and Project Out nodes, the flow can be triggered to read the temperature from any Node-RED instance within your team using the Project Call node and receive the response.
# Triggering the Flow and Receiving Temperature Data
In this section, we will explore how to trigger the flow we created in the previous step and receive the on-demand temperature data.
- Navigate to the instance within your team where you want to receive the data.
- Drag the Project Call node onto the canvas. Double-click it to set the timeout according to your preference, then set the target to the instance where your flow needs to be triggered. Next, enter the topic you configured in the Project In node previously.
- Drag an Inject node onto the canvas and connect it to the input of the Project Call node. This will allow you to trigger the Project Call node manually.
- Finally, drag a Debug node onto the canvas and connect it to the output of the Project Call node. This will help you view the response received from the triggered flow in the Debug panel.
- Deploy the flow.
Now, once you click the Inject button, you will see the response that includes the temperature in the debug panel, which is read by the flow deployed on the Raspberry Pi.
Image showing the project call node triggering the flow deployed on the device to read the temperature data.
Now that you understand how to use FlowFuse project nodes, you can significantly improve the way your Node-RED instances communicate with one another.
Try the FlowFuse platform with its Project Node today to enhance your Node-RED instance management, streamline collaboration, improve security, and effortlessly scale your projects. Accelerate inter-instance communication with Project Nodes—start your free trial now!
If you are an educator or student, we offer support and provide free licenses. Contact us for more information here.
# Conclusion
FlowFuse project nodes streamline communication between Node-RED instances. By using these nodes, you can easily monitor performance, request data, and more. This makes your workflows smoother and more efficient. Start using FlowFuse to enhance your Node-RED projects today!
Written By:
Published on:
Recommended Articles:
- MQTT Service Now Available on FlowFuse
- FlowFuse 2.10: MQTT Broker, Improved Version Control & More!
- FlowFuse Security Features You Didn’t Know You Needed
- Transform Chaos into Control: Centralize Node-RED Management with FlowFuse
- FlowFuse's Software bills of material helps enhance Application Security and Management