Node RED
Is a visual programming language and the associated Software to run it.
Installation on PC¶
- Set-up an Alpine VM
- Activate community packages
- Install docker
- Install Node-RED
- Set-up NAT forwarding as required
- 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¶
Make a dashboard running even on no value change¶
- Create an Inject timestamp with topic: dummy
- Join the input with the dummy timestamp, after 1 message part
- Create a function that return the input payload
return {payload: msg.payload.topic_input};
Images¶
- node-red-contrib-chart-image to generate images
- âš Not (easily) installable on Alpine because of missing dependencies
- node-red-contrib-image-output to view them
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