Virtual Internet of Things Node-Red Chapter
Virtual Internet of Things Node-Red Chapter
5,900
Open access books available
145,000
International authors and editors
180M Downloads
154
Countries delivered to
TOP 1%
most cited scientists
12.2%
Contributors from top 500 universities
Abstract
Due to the pandemic or any other tough situations, attending the student labora-
tory session physically is difficult or even impossible. To overcome this problem, a
virtual laboratory can be introduced. In many universities, virtual teaching method-
ology is not implemented widely. While there are several existing visual programming
languages developed for various applications, an open-source visual programming
language named Node-RED, which is particularly used for Internet of Things (IoT)-
based applications, is taken into consideration in the book chapter. A complete out-
look of Node-RED, which can be applied for an IoT-based virtual laboratory, is
described. Its simplicity providing many built-in entities makes it possible to evolve
innovative platforms with less coding complexity. The configuration, the flow devel-
opment, the requirements, and the usage of the Node-RED are explained with respect
to handling all the various types of errors. A few experimental cloud-based services
are implemented on an IoT platform using serial port and message queuing telemetry
transport (MQTT) broker service as well as providing live camera capturing feature
with artificial-intelligence-based object detection. The results show that real-time IoT
sensor data can be efficiently measured and visualized in dashboard and live object
detection can be done with good accuracy.
1. Introduction
In this modern era, there has been a lot of development and upgradation in the
field of Internet of things (IoT). The development has been actively growing in
various sectors, for instance, industries, healthcare, education, agriculture, just to
name a few. Consequently, it creates more employment opportunities. Thus, IoT
should come into intensive usages with very careful awareness. The development of
IoT programs can be done in various ways into the society. Although there have been a
plenty of IoT development and applications, only very few academic institutions
throughout the world are fully IoT equipped in their laboratories.
1
Digital Transformation
• To describe the environment and features of Node-RED software with its abilities
of numerous functions.
2
Virtual Internet of Things Laboratory Using Node-RED
DOI: [Link]
• To talk over the suitability and rightness of machine learning and deep learning
centered explanations in numerous practical fields.
• To arrange for a broad opinion on machine learning algorithms, which can be put
to build-up the abilities of a data-driven approach.
• To highlight and summarize the possible study for smart systems including cloud
technology.
The rest of the book chapter is organized as follows. Section 2 presents the
past related existing works on VPL and NodeRED. In Section 3, the step-by-step
methodology of the work is described in detail, which includes getting started,
configuration, utilization, and machine learning (ML) package for Node-RED. The
experimentational examples are provided along with the corresponding results in
Section 4. Section 5 discusses about the results. Lastly, the conclusion is drawn in
Section 6.
2. Related work
IoT has been playing an important role throughout the globe. It is a combination of
both software and hardware tools. With the support of VPL, IoT can be applied into
our day-to-day essential things. According to the survey by Ray in 2017, there were 13
VPLs for the usage and for the upgradation of IoT [1]. The VPL is classified into two
types, namely open-source and proprietary-source with the four following main fea-
tures, i.e., programming atmosphere, license, project source, and platform support
[1]. Students can use open-source VPL such as Node-RED to learn and implement an
IoT system or device with basic engineering skills and low-code programming. It
helped many programmers to develop new software [2, 3]. Node-RED was initiated
and was developed by IBM for connecting hardware devices with web-based editors
[2, 3]. It was then applied further in the field of IoT. Rajalakshmi and Shahnasser came
with a problem while making a cloud-system for IoT devices [4]. This is difficult to
update the firmware by reinstalling the devices. To solve this issue, Node-RED was
used without reinstalling the device and changing the programming code with quick
setup [4]. In 2018, a model based on LoPy, which is a MicroPython triple-network
development platform doubling up as a long-range (LoRa) Nano gateway, was
connected to a system that uses Node-RED for interfacing with a local actuator and
the external data with protocols [5, 6]. Their IoT development could be done in fog/
clouds. The introduction of the IoT in education allows Internet-based communica-
tions to occur between things, sensors, and actuators. This has improved educational
institutions [7–14]. In 2015, Giang et al. implemented a distributed Node-RED (D-
NR) framework for building various types of IoT applications, which can work effi-
ciently with simple designing process and less time [15]. Abdel-Basset et al. could
make an efficient framework by new ideas with lower cost and greater security [16].
3
Digital Transformation
The advantages in maximizing IoT became more for the institutions, i.e., bringing out
an affluent knowledge, better quality of working efficiency, and gaining real-time
experiences [17]. In addition, they could keep track record of all the university
resources with secured data accessibility. Using an open-source platform such as
Node-RED, it helps for the creation of new ideas, i.e., linking up with many other
specialized courses, for instance, information and communication technologies
(ICTs), embedded system design, humanities, agricultural, just to name a few, yield-
ing a good IoT program of study for students to learn and make research [16]. Another
model was proposed by Marquez et al. as an IoT educational platform for virtual
academic communities [17]. In 2020, Torres et al. used VPL with Node-RED to
improve their IoT system by reducing the time taken for the development, i.e.,
reducing the number of failed attempts while deploying an IoT system [18]. Home
automation consisting of water heater, cooling systems, electrical outlets was raised all
over the IoT using cloud-platform where Node-RED is used to make fast setup for
remote monitoring and control of data with a mutual communication [19]. In 2021,
David et al. worked on indoor crop agriculture by monitoring parameters such as
humidity, temperature, and light intensity with the help of IBM-Bluemix, which is the
IBM open cloud platform providing mobile and web developers access to IBM soft-
ware for integration security transaction and other key functions [20]. The data was
transformed into Node-RED platform through a mobile application for tracking pur-
pose of the farmers. Thuluva et al. made a solution for interoperability problem for
IoT semantic web technologies in industrial field using semantic Node-RED models
with feasibility and scalability approach [21]. A rapid and low-cost IoT prototype was
developed by Ferencz and Domokos within less time on Node-RED using the combi-
nation of various cycle power plant dataset [22]. A low-power wide area network
(LPWAN) technology called LoRa with its medium access control (MAC) layer pro-
tocol called LoRaWAN was deployed by Fox et al. in 2019, and these end devices
interact with a gateway using Node-RED connection to an IBM-IoT platform [23].
Node-RED was applied and analyzed by Olsson and Eric in terms of modeling and
security with misuse of API and providing security guarantees [24]. Clerissi et al.
made a model for testing and developing IoT platforms using Node-RED with the
functional behavior and the static view of the system. The class diagrams were used by
testing, defining, and generating in java script using a Mocha test framework [25].
Proper regulations and rules for all the Node-RED developers were given by Clerissi
et al. [26]. They are about the comprehensibility issues, which can be used to increase
efficiency by reducing errors and time to complete tasks.
VPL is any programming language that lets users create program by manipulating
program elements graphically rather than by specifying them textually [27, 28]. A
VPL allows programming with visual expressions, spatial arrangements of text and
graphic symbols used either as elements of syntax or secondary notation. For instance,
many VPLs known as dataflow or diagrammatic programming are based on the idea of
“boxes and arrows,” where boxes or other screen objects are treated as entities,
connected by arrows, lines, or arcs representing relations [29–31]. There are several
different VPLs, which can be divided into different fields of applications, such as
education (23 languages), multimedia (26 languages), video games (18 languages),
systems (34 languages), automation (4 languages), data warehousing (8 languages),
legacy (5 languages), and miscellaneous (10 languages) [29–31]. The difference
between a regular programming and visual programming, in terms of type, nature,
flexibility, speed, efficiency, interface, learning complication, space usage, and
example, is shown in Table 1.
4
Virtual Internet of Things Laboratory Using Node-RED
DOI: [Link]
Table 1.
Difference between regular programming and visual programming.
3. Methodology
Getting started by installing Node-RED can be done on various criteria, which are
explained as follows.
Figure 1.
Block diagram representing methodology workflow.
6
Virtual Internet of Things Laboratory Using Node-RED
DOI: [Link]
• For Microsoft Azure: It is also having the same abilities like IBM cloud with
some extra added features such as replacing as an supplement for many
other on-premise virtual servers with best recovery support.
• For Amazon web services (AWS): It has various new features when
compared with many other cloud-services for developing new innovative
smart devices, where it includes all the required API with less cost for the
third-party usage.
3.2 Configuration
This section describes about various types of configurations that are needed for the
deployment of each different application with default parameters in the default file
directory.
• Editor configuration: It is a set of files with different coding styles with various
text editor plugins.
1. adminAuth: It permits security for user in the editor and admin API.
• Httpadminroot: It is the root url, which contains both API and editor UI.
• httpNodeRoot: It is the node root for all the urls that run HTTP at all endpoints.
• httpRoot: It enables the root url to run on both admin and node endpoints
through overriding httpAdminRoot and httpNodeRoot value.
• httpNodeCors: It is source distribution for the nodes, which are responsible for
HTTP endpoints with cross-origin authentication.
• Tracing (Trace): Tracks about all complete logging, debugging, info, warnings,
error, and fatal errors.
• Function Node: It is for gathering bits and pieces to attach into universal functions.
• Debug Node: Any message directed to the debug sidebar tab with maximum size
and characters.
• MQTT Nodes: If the link is misplaced, how much time to pause in milliseconds
before trying to connect.
• Serial Nodes: How much time to pause in milliseconds before making an effort to
revive into serial port
3.3 Utilization
The important nodes used for the basic functioning of the Node-RED are called
“core nodes.” The main six types of core nodes are explained as follows.
9
Digital Transformation
1. Inject: It starts any flow manually by clicking the inject button. It can be at
required intervals or any time within the editor.
2. Debug: It is used to show messages in the Debug sidebar in the editor, and the
control on the node can be used to permit or restrict its outcome.
It is the section in which all the necessary placement and arrangement of the nodes
are done for the successful execution on the Node-RED.
1. Flow structure: It helps us organize flows, approaches for splitting into smaller,
reusable components, and how to modify them to make use in different
platforms.
2. Message design: It helps how to design messages to create nodes and flows, which
can work together with any number of nodes and are easier to maintain.
It is described as tracing out the bug or an error, which helps to reduce the
developing time and correct the errors easily. The different types of errors on
Node-RED are explained as follows.
1. Logging error: It displays the error with the date and time of the error and the
node, which is noted as an error.
2. Catchable error: It will not be logged, but it informs about run-time error. Then,
the Catch node will be used to produce a flow which can handle it.
3. Sub-flow error: It will not be logged but it informs about run-time error. Then,
the Catch node will be used to produce a flow, which can handle it.
10
Virtual Internet of Things Laboratory Using Node-RED
DOI: [Link]
4. Uncatchable errors: If the error is written in the log, then a message is seen in the
Debug sidebar and log outcome. But creation of a flow is not possible to handle it.
5. Uncaught errors: It causes the Node-RED run-time to shut down and cannot be
controlled in the flow as they are produced by bugs in nodes.
3.4.1 Usage
These flows create a dataset, train a model, and then evaluate it. Models, after
training, can be used in real scenarios to make predictions.
Flows and test datasets are available in the “test” folder. We need to make sure that
the paths specified inside nodes’ configurations are correct before trying to execute the
program. “node-red” can be run from the folder “.node-red/node-modules/node-red-
contrib-machine-learning” and the paths will be automatically correct. The flow shown
in Figure 2 loads a csv file, shuffles it, and creates a training and a test partition.
The flow shown in Figure 3 loads a training partition and trains a “decision tree
classifier” and then saves the model locally.
The flow shown in Figure 4 loads a test partition and evaluates a previously
trained model.
Figure 5 shows the flow of how to use a trained model during deployment. Data is
received via mqtt, predictions are made and then sent back.
Figure 2.
Flow for loading a csv file, shuffling it, and creating a training and a test partition.
Figure 3.
Flow for loading a training partition and training a “decision tree classifier”.
11
Digital Transformation
Figure 4.
Flow for loading a test partition and evaluating a trained model.
Figure 5.
Flow for showing how to use a trained model during deployment.
4. Experimentation
In this section, various types of experiments related to IoT are provided. ESP32,
which is a microcontroller chip manufactured by Espressif Systems, is applied. It
consists of a low-cost and a low-power chip with features such as Wi-Fi (IEEE802. 11
b/g/n), Bluetooth, and built-in antenna. The distributed hash table (DHT11) is a basic,
ultralow-cost digital temperature and humidity sensor. It uses a capacitive humidity
sensor and a thermistor to measure the surrounding air and spits out a digital signal
(using an 8-bit microcontroller unit (MCU)) on the data pin. An Arduino integrated
development environment (IDE) is used to write and upload programs to the Arduino
compatible boards supporting the languages C and C++. Message queuing telemetry
transport (MQTT), which is a lightweight messaging protocol, is used on such a small
microcontroller that allows messaging between device to cloud and cloud to device
with supporting several IoT devices. By using MQTT commands can be sent to control
outputs, data can be read and published from sensors. Therefore, communications
between multiple devices can be established. We can send a command with a client to
control outputs, or we can read data from a sensor and publish it to a client.
Example 4.1.1 DHT11 Sensor Data on Node-RED using a Serial Port (ESP32).
The procedure of this task is described as follows.
2. If the connections are correct, then a light present on the DHT11 sensor is
turned on.
12
Virtual Internet of Things Laboratory Using Node-RED
DOI: [Link]
Figure 6.
ESP32 connection with DHT11 temperature sensor (serial port).
4. If the required packages are absent, then the Arduino IDE shows an error while
uploading the code.
5. After the code is successfully uploaded, we can click on the serial monitor to see
the corresponding temperature and humidity readings of the DHT11 sensor.
6. The Node-RED software is installed into the system. Then, the local hosting
address of the Node-RED is open. This can be run on any browsers.
7. The required nodes, i.e., dashboard and serial port, are installed.
Figure 7.
Node-RED serial port connection for temperature and humidity.
13
Digital Transformation
9. A serial is inserted into the port node, one function node for temperature and
another function node for humidity, which display the DHT11 sensor data.
10. To get the representation, two-gauge nodes for temperature and humidity are
inserted and connected to their respective function nodes.
Example 4.1.2 MQTT Broker Service (ESP32) on Node-RED with DHT11 Sensor Data.
The procedure of this task is described as follows.
2. If the connections are correct, then a light present on the DHT11 sensor will be
turned on.
3. The DHT11 sensor is programmed into the Arduino (IDE) and uploaded into the
ESP32 to show the temperature and humidity.
4. If the required packages are absent, then the Arduino IDE shows an error while
uploading the code.
5. After the code is successfully uploaded, click on the serial monitor to see the
temperature and humidity readings of the DHT11 sensor.
6. The Node-RED software is installed into the system. Then, the local hosting
address of the Node-RED is open. This can be run on any browsers.
7. The required nodes, i.e., dashboard, MQTT-in, and MQTT-out nodes, are installed.
Figure 8.
ESP32 and DHT11 temperature sensor (MQTT broker service).
14
Virtual Internet of Things Laboratory Using Node-RED
DOI: [Link]
Figure 9.
MQTT broker service for temperature and humidity with node-RED.
9. Two MQTT-in nodes, one for temperature and another for humidity, are
inserted.
10. This extracts the sensor data from the ESP32 through the MQTT broker service
and gets into the Node-RED platform with the help of the local-host ip address.
[Link] display this data, the one gauge is connected to the temperature node and the
other is connected to the humidity node.
Example 4.1.3 Live Camera Capture and Object Detection using Machine Learning
(ML).
In this example, a user interface (UI) has a major role for making an interface
between the user and the Node-RED dashboard by the means of a system camera and
a UI-table. Figure 10 shows the procedure of this task, which is described as follows.
1. The Node-RED software is installed into the system. The local hosting address of
the Node-RED is opened. This can be run on any browser.
Figure 10.
Node-RED flow for live camera capture and object detection using machine learning (ML).
15
Digital Transformation
3. We connect the nodes by inserting button node = 2 (capture and clear), change
node = 4 (set [Link], set [Link], set [Link], set [Link]),
UI-webcam node = 1, UI-table node = 1, tfjs-coco-ssd = 1, debug node = 2 (msg.
payload), file node = 1.
The object detection flow recognizes objects in an image and annotates objects
with bounding boxes. An image can be loaded from a built-in camera, the file system,
or by injecting the default image. We need to make sure that we have the node-
red-contrib-browser-utils package installed for all these input nodes to work. This
flow uses three of the custom nodes mentioned above (tf-function, tf-model, and
post-object-detection). The loaded image is passed into the preprocessing node as
[Link]. The msg object is a JavaScript object that is used to carry messages
between nodes. By convention, it has a payload property containing the output of the
previous node. The preprocessing function node is an example of tf-function that
directly calls the [Link] method with the predefined tf variable. The
node produces a Tensor4D image representation as the payload and then passes it to
the COCO SSD lite node, which is an instance of the tf-model custom node. This loads
the COCO-SSD lite [Link] from an external URL and runs inference on the model.
The result of the model goes through the postprocess node that returns an object
array containing bbox, className, and score properties. The objects node combines
an additional property, complete that is set to true, to the msg with the image object.
Then, the bounding-box node draws bounding boxes on the input image and displays
it in the browser.
Example 4.2.1 DHT11 Sensor Data on Node-RED using a Serial Port (ESP32).
Once after the successful deployment, we go to the hosting ip address followed
by:1880/ui, which opens another new webpage representing the gauge readings of the
temperature and the humidity of the DHT11 sensor. The temperature and humidity
readings are directly sent from the serial port to the Node-RED directly. Figure 11
Figure 11.
Dashboard of temperature and humidity from DHT11 sensor (serial port).
16
Virtual Internet of Things Laboratory Using Node-RED
DOI: [Link]
shows an example of the dashboard showing temperature and humidity from the
DHT11 sensor (serial port).
Example 4.2.2 MQTT Broker Service (ESP32) on Node-RED with DHT11 Sensor Data.
Once after the successful deployment, go to the hosting ip address followed
by:1880/ui, which opens another new webpage representing the gauge readings of the
temperature and the humidity of the DHT11 sensor. Temperature and humidity
readings are sent from the sensor to MQTT broker (as a cloud), then finally sent to the
Node-RED as a third-party service. Figure 12 shows an example of the dashboard
showing temperature and humidity from the DHT11 sensor (MQTT broker service).
Figure 12.
Dashboard of temperature and humidity from DHT11 sensor (MQTT broker service).
Figure 13.
Debug message showing single object class and accuracy score.
17
Digital Transformation
Figure 14.
Debug message showing dual object class and accuracy score.
(Press allow). Then, we can see the live camera working and press the capture button
to capture. It detects the object with the help of TensorFlow analysis node as earlier
describe and the output can be seen on the debug panel with the accuracy score of its
correctness. The examples of the single object and the dual object detection are shown
in Figures 13 and 14, respectively.
From the given examples, they can also be made visible on a mobile phone for both
iOS and Android. It is done through remote access just by installing the application
named “RemoteRED” from the mobile app store. The steps are explained as follows.
3. Open the Remote-RED application from the mobile phone and scan the QR code.
18
Virtual Internet of Things Laboratory Using Node-RED
DOI: [Link]
Figure 15.
Connecting to remote-RED application (iOS/android).
5. Now we can see the same output of the Node-RED on the mobile phone Remote-
RED application as shown in Figure 15.
6. This process is the same and it works for any Node-RED workflow.
5. Discussion
The results show that simulated systems developed using the Node-RED can be
deployed in the real world without changing the system parameters. Moreover, the
19
Digital Transformation
simulated system can be connected with hardware platforms easily. VPL-based hands-
on tools are effectively smoothing the beginner’s learning curve on IoT. The stranded
network protocols and IoT protocols are easy to understand using hands-on experi-
ence and deploy in the Node-RED environment. Node-RED system models are easy to
debug compared with the traditional programming debug methods. The platform
works well in both Internet and Intranet mode as all the components are virtually
presented in Node-RED. After all, the laboratory instructors can effectively convey
the basics of network and IoT concepts to the students through a VPL language
including the Node-RED.
6. Conclusion
The book chapter described a complete outlook of Node-RED that can be applied
for an IoT based virtual laboratory. The configuration, the flow development, the
requirements, and the usage of the Node-RED were explained with respect to han-
dling all the various types of errors. We modeled, implemented, and tested the IoT
virtual laboratory using Node-RED. The implemented virtual laboratory system is
currently serving for flexible postgraduate programs and broadcasting completely
online. Students obtain great encouragement and motivation toward virtual IoT
hands-on practices as they can manage their own and convenient time and a location.
The virtual laboratory concept utilizes the available hardware (Wi-Fi IEEE802. 11 b/g/
n routers, classical Bluetooth hardware, and system-on-chip (SoC) like MCU) at the
student location. The virtual IoT laboratory concept was proved to help students to
learn faster than a classical theory class or a video-recorded lesson. With the simplicity
of Node-RED and its built-in entities a few examples, which can be used for an IoT-
based virtual laboratory, were done to evolve innovative platforms with less coding
complexity. It provides flexibility such that the remote laboratory can run on several
operating systems or on a mobile application. The proposed solution is platform-
independent, and therefore, it can be implemented on low-cost hardware for smaller
systems, and the clients can run on mobile devices. The first and second examples are
typical scenarios in IoT on Node-RED platform including Arduino and third-party
cloud service, whereas the third example is live camera capture with object detection
capability. Finally, it was also shown about how Node-RED can be used as a mobile
application remotely. After the completion of the book chapter, the readers are sup-
posed to be able to develop IoT systems using VPL-Node-RED, integrate IoT with
Node-RED, to design various workflows for IoT on Node-RED, develop real-time IoT
applications, and apply security features for IoT and Node-RED while using cloud-
based services. Hence, IoT with Node-RED has the capability to change the entire
education system, which makes better learning with good interaction and flexibility.
The variety of IoT devices in the future is expected to dramatically grow. Our
Node-RED IoT platform was designed to be extendible. To model these future sce-
narios, we expect to support new IoT device types by using the generic framework for
creating new devices. An example of such devices could be wearables that generate
movement data. This type of data can be emitted at high volumes but small size.
Another device type, which is expected, is an IoT device that is configurable at
runtime. This would give us the ability to change the behavior of the device according
to an operation plan. An example of this type of device would be a smart home
thermostat. Furthermore, we also want to improve the intelligence of our smart
testing framework providing machine learning libraries that can continuously learn
20
Virtual Internet of Things Laboratory Using Node-RED
DOI: [Link]
from past data to improve prediction accuracy. Finally, empirical research can be done
collecting a large amount of data in order to know the impact of virtual IoT laborato-
ries on the students with their involvement as it helps the instructors to improve their
laboratory sessions further.
Conflict of interest
Author details
© 2022 The Author(s). Licensee IntechOpen. This chapter is distributed under the terms
of the Creative Commons Attribution License ([Link]
by/3.0), which permits unrestricted use, distribution, and reproduction in any medium,
provided the original work is properly cited.
21
Digital Transformation
References
[14] Bagheri M, Movahed SH. The effect [20] David V, Ragu H, Duraiswamy RK,
of the internet of things (IoT) on Sasikumar P. Iot based automated indoor
education business model. In: agriculture system using node-red and
Proceedings of the 12th International ibm bluemix. In: Proceedings of the 6th
Conference on Signal-Image Technology International Conference on Inventive
and Internet-Based Systems (SITIS); 28 Computation Technologies (ICICT’21);
November-1 December 2016. Naples, 20–22 January 2021. Coimbator, India:
Italy: IEEE; 2016 IEEE; 2021
24