Introduction to Node-red
Dr. Nik
P.M Dr Fahmi
UTeM, FKE
26/2/2020
1
Learning Outcome
• How to install and run node-red
• My first node
• How to import node
• How to install new “palette”
• Writing my first function
• Dashboard
• MQTT
• Email & Telegram
2
How to install node-red
Download latest version of java-script, https://nodejs.org/en/
3
node-red INSTALLATION Next install node-red
Refer: https://nodered.org/docs/getting-started/windows
4
How to run node-red
Go to command prompt by typind ‘cmd’ …
go to the path where node-red is installed, in my case:
C:\Users\01238\AppData\Roaming\SPB_Data\.node-red
Type ‘node-red’
5
Go to web-browser and type the IP –address of the node-red server
By default, node-red is run at port 1880
6
How to stop node-red server
Push “ctrl + c” to stop the server, then push “Y”
Next, try running node-red at different port (1888) by typing
Node-red –p 1888 NIK_task2.json
7
My first node
Epoch time
Don’t forget to Deploy first…
8
Importing node
Choose file or Copy & paste in the field
Click9 Import
Importing node
10
How to install new “palette”
Search for “node-red-contrib-ibm-watson-iot”
11
Try opening the Watson link in your phone too 12
Writing my first function
Now choose the function node, and write a function to generate random number:
Copy this into the function node
var zufall;
zufall=Math.floor(Math.random()*100+1);
msg.payload=zufall;
return msg;
Random number in Watson IOT website
The function is written in javascript language, here is
a good reference to learn more about javascript:
https://www.w3schools.com/js/
13
Dashboard
First install the Dashboard palette.
Add a chart
14
Dashboard
Add new group. Give name “MSD” Add new tab. Give any name.
15
Dashboard
Click on ‘layout’ to change dashboard layout.
Change ‘width’ to any value.
16
Dashboard
Click here to
show dashboard
List of “Tabs”
17
MQTT = Message Queuing Telemetry Transport
PUBLIC
MQTT = Message Queuing Telemetry Transport
List of free to use MQTT servers
https://github.com/mqtt/mqtt.github.io/wiki/public_brokers
However, using public MQTT servers means your data can be viewed by the public.
Alternatively, you can use your PC as MQTT server .
Go to this website for installation:
https://mosquitto.org/download/
PRIVATE
18
MQTT = Message Queuing Telemetry Transport (continued)
19
Using Smartphone as IoT-
Sensor Module
20
Sensor Data logger
• Remotely activate start of data collection
• Live data monitoring (at slower rate)
• Start data logging (at higher rate, no live monitoring)
• Stop
• or Specify duration (in mins) and stop automatically
• Data is stored in .csv
• Retrieve the .csv data by email
21
How to split JSON into individual values (source FB)
a = JSON.parse(msg.payload);
var t = { payload: parseFloat(a.temp)};
t.topic = "Temp";
var rh = { payload: parseInt(a.rh) };
rh.topic = "Humidity";
var co2 = { payload: parseInt(a.co2) };
co2.topic = "CO2";
var r = { payload: parseInt(a.r1) };
r.topic = "relay";
return [co2,t,rh,r];