Belajar Node Red
Table of Contents
Introduction
This tutorial is designed to guide you through the basics of Node-RED, a visual programming tool used for connecting hardware devices, APIs, and online services in IoT applications. Whether you are a beginner or looking to refresh your skills, this step-by-step guide will help you understand Node-RED's functionality and how to get started.
Step 1: Install Node-RED
- Prerequisites: Ensure you have Node.js installed on your machine. You can download it from Node.js official site.
- Install Node-RED:
- Open your terminal or command prompt.
- Run the following command to install Node-RED globally:
npm install -g node-red
- Start Node-RED:
- After installation, start Node-RED by typing:
node-red
- This will launch Node-RED, typically accessible at
http://localhost:1880
.
- After installation, start Node-RED by typing:
Step 2: Navigate the Node-RED Interface
-
Overview of the Interface:
- You will see the main workspace where you can drag and drop nodes.
- The palette on the left contains different nodes categorized by functionality.
- The sidebar allows you to configure nodes and view debug messages.
-
Familiarize Yourself with Node Types:
- Input Nodes: Receive data from various sources (e.g., HTTP, MQTT).
- Output Nodes: Send data to destinations (e.g., Dashboard, devices).
- Function Nodes: Allow you to write custom JavaScript code to manipulate data.
Step 3: Create Your First Flow
-
Add Nodes:
- Drag an input node (like an
Inject
node) onto the workspace. - Drag an output node (like a
Debug
node) next to it.
- Drag an input node (like an
-
Connect Nodes:
- Click on the small circle on the right side of the
Inject
node and drag it to the left side of theDebug
node to create a link.
- Click on the small circle on the right side of the
-
Configure the Inject Node:
- Double-click the
Inject
node to configure it. - Set the payload type (e.g., string, number) and value.
- Double-click the
-
Deploy the Flow:
- Click the Deploy button in the top right corner to save your changes.
-
Test the Flow:
- Click the button on the
Inject
node to trigger it. - Check the debug tab on the right sidebar to see the output.
- Click the button on the
Step 4: Expand Your Flow with Additional Functionality
-
Add More Nodes:
- Explore various nodes from the palette, such as
Function
nodes for data processing orHTTP Request
nodes for API calls.
- Explore various nodes from the palette, such as
-
Use Function Nodes:
- Drag a
Function
node to the workspace and connect it between an input and output node. - Double-click to edit and write JavaScript code for custom data manipulation. For example:
msg.payload = msg.payload.toUpperCase(); return msg;
- Drag a
-
Deploy and Test:
- After making changes, click Deploy again.
- Test the flow by injecting data and observing how it processes through the function node.
Step 5: Create a Dashboard
-
Install Dashboard Nodes:
- In the terminal, install the dashboard package:
npm install node-red-dashboard
- In the terminal, install the dashboard package:
-
Add Dashboard Nodes:
- Drag dashboard nodes (e.g.,
ui_button
,ui_gauge
) from the palette. - Connect them to your flow as needed.
- Drag dashboard nodes (e.g.,
-
Access the Dashboard:
- Once deployed, access your dashboard at
http://localhost:1880/ui
.
- Once deployed, access your dashboard at
Conclusion
You've now learned the basics of Node-RED, from installation to creating your first flow and building a simple dashboard. Node-RED is powerful for building IoT applications, and with this foundation, you can explore more complex interactions and integrations.
Next steps can include:
- Experimenting with different node types.
- Integrating external APIs.
- Exploring community contributions and shared flows on the Node-RED website.
Happy coding!