Professional Documents
Culture Documents
Node Red Workshop
Node Red Workshop
Workshop
Author: Renata Frenken
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
Starting Up
• Short description Node-RED
• “Hello World” example
• Installation instructions
• Installation instructions for libraries necessary
for the next parts of the workshop
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
[{"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
Dashboard
IoT Examples
• MQTT in Node-RED, how to connect to FHICT
MQTT Broker
• MQTT Mosca Broker
• Web Sockets with ESP8266/ESP32
• CoAP with ESP8266/ESP32
MQTT in Node-RED
• MQTT is standard part of
Node-RED distribution
• There are 2 standard MQTT
nodes, 1 input and one output
node
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":""}]
[{"id":"978a7b90.f10518","type":"mosca
in","z":"d34b5bc8.913538","mqtt_port":"1884","mqtt_ws_port":8080,"name":"mymosca","username":"renata","password":"password","dbur
l":"","x":310,"y":220,"wires":[[]]},{"id":"6f0e210d.caebc","type":"mqtt
in","z":"d34b5bc8.913538","name":"","topic":"topic/mysensorvalue","qos":"2","broker":"6229742c.cc253c","x":340,"y":320,"wires":
[["f1adab22.3d1298"]]},
{"id":"f1adab22.3d1298","type":"debug","z":"d34b5bc8.913538","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"co
mplete":"false","x":550,"y":320,"wires":[]},{"id":"8d3981a7.e51a7","type":"inject","z":"d34b5bc8.913538","name":"","topic":"topic/
mysensorvalue","payload":"35","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":340,"y":440,"wires":
[["b938b25d.62b57"]]},{"id":"b938b25d.62b57","type":"mqtt
out","z":"d34b5bc8.913538","name":"","topic":"topic/mysensorvalue","qos":"","retain":"","broker":"6229742c.cc253c","x":670,"y":440,"wires
":[]},{"id":"2f1cef76.f689a","type":"comment","z":"d34b5bc8.913538","name":"Configure your onw mosca broker","info":"For network
address you can use \"localhost to run it locally. I've used port 1884 so I don't mess with my running MQTT FHICT
server\"","x":380,"y":160,"wires":[]},
{"id":"b1b01daa.8b026","type":"comment","z":"d34b5bc8.913538","name":"Subscribe","info":"","x":300,"y":280,"wires":[]},
{"id":"b792f8a.c4d1908","type":"comment","z":"d34b5bc8.913538","name":"publish","info":"I publish a number now instead of
string.","x":270,"y":380,"wires":[]},{"id":"6229742c.cc253c","type":"mqtt-
broker","z":"","name":"mymosca","broker":"localhost","port":"1884","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleanse
ssion":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willP
ayload":""}]
MQTT Mosca Broker(2)
Go inside the comment for short instructions
Mosca broker
[{"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!