Professional Documents
Culture Documents
Node-Red Workshop Autumn 2021
Node-Red Workshop Autumn 2021
Workshop
Author: Renata Frenken
1. Starting Up
• Short description Node-RED
• “Hello World” example
• Installation instructions
• Installation instructions for libraries necessary
for the next parts of the workshop
Node-RED in Short
• developed for fast prototyping in IoT
• used also for wiring hardware, APIs and
services (web services, cloud, …)
• based on node.js
• programmed visually using flows
Node-RED Examples
• Data scraping
• Twitter Control
• Dashboards
• GUI’s
• Domotica
• Database Integration
• Web Sockets
• And Many Others
Example Project Fontys Students
(This project uses Node-RED for MQTT and GUI)
Install Node-RED
• Follow the official installation procedure on
Node-RED web. Before you install Node-RED,
you’ll have to install node.js too:
https://nodered.org/docs/getting-started/local#i
nstalling-with-npm
comments
wires
blocks
flows
Useful plugins for installation
• Node-RED has a lot of nodes but as the online
support is really big, there are a lot of libraries
available too. By installing them you can get
extra functionality
• For the coming examples you should install at
least the libraries from the following page. You
can do that
by choosing “Manage Palette”
from the menu.
Mosquitto MQTT Broker
Dashboard
“Hello world” in Node-RED
Once you install Node-RED, you can run your first flow. Do the following steps:
1. Run Node-RED and connect to it via your browser by typing: localhost:1880
in your URL
2. Import the following flow (text) by going to menu->import->clipboard, see
the next picture:
[{"id":"ce74c126.c2771","type":"inject","z":"42d0aeef.c5aeb","name":"","topi
c":"Hello
World","payload":"","payloadType":"date","repeat":"","crontab":"","once":fals
e,"onceDelay":0.1,"x":200,"y":280,"wires":[["eadd0167.d32c4"]]},
{"id":"eadd0167.d32c4","type":"debug","z":"42d0aeef.c5aeb","name":"","acti
ve":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x
":540,"y":300,"wires":[]}]
Now you should see your first flow:
Input trigger block, click here to start the flow
blue stip means not deployed yet, see next sheet output block
Pu
o
iat
bl
ish
a d Temperature
Publish: Radiator/Config/21
R 1
:T
: 2
be g/ Sensor
se
ri fi
ns
c n
bs o
o
Su r/C
Pub
r/
o
2
t
dia
/1
lish
a
7
:R
Building sh
: Ts
bli
Pu
e ns
Automation
o r/
Server
3/2
Temperature
0
Sensor
Temperature
Sensor
Radiator
MQTT Topics
• Messages on MQTT are published on topics
• Topics don’t need to be configured, they have
to be published
• Topics are organized in hierarchical structure
• Example:
Radiator/Config/Temperature
MQTT in Node-RED
• MQTT is standard part of
Node-RED distribution
• There are 2 standard MQTT
nodes, 1 input and one output
node
Student NR topic:nr
_worksh
op /greetin
gs
MQTT Client
MQTT Broker
test.mosquitto.org
te
Student’s s h o p /clima
rk
nr_wo te
HW MQTT Client topic: l i ma
c
(e.g.ESP32) o p/
h
orks
w
r_
… : n
p ic
to
Student’s
HW MQTT Client
(e.g.ESP32)
Try It out !
• Configure your MQTT block so that it can communicate with
“test.mosquitto.org” MQTT broker (we will use unsecure
connection and port 1883)
• Use inject block to define nr_workshop/greetings topic and a
string payload (string should be about 20 characters long, so
that it can fit in our dashboard)
Try it Out (part 2)
Go to the Node-RED dashboard in the IBM Watson Cloud :
https://node-red-workshop-int.eu-gb.mybluemix.net/ui/
Let the other members of the team publish to this topic. If you
also subscribe to the topic, you should be able to see the
messages from the rest of the team
Node-RED with HW MQTT integration
[{"id":"68da4f11.9bdf3","type":"coap request","z":"4ff0fc80.6b8b74","method":"PUT","observe":false,"url":"coap://192.168.2.143/lightled","content-format":"text/
plain","raw-buffer":false,"name":"PUT lightled","x":370,"y":180,"wires":[["ea9cbb87.4c9cd8"]]},
{"id":"f0a18ae1.f64608","type":"inject","z":"4ff0fc80.6b8b74","name":"","topic":"","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,
"x":130,"y":200,"wires":[["68da4f11.9bdf3"]]},
{"id":"ea9cbb87.4c9cd8","type":"debug","z":"4ff0fc80.6b8b74","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":680,"y":20
0,"wires":[]},
{"id":"92f7cde6.decc5","type":"inject","z":"4ff0fc80.6b8b74","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"
x":140,"y":440,"wires":[["b8dc3d0a.3eadc"]]},{"id":"b8dc3d0a.3eadc","type":"coap request","z":"4ff0fc80.6b8b74","method":"GET","observe":false,"url":"coap://
192.168.2.143/lightled","content-format":"text/plain","raw-buffer":false,"name":"GET lightled","x":370,"y":500,"wires":[["8ecc3510.51e8b8"]]},
{"id":"8ecc3510.51e8b8","type":"debug","z":"4ff0fc80.6b8b74","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":670,"y":46
0,"wires":[]},
{"id":"7be20cd0.9205e4","type":"inject","z":"4ff0fc80.6b8b74","name":"","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1
,"x":110,"y":100,"wires":[["68da4f11.9bdf3"]]},
{"id":"65ab74d6.fe31fc","type":"inject","z":"4ff0fc80.6b8b74","name":"","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"
x":130,"y":300,"wires":[["955db9be.8c4ca8"]]},
{"id":"20c9b295.5af69e","type":"inject","z":"4ff0fc80.6b8b74","name":"","topic":"","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,
"x":130,"y":360,"wires":[["955db9be.8c4ca8"]]},{"id":"955db9be.8c4ca8","type":"coap request","z":"4ff0fc80.6b8b74","method":"PUT","observe":false,"url":"coap://
192.168.2.143/light","content-format":"text/plain","raw-buffer":false,"name":"PUT light","x":400,"y":320,"wires":[["e661e2a8.0504e"]]},
{"id":"e661e2a8.0504e","type":"debug","z":"4ff0fc80.6b8b74","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":650,"y":320
,"wires":[]}]
Note: Only the ESP8266 CoAP code is working, the ESP32 code causes memory
crashes
Success!
MQTT Example with MQTT FHICT server
Use of FHICT MQTT Server
• Before you start using MQTT FHICT Server you
have to create an account, see next slide.
• Please, write down your credentials you’ll need
them for the configuration of the MQTT server
• You can also create your own topic where you
want to publish further, create it with your own
name and give it read/write access, so that you
can delete it in the future
https://selfservice.app.fhict.nl/Services/Mqtt
read/write
result
Configure MQTT Broker(Server)
Trigger Publish To Test
Try It out !
• Publish your name to the
public/i871711_renata topic
- we should be able to see the name strings
on the common screen
• More advanced : Create a string of the format:
<Name>!<timestamp> and publish it to the same
topic
Test with your own hardware
Now that you have an MQTT Broker, credentials and topic, you can start testing by publishing MQTT message by e.g. Arduino,
Raspberry PI, ESP8266. In this way you replace the MQTT publish from Node-RED by your own.
The used flow for MQTT FHICT :
[{"id":"a0b6f1e5.d295","type":"mqtt out","z":"650f08e9.b66298","name":"Publish
","topic":"public/i871711_renata/mytopic","qos":"","retain":"","broker":"985109ec.25b378","x":620,"y":460,"wires":[]},
{"id":"6d45b065.bf2b2","type":"inject","z":"650f08e9.b66298","name":"","topic":"","payload":"my first
test","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":460,"wires":[["a0b6f1e5.d295"]]},
{"id":"e3a9d45c.d23c98","type":"mqtt in","z":"650f08e9.b66298","name":"Subscribe to MQTT
broker","topic":"public/i871711_renata/mytopic","qos":"0","broker":"985109ec.25b378","x":230,"y":180,"wires":
[["37a28f73.65b57"]]},
{"id":"37a28f73.65b57","type":"debug","z":"650f08e9.b66298","name":"","active":true,"tosidebar":true,"console":false,"tostatus"
:false,"complete":"payload","x":600,"y":240,"wires":[]},
{"id":"e6f4f666.189988","type":"comment","z":"650f08e9.b66298","name":"Subscribe to FHICT MQTT server on topic
public/i871711_renata","info":"","x":270,"y":80,"wires":[]},
{"id":"6c2b457b.8e7eac","type":"comment","z":"650f08e9.b66298","name":"Publish timestamp on topic
public/i871711_renata","info":"","x":250,"y":380,"wires":[]},{"id":"985109ec.25b378","type":"mqtt-
broker","z":"","name":"mqtt.fhict.nl","broker":"mqtt.fhict.nl","port":"8883","tls":"","clientid":"","usetls":true,"compatmode":true,
"keepalive":"60","cleansession":true,"birthTopic":"public/i871711_renata/mytopic","birthQos":"2","birthPayload":"Subscribing to
FHICT MQTT Server","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]