0
0
Iot-protocolsHow-ToBeginner · 4 min read

How to Use Node-RED on Raspberry Pi: Easy Setup and Example

To use Node-RED on a Raspberry Pi, first install it using the official script or package manager, then start the node-red service. Access the Node-RED editor via a web browser at http://localhost:1880 to create flows visually.
📐

Syntax

To install and run Node-RED on Raspberry Pi, use these commands:

  • bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered): Installs Node.js and Node-RED.
  • node-red-start: Starts the Node-RED server.
  • node-red-stop: Stops the Node-RED server.
  • node-red-restart: Restarts the Node-RED server.

Access the editor at http://localhost:1880 in a browser on the Raspberry Pi or its IP address from another device.

bash
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
node-red-start
Output
Node-RED installation script running... Node.js and Node-RED installed. Starting Node-RED... Welcome to Node-RED Once started, open your browser to http://localhost:1880 to access the editor.
💻

Example

This example shows how to create a simple flow that injects a timestamp every 5 seconds and logs it to the debug panel.

Use the Node-RED editor to drag an inject node and a debug node, then connect them.

json
[
  {
    "id": "inject1",
    "type": "inject",
    "z": "example-flow",
    "name": "Inject Timestamp",
    "props": [{"p":"payload"}],
    "repeat": "5",
    "crontab": "",
    "once": true,
    "onceDelay": 0.1,
    "topic": "",
    "payloadType": "date",
    "x": 150,
    "y": 100,
    "wires": [["debug1"]]
  },
  {
    "id": "debug1",
    "type": "debug",
    "z": "example-flow",
    "name": "Debug Output",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "x": 350,
    "y": 100,
    "wires": []
  }
]
Output
Every 5 seconds, the debug sidebar shows the current timestamp in milliseconds since 1970-01-01.
⚠️

Common Pitfalls

Not running Node-RED as a service: Forgetting to start Node-RED means you cannot access the editor.

Firewall or network issues: If accessing from another device, ensure port 1880 is open and the Raspberry Pi IP is correct.

Using outdated Node.js versions: Node-RED requires a recent Node.js version; use the official install script to avoid compatibility problems.

bash
Wrong way:
node-red

Right way:
node-red-start
📊

Quick Reference

CommandDescription
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)Install Node.js and Node-RED on Raspberry Pi
node-red-startStart Node-RED server
node-red-stopStop Node-RED server
node-red-restartRestart Node-RED server
http://localhost:1880Access Node-RED editor in browser

Key Takeaways

Use the official install script to get the latest Node.js and Node-RED versions on Raspberry Pi.
Start Node-RED with 'node-red-start' to run it as a service and access the editor at port 1880.
Create flows visually in the browser by dragging and connecting nodes in the Node-RED editor.
Check network settings if you cannot access Node-RED from other devices on your network.
Keep Node.js updated to avoid compatibility issues with Node-RED.