Link Search Menu Expand Document

Node-RED

Installation on PC

  1. Set-up an Alpine VM
  2. Activate community packages
  3. Install docker
  4. Install Node-RED
  5. Set-up NAT forwarding as required
  6. Start the Node-Red docker docker start mynodered

Usage

Generalities

  • Nodes can be edited by double-click them
  • New nodes can be added directly in the editor with CTRL+click
  • If you want to set a default value, you can use an inject node
    • But you may have to use 2 in order to change the value

Function nodes

Message go through the node in JavaScript

Example for On Message:

// Create a Date object from the payload
var date = new Date(msg.payload);
// Change the payload to be a formatted Date string
msg.payload = date.toString();
// Return the message so it can be sent on
return msg;

Variables

//Node context
let d = context.get("myData");
context.set("myData", {color: "red"});
var myData = context.get('myData') || 0;

//Flow context
let f = flow.get("sensor");
flow.set("sensor", 1234);
var sensor = flow.get('sensor') || 0;

//Global context
let g = global.get("active");
global.set("active", false);
var active = global.get('active') || 0;

Dashboards

Use node-red-dashboard

Make a dashboard running even on no value change

  1. Create an Inject timestamp with topic: dummy
  2. Join the input with the dummy timestamp, after 1 message part
  3. Create a function that return the input payload return {payload: msg.payload.topic_input};

Images

MQTT

  • If you have a ghost MQTT broker, trying removing all brokers and restart Node-RED
  • If you have connecting, check credentials - they are gone on import