You are on page 1of 22

sustainability

Article
An Efficient Wireless Sensor Network Based on the ESP-MESH
Protocol for Indoor and Outdoor Air Quality Monitoring
Anwar Ulla Khan 1, * , Mohammad Ehtisham Khan 2 , Mashhood Hasan 1 , Waleed Zakri 3 , Waleed Alhazmi 3
and Tarikul Islam 4

1 Department of Electrical Engineering Technology, CAIT, Jazan University, Jazan 45142, Saudi Arabia
2 Department of Chemical Engineering Technology, CAIT, Jazan University, Jazan 45142, Saudi Arabia
3 Department of Mechanical Engineering Technology, Jazan University, Jazan 45142, Saudi Arabia
4 Department of Electrical Engineering, Jamia Millia Islamia, New Delhi 110025, India
* Correspondence: anwarkhan@jazanu.edu.sa; Tel.: +966-544-952-944

Abstract: The main aim of this work is to establish a sensor MESH network using an ESP-MESH
networking protocol with the ESP32 MCU (a Wi-Fi-enabled microcontroller) for indoor and outdoor
air quality monitoring in real time. Each sensor node is deployed at a different location on the college
campus and includes sensor arrays (CO2 , CO, and air quality) interfaced with the ESP32. The ESP-
MESH networking protocol is a low-cost, easy-to-implement, medium-range, and low-power option.
ESP32 microcontrollers are inexpensive and are used to establish the ESP-MESH network that allows
numerous sensor nodes spread over a large physical area to be interconnected under the same wireless
network to monitor air quality parameters accurately. The data of different air quality parameters
(temperature, humidity, PM2.5, gas concentrations, etc.) is taken (every 2 min) from the indoor and
outdoor nodes and continuously monitored for 72 min. A custom time-division multiple-access
(TDMA) scheduling scheme for energy efficiency is applied to construct an appropriate transmission
Citation: Khan, A.U.; Khan, M.E.; schedule that reduces the end-to-end transmission time from the sensor nodes to the router. The
Hasan, M.; Zakri, W.; Alhazmi, W.; performance of the MESH network is estimated in terms of the package loss rate (PLR), package
Islam, T. An Efficient Wireless Sensor
fault rate (PFR), and rate of packet delivery (RPD). The value of the RPD is more than 97%, and the
Network Based on the ESP-MESH
value of the PMR and PER for each active node is less than 1.8%, which is under the limit. The results
Protocol for Indoor and Outdoor Air
show that the ESP-MESH network protocol offers a considerably good quality of service, mainly for
Quality Monitoring. Sustainability
medium-area networks.
2022, 14, 16630. https://doi.org/
10.3390/su142416630
Keywords: air quality; ESP-MESH; humidity; PM2.5; sensor nodes; temperature
Academic Editors: Shahrin bin Md.
Ayob and M Saad Bin Arif

Received: 20 October 2022


Accepted: 8 December 2022 1. Introduction
Published: 12 December 2022 The oxygen present in the air is essential for human life. The air combines oxygen,
Publisher’s Note: MDPI stays neutral
nitrogen, inert gases, and water vapor. In the atmosphere, human actions release unwanted
with regard to jurisdictional claims in elements, some of which could be the source of complications for living beings (plants,
published maps and institutional affil- humans, and animals). Polluted air also affects plant growth in precision agriculture [1].
iations. Air quality could be articulated by the absorption of numerous pollutants, such as
carbon NOx, SO2 , O3 , CO, HC, volatile or semi-volatile organic compounds (VOCs), and
particulate matter (PM) of diverse particle sizes [2]. The level of air pollution could also be
expressed in terms of the air quality index (AQI) [3].
Copyright: © 2022 by the authors. Contamination inside our homes is also considered an alarming issue, as well in
Licensee MDPI, Basel, Switzerland. offices and schools. Indoor actions, such as smoking and cooking, could create impurities.
This article is an open access article Typically, in manufacturing nations, the inhabitants devote approximately 80–90% of their
distributed under the terms and time inside houses and are consequently exposed to detrimental interior contaminants.
conditions of the Creative Commons
Indoor air quality is commonly evaluated by distinctly gauging the CO, temperature, and
Attribution (CC BY) license (https://
humidity [4]. These statistics, even if merged, are deficient in permitting a good depiction
creativecommons.org/licenses/by/
of the inside air quality.
4.0/).

Sustainability 2022, 14, 16630. https://doi.org/10.3390/su142416630 https://www.mdpi.com/journal/sustainability


Sustainability 2022, 14, 16630 2 of 21

There are mainly two types of outdoor air pollutants in urban areas: vehicle emissions
and industrial emissions. Depending on the location and winds, there could also be
contributions from power plants and industrial boilers, incinerators, petrochemical plants,
aircraft, and ships [2,5].
Numerous studies [6–8] indicated that outdoor air influences indoor air quality. Kuo
and Shen et al. [6] found a similar increase in PM2.5 and PM10 concentrations indoors
and outdoors during a dust storm event, which they attributed to the ventilation system’s
extraction of outdoor air.
The effects of poor air quality could be felt immediately, even after exposure to pollu-
tants only, including irritation of the throat, eyes, and nose, a headache, and so on [9]. For
monitoring the air pollution effects in homes and workplaces before the condition becomes
more serious, a real-time air quality monitoring system is quickly becoming necessary.
Indoor and outdoor air quality monitoring networks characterized by high flexibility
and a real-time, modular, and cost-effective nature are becoming feasible due to the ad-
vancement of IoT technology, information communication technology (ICT), and sensor
technology [10]. In [11], Kumar et al. proposed an inexpensive indoor pollution gas moni-
toring system based on internet of things (IoT) technology to monitor indoor air quality.
Many researchers have already addressed this issue. An integrated DSP microcontroller
was used for this monitoring system, allowing it to measure CO and CO2 gas concentrations
with a deviation of ±5% from the standard data set.
Using WSNs, Abraham and Li proposed an inexpensive IAQ monitoring system [12]
that could simultaneously collect six air quality parameters from various sites. A real-time
system for monitoring CH4 and CO gases was proposed by Ahmed et al. in [13], but the
final system cost increased due to the Intel Edison microcontroller board. Firdhous et al.
in [14] projected an inside air monitoring system, which was imperfect for O3 only, based
on the IoT technology.
After reviewing the available literature, it was recognized that communication tech-
nologies mostly used Bluetooth low energy (BTLE), Wi-Fi, and Zig-Bee [15–17].
Hence, an inexpensive and medium-range network was proposed to measure indoor
and outdoor air quality. For this, a dust and gas sensor was used to monitor the PM2.5
dust particles and toxic gases. Scientists have long pointed out that haze could significantly
increase lung cancer risk, reducing the average life expectancy by one year [18]. MQ series
gas sensors (MQ-135, MQ-2, and MQ-7) are available for monitoring air quality (benzene,
alcohol, and NH3 ), methane, butane, LPG, smoke, and carbon monoxide.
Finally, temperature and humidity sensors are selected so that people can monitor
how comfortable their working and living environments are and how the temperature and
humidity impact other parameters.
This work aims to present an indoor and outdoor air quality monitoring system by
using an ESP-MESH networking protocol that permits abundant devices (stated as sensor
nodes) spread over a large physical area (both indoors and outdoors) to be consistent
under one WLAN (wireless local-area network) for a precise extent of air quality and the
recognition of the air contamination measures of the sensor’s irregular operation. The main
influence of this article is as follows:
1. As part of the first step, the hardware platform for the air quality sensors, which in-
cludes a gateway, a base station, and sensors, is designed; specifically, a new hardware
platform for the sensor nodes that could collect air quality measurements from the
indoors and outdoors;
2. The second function of the system software is to provide data acquisition, processing,
transmission capabilities, and energy conservation strategies for the entire system;
3. Third, utilizing a custom time-division multiple-access (TDMA) scheduling scheme
for energy efficiency, a transmission schedule that reduces the end-to-end transmission
time from the sensor nodes to the router is constructed;
4. Fourth, the experimentation of the sensor accurateness extent in the real physical
scenes is provided;
system;
3. Third, utilizing a custom time-division multiple-access (TDMA) scheduling scheme
for energy efficiency, a transmission schedule that reduces the end-to-end transmis-
sion time from the sensor nodes to the router is constructed;
Sustainability 2022, 14, 16630
4. Fourth, the experimentation of the sensor accurateness extent in the real physical 3 of 21
scenes is provided;
5. In the final section, we evaluate the communication interface performance, includ-
ing the package loss rate (PLR), package fault rate (PFR), and rate of packet delivery
5. In the final section, we evaluate the communication interface performance, including
(RPD).
the package loss rate (PLR), package fault rate (PFR), and rate of packet delivery (RPD).
2. ESP-MESH Protocol
2. ESP-MESH Protocol
Based on a Wi-Fi protocol, a novel networking protocol, “ESP-MESH”, was pro-
Based on a Wi-Fi protocol, a novel networking protocol, “ESP-MESH”, was proposed
posed by Espressif
by Espressif SystemsSystems (Shanghai)
(Shanghai, CO., LTD
China) CO., LTD [19].
[19].
By using the ESP-MESH protocol, a huge number of Wi-Fi-enabled
By using the ESP-MESH protocol, a huge number of Wi-Fi-enabled devices
devices (e.g.,(e.g.,
ESP-
ESP-32,
32, ESP-8266,
ESP-8266, etc.) could
etc.) could be interconnected
be interconnected beneath
beneath a single
a single wireless
wireless local-area
local-area net-
network
work (WLAN)
(WLAN) over a over
wideaphysical
wide physical
area. Thearea. Thefeature
main main feature
of this of this protocol
protocol is its self-
is its self-healing
healing and self-organizing property (the network could be built and sustained
and self-organizing property (the network could be built and sustained independently). inde-
pendently). The main disadvantages of the outmoded Wi-Fi network substructure
The main disadvantages of the outmoded Wi-Fi network substructure are (1) the limited are (1)
the limited coverage area with the single access point shown in Figure 1a
coverage area with the single access point shown in Figure 1a and (2) overloading (the and (2) over-
loading (the
capacity capacity
limitation limitation
of the of the access point).
access point).

(a) (b)
Figure1.1.(a)
Figure (a)Traditional
Traditionalinfrastructure
infrastructureofofWi-Fi
Wi-Fi networks:
networks: limited
limited coverage
coverage area
area with
with a single
a single ac-
access
cess point. (b) In the ESP-MESH, the nodes are free to connect with nearby nodes.
point. (b) In the ESP-MESH, the nodes are free to connect with nearby nodes.

TheESP-MESH
The ESP-MESHovercomes
overcomesthethe limitations
limitations of outdated
of outdated infrastructure
infrastructure Wi-FiWi-Fi net-
networks
works in such a way that in ESP-MESH, the nodes are free to connect
in such a way that in ESP-MESH, the nodes are free to connect with their nearby nodes with their nearby
nodesis(there
(there is no
no need need to to
to connect connect to anode),
a central central node),
shown in shown
Figure 1b.in Figure 1b. Each
Each node node is
is commonly
commonly accountable for communicating with each other’s transmissions.
accountable for communicating with each other’s transmissions. This results in the This results
ESP-
in the ESP-MESH
MESH network
network covering covering a considerably
a considerably better
better exposure exposure
area withoutarea without
requiring requir-
it to be in
ingrange
the it to be
ofin
thethe rangenode.
central of the Also,
central node. Also,
ESP-MESH ESP-MESH
seems to be less seems
proneto to
be congestion
less prone to as
congestion
there as there is no
is no requirement forrequirement
any node tofor any node
connect to connect
the single centralthenode.
single central node.
The ESP-MESH network is a multi-hop network, which means that each node could
transmit packets to another through one or more wireless hops in the network. Thus, each
node in the network serves as a relay as well as transmitting its packets.
A network of ESP-MESH nodes may consist of three types: the sink node, the inter-
mediate node, and the end node. The sink node interfaces directly with a conventional
Wi-Fi router and relays packets between the nodes in the network and the external IP
network. Only one sink node is present in an ESP-MESH network. Node A is the root node
in Figure 1b.
An in-between node communicates, obtains data packets, and forwards data packets
directed from its upstream and downstream connections (Nodes B, C, and D, are the
intermediate nodes in Figure 2b). An end node could be able only to transmit or receive its
packets. However, it cannot forward the data packets of other nodes (Nodes E, F, G, and H,
are the end nodes in Figure 2b). sink/root node selection, layer formation, and limiting tree
depth are the three steps of the ESP-MESH network-building process, as shown in Figure 2.
The ESP-MESH is a self-healing network since it perceives and corrects for letdowns in
network routing.
ets directed from its upstream and downstream connections (Nodes B, C, and D, are the
ets directed from its upstream and downstream connections (Nodes B, C, and D, are the
intermediate nodes in Figure 2b). An end node could be able only to transmit or receive
intermediate nodes in Figure 2b). An end node could be able only to transmit or receive
its packets. However, it cannot forward the data packets of other nodes (Nodes E, F, G,
its packets. However, it cannot forward the data packets of other nodes (Nodes E, F, G,
and H, are the end nodes in Figure 2b). sink/root node selection, layer formation, and
and H, are the end nodes in Figure 2b). sink/root node selection, layer formation, and
limiting tree depth are the three steps of the ESP-MESH network-building process, as
Sustainability 2022, 14, 16630 limiting tree depth are the three steps of the ESP-MESH network-building process, ofas
shown in Figure 2. The ESP-MESH is a self-healing network since it perceives and4 cor-21
shown in Figure 2. The ESP-MESH is a self-healing network since it perceives and cor-
rects for letdowns in network routing.
rects for letdowns in network routing.

(a) (b) (c)


(a) (b) (c)
Figure 2. Three steps of the ESP-MESH network-building process; (a) root node selection, (b) layer
Figure2.2.Three
Three steps of
of the
the ESP-MESH
ESP-MESH network-building process; (a) root node selection, (b) layer
formation, andsteps
Figure (c) limiting tree depth. network-building process; (a) root node selection, (b) layer
formation, and (c) limiting tree depth.
formation, and (c) limiting tree depth.
The following diagram shown in Figure 3 represents the arrangement of an ESP-
Thefollowing
The following diagram shown in Figure 3 represents the arrangement
of an of an ESP-
MESH packet anddiagram shown
its linkage within aFigure
Wi-Fi3data
represents
frame.the arrangement
The header contains ESP-MESH
the media
MESHand
packet packet and itswith
its linkage linkage with
a Wi-Fi a Wi-Fi
data frame. data header
frame. The header contains the control
media
access control (MAC) addresses for both theThe
transmittercontains the media
and receiver nodes.access
The actual
access addresses
(MAC) control (MAC)for addresses
both the for bothand
transmitter the receiver
transmitter andThe
nodes. receiver
actualnodes.
data The
are actual
available
data are available in the payload of the MESH packet. The payload of an ESP-MESH
data are
inpacket available
the payload in
of the the
MESH payload
packet. of the MESH
The payload packet.
of anmayThe payload
ESP-MESH of an ESP-MESH
comprises the definite application data and contain packet
either comprises
encoded data the
packet comprises
definite application the
data definite
and mayapplication
contain data encoded
either and maydatacontain either
(MQTT, encoded
JSON, and data
HTTP)
(MQTT, JSON, and HTTP) or raw binary data.
(MQTT,
or JSON,data.
raw binary and HTTP) or raw binary data.

Figure3.3.The
Figure TheESP-MESH
ESP-MESHpacket
packetstructure
structurecorresponds
correspondstotoitsitsWi-Fi
Wi-Fidata
dataframe.
frame.
Figure 3. The ESP-MESH packet structure corresponds to its Wi-Fi data frame.
2.1.
2.1.Selection
Selectionofofthe
theRoot/Sink
Root/Sinkand andIntermediate
IntermediateNodes
Nodes
2.1. Selection of the Root/Sink and Intermediate Nodes
The
The sink node may be automaticallyset
sink node may be automatically setupupororchosen
chosen bybythe
theadministrator.
administrator. The
Thesignal
sig-
The
intensities sink
of node
all idle may
nodes be automatically
relative to the set
router up or chosen
determine by
the the administrator.
automatic selection The
of a sig-
sink
nal intensities of all idle nodes relative to the router determine the automatic selection of
nal intensities
node. ofnode
all idle nodes relative to the router determine the automatic selection of
a sinkEach
node. idle
Each would
idle node send
would its send
addresses (MAC)
its addresses and
(MAC)router
andRSSI values
router RSSIthrough
values
a sink
Wi-Fi node.
beacon Each
packets.idle node would send its addresses (MAC) and router RSSI values
through Wi-Fi beaconThen, every
packets. nodeevery
Then, concurrently scans for beacon
node concurrently packets
scans for from
beacon other
packets
through
idle nodes.Wi-Fi beacon
If a node packets.a beacon
identifies Then, every
packet node
withconcurrently scans
a greater router for it
RSSI, beacon
wouldpackets
initiate
from other idle nodes. If a node identifies a beacon packet with a greater router RSSI, it
from other
sending the idle nodes.
frame’s If a node identifies
information. a beacon
The broadcast and packet
scanning with a greaterwould
procedure routercontinue
RSSI, it
would initiate sending the frame’s information. The broadcast and scanning procedure
would
for initiate sending
a predetermined the frame’s
minimum information.
number The (10
of iterations broadcast andisscanning
iterations procedure
the default setting),
resulting in the propagation of the beacon packet with the greatest router RSSI across
the network. Every node would verify its vote percentage (the count of votes or number
of nodes taking part in the election) after all iterations to decide whether it becomes the
sink node. If a node’s vote percentage exceeds a predefined threshold (90% is the default
setting), the node becomes a sink node.
Figure 4 shows the construction of an ESP-MESH network when the sink node is
selected automatically. The beacon frame with the strongest router RSSI is transmitted
across the network after numerous iterations of broadcasting and scanning. Node A has the
strongest router RSSI (−15 dB); as a result, its beacon frame is broadcast across the network.
All nodes participate in the election vote for node A, providing it with a 100% vote share.
Thus, node A becomes a sink node and establishes a connection with the router. Nodes
B/C/D/H link to node A since they are the preferred intermediate nodes after node A is
connected to the router. Nodes F and G link to node C, while node E connects to node B,
concluding the network construction process.
across the network after numerous iterations of broadcasting and scanning. Node A has
the strongest router RSSI (−15 dB); as a result, its beacon frame is broadcast across the
network. All nodes participate in the election vote for node A, providing it with a 100%
vote share. Thus, node A becomes a sink node and establishes a connection with the
router. Nodes B/C/D/H link to node A since they are the preferred intermediate nodes
Sustainability 2022, 14, 16630 5 of 21
after node A is connected to the router. Nodes F and G link to node C, while node E
connects to node B, concluding the network construction process.

Figure 4. Construction of an ESP-MESH network in which the sink node is automatically selected.
Figure 4. Construction of an ESP-MESH network in which the sink node is automatically se-
lected.
Using the “esp_mesh_set_attempts()” function, the minimum number of election pro-
cess iterations may be configured. Users must modify the number of iterations dependent
Using the “esp_mesh_set_attempts()” function, the minimum number of election
on the number of network nodes (i.e., the more extensive the network, the greater the
process iterations may be configured. Users must modify the number of iterations de-
necessary number of scan iterations).
pendent on the number of network nodes (i.e., the more extensive the network, the
The threshold for the vote percentage may also be set using the “esp_mesh_set_vote_
greater the necessary number of scan iterations).
percentage()” function. Setting a low vote threshold percentage may result in two or more
The threshold for thesink
nodes becoming vote
nodes percentage
in the samemay also network,
ESP-MESH be set forming
using the several networks.
“esp_mesh_set_vote_percentage()” function. Setting a low vote threshold
If such is the case, the ESP-MESH provides internal capabilities percentage
to resolve the sink node
may result in two or more nodes
disagreement becoming sink
autonomously. nodessink
Multiple in the same
node ESP-MESH
networks wouldnetwork,
be merged into a sin-
forming several networks. If such is the case, the ESP-MESH provides internal
gle network with a single sink node. In addition, setting a small capabili-
number of iterations
ties to resolve and
the sink
a lownode disagreement
voltage threshold autonomously.
percentage mightMultiple
cause sink nodeinstability
network networks owing to RSSI
variations [19–21].
The administrator may also nominate the sink node, which would result in the speci-
fied sink node communicating directly with the router and bypassing the voting mechanism.
Whenever a sink node is selected, all other nodes must forego the voting mechanism to
avoid a sink node dispute.
Following the sink node’s connection to the router, the idle nodes in the vicinity of
the root node would begin connecting to the sink node, creating the second layer of the
network. Once joined, the second layer nodes become intermediate nodes, forming the
third layer. Figure 2 shows that nodes B, C, and D are reachable from the sink node. As a
result, nodes B, C, and D become intermediate since they establish upstream connections
with the sink node. The connected nodes on the topmost layer of the network would
immediately become terminal nodes to prevent the network from expanding over the
maximum number of levels. This prevents a newer layer from emerging by preventing the
unused nodes from communicating with the terminal node. Furthermore, if there is no
other idle node that may serve as an intermediate node, the node would stay idle forever.
forever.

2.2. Network Management


Sustainability 2022, 14, 16630
The ESP-MESH is a self-healing wireless network because it detects6 ofand
21
rectif
routing failures. The ESP-WIFI-MESH manages sink node failures as well as interme
ate node failures.
2.2. Network Management
2.2.1. SinkTheNode Failure
ESP-MESH is a self-healing wireless network because it detects and rectifies
routing failures. The ESP-WIFI-MESH manages sink node failures as well as intermediate
If the sink node breaks down, the nodes connected with it would promptly det
node failures.
the failure of the sink node. The second layer nodes would initially attempt to reconn
with2.2.1.
the Sink
sinkNode
node.Failure
Nonetheless, after numerous unsuccessful attempts, the second lay
nodes would initiate abreaks
If the sink node freshdown,
round theof sinkconnected
nodes node election.
with it wouldThe second
promptly layer
detectnode
the with
failure of the sink node. The second layer nodes would initially attempt
highest router RSSI would be selected as the new sink node, while the other second lay to reconnect with
the sink node. Nonetheless, after numerous unsuccessful attempts, the second layer nodes
nodes would establish an upstream link with the newly chosen sink node.
would initiate a fresh round of sink node election. The second layer node with the highest
If theRSSI
router sinkwould
nodebeand many
selected as descending
the new sink node,layers subsequently
while the other secondfailed (for
layer example,
nodes
rootwould
node,establish
secondanlayer,
upstreamandlinkthird
withlayer), thechosen
the newly shallowest
sink node. layer that was still operatio
If the sink node and many descending layers subsequently
would initiate the root node election. Figure 5 demonstrates the failed (for example, the root
self-healing mechani
node, second layer, and third layer), the shallowest layer that was still operational would
after a root node failure. Sink node A would attempt to reconnect if it becomes disco
initiate the root node election. Figure 5 demonstrates the self-healing mechanism after a
nected. The failure.
root node secondSinklayer
nodenodes
A would initiate
attemptthe voting process
to reconnect if it becomesby disconnected.
transmittingThe their RS
aftersecond
numerous unsuccessful
layer nodes attempts
initiate the voting to by
process rejoin. Node their
transmitting D’s RSSIs
router RSSI
after is the greate
numerous
Node D is chosen
unsuccessful as thetosink
attempts rejoin.node
Nodeand D’s starts to accept
router RSSI the downstream
is the greatest. links. The oth
Node D is chosen
as the sink node and starts to accept the downstream
nodes on the second layer, B and C, establish upstream links with node D,links. The other nodes on restoring
the
second layer, B and C, establish upstream links with node D, restoring the network to
network to regular operation.
regular operation.

Figure 5. Auto-healing
Figure 5. Auto-healingfrom theeffects
from the effects of sink
of sink nodenode failure.
failure.

2.2.2. Intermediate Node Failure


If an intermediate node fails, the detached end nodes would first try to reconnect
with the intermediate node. After numerous unsuccessful efforts to rejoin, every end node
would begin scanning for possible intermediate nodes. If there are more viable intermediate
nodes, every end node would choose a new desired intermediate node and establish an
upstream link. If there are no other suitable intermediate nodes for a given end node, it
would stay idle forever.
Figure 6 depicts self-healing in response to a failure of an intermediate node. If
intermediate node B fails, the surrounding nodes, E and F, would notice the failure and seek
to reestablish communication with node B. After many unsuccessful reconnect attempts,
nodes E and F begin to pick a new favorite intermediate node. Node E is out of range from
all intermediary nodes and is thus currently inactive. Node F is within the reach of nodes C
and G, although node C is chosen due to its lesser depth. After joining with node C, node F
becomes an intermediary node, allowing node E to link. The connectivity is restored, but
its routing is altered, and an additional layer is introduced.
seek to reestablish communication with node B. After many unsuccessful reconnect
tempts, nodes E and F begin to pick a new favorite intermediate node. Node E is out
range from all intermediary nodes and is thus currently inactive. Node F is within t
reach of nodes C and G, although node C is chosen due to its lesser depth. After joini
Sustainability 2022, 14, 16630 with node C, node F becomes an intermediary node, allowing node E to 7link. of 21 The co

nectivity is restored, but its routing is altered, and an additional layer is introduced.

Figure 6. Auto-healing
Figure 6. Auto-healingfrom theeffects
from the effectsof of an intermediate
an intermediate node failure.
node failure.

2.2.3. Asynchronous Switching-on Reset


2.2.3. Asynchronous Switching-on Reset
The sequence in which nodes the switch on may influence the formation of the ESP-
The sequence
MESH networks. If inspecific
whichnodesnodes the the
within switch
networkon turn
mayoninfluence the formation
asynchronously (i.e., delayed of the ES
MESHby anetworks.
few minutes), the network’s
If specific nodes final configuration
within may vary
the network fromon
turn theasynchronously
ideal scenario in (i.e., d
which all nodes turn on synchronously. The following conditions would apply to nodes
layed by a few minutes), the network’s final configuration may vary from the ideal s
that are delayed when powering on:
nario in Condition
which all1:nodes If there turn on synchronously.
is an existing sink node in theThe following
network, conditions
the delayed node wouldwould app
to nodes
not trythat areindelayed
to vote a new sink when
node,powering on:a greater RSSI. Instead, the delayed node
even if it had
Condition 1: If there is an existing sink node
would connect to a suitable intermediary node andin thethenetwork,
join network theas anydelayed
idle nodenode wou
would. If the delayed node is the assigned sink node, all other network
not try to vote in a new sink node, even if it had a greater RSSI. Instead, the delayed no nodes would
remain inactive until it activates.
would connect to a suitable intermediary node and join the network as any idle no
Condition 2: When a delayed node establishes an upstream link and becomes an inter-
would. If the
mediate node,delayed
it may also node is the
become the assigned sink node,
favored intermediate alladjacent
of the other nodes.
network nodes wou
It would
remain inactive
result until it activates.
in the neighboring nodes switching their upstream links to join the delayed node.
Condition 3: If
Condition 2: When a delayedan idle node has anode
specified intermediate
establishes an node that is delayed
upstream link and when
becomes
switching on, it would not try to create any upstream links in the lack of its specified inter-
intermediate node, it may also become the favored intermediate of the adjacent nodes
mediate node. The inactive node would stay inactive forever until its assigned intermediate
would
noderesult in the neighboring nodes switching their upstream links to join the delay
arrives.
node. Figure 7 depicts the impact of asynchronous power on network construction. Nodes A,
Condition
C, E, F, G, and3: H Ifarean idle node
switched has a specified
on simultaneously intermediate
and start the sink node node thatprocedure
election is delayed wh
switching on, it would not try to create any upstream links in the lack ofsink
by transmitting their addresses (MAC) and router RSSIs. Node A is chosen as the its specifi
node since its RSSI is the highest. As node A becomes the sink node, the other nodes start
intermediate node. The inactive node would stay inactive forever until its assigned
constructing upstream links with their selected parent intermediate, layer after layer. Nodes
termediate
B and D nodeare slowarrives.
in switching on, although neither attempts to become the sink node,
Figurehaving
despite 7 depicts the impact
a greater router RSSIof asynchronous
(−10 dB) than node power on network
A. Instead, construction.
both delayed nodes Nod
establish upstream links with their selected root node, node A.
A, C, E, F, G, and H are switched on simultaneously and start the sink node electi Following the completion
of the node joining, nodes B and D would each take on the role of an intermediate node.
procedure by transmitting their addresses (MAC) and router RSSIs. Node A is chosen
If the network started up simultaneously, node D would have been the root since
the sink node
its router since
RSSI is the itshighest
RSSI is(−the highest.
10 dB). To putAs node A
it another becomes
way, the sink
the network node, the oth
architecture
nodes start
built underconstructing
synchronous power upstream links withwould
on circumstances theirlook
selected parentfrom
quite different intermediate,
the one lay
produced under asynchronous power on conditions.
delayed nodes establish upstream links with their selected root node, node A. Following
the completion of the node joining, nodes B and D would each take on the role of an
intermediate node.
If the network started up simultaneously, node D would have been the root since its
Sustainability 2022, 14, 16630 router RSSI is the highest (−10 dB). To put it another way, the network architecture 8built
of 21
under synchronous power on circumstances would look quite different from the one
produced under asynchronous power on conditions.

Figure 7. Construction of a network using an example of asynchronous power on.


Figure 7. Construction of a network using an example of asynchronous power on.
2.2.4. Sink Node Switching
2.2.4. Sink Node Switching
The ESP-MESH protocol does not switch the sink node automatically until the root
node The
fails.ESP-MESH
The sink nodeprotocol doesstay
would not unaffected
switch the sinkevennode
if its automatically until thetoroot
router RSSI declines the
node fails. The sink node would stay unaffected even if its router
point of disconnection. Sink node switching is actively initiating a fresh election in whichRSSI declines to the
apoint
nodeofwith
disconnection.
a strongerSink node
router switching
RSSI is chosen is actively
as the initiating
new sinkanode. fresh election
This may in which
be an
a node with
effective a stronger
strategy router RSSI
for adjusting is chosen
to the as the new
deteriorating sinksinknodenode. This may beWhen
performance. an effec-
the
tive strategy
existing networkfor adjusting
requires atosink
the switch,
deteriorating
the sink sink node
node performance.
must When
explicitly use thethe existing
“esp_mesh
network requires
waive_sink()” a sink
function switch,
to initiate the election.
a fresh sink node must
At this time,explicitly
the sinkusenodethe “esp_mesh
would request
waive_sink()”
that all other nodesfunction
in theto initiatetransmit
network a fresh election.
and scan At thethis
beacontime, the sink
frames nodeawould
through re-
broadcast,
questwhich
after that all
it other
wouldnodes in the network
stay networked. transmitnode
If another and scan
winsthe more beacon
votesframes
than thethrough
current a
broadcast,
sink node, theaftersink
which it would
switching stay networked.
procedure If another
would begin; node wins
otherwise, morenode
the sink voteswould
than
remain unaltered.
the current sink node, the sink switching procedure would begin; otherwise, the sink
nodeThe newly
would chosen
remain sink node sends a switch request to the existing sink node, and
unaltered.
the current sink chosen
The newly node responds
sink node with
sendsan aindication that ittoisthe
switch request prepared
existingtosink
switch.
node,Upon
and
receiving
the currentthesink
answer,
nodetheresponds
newly chosen
with an sinkindication
node would thatseparate from itsto
it is prepared parent node
switch. Uponand
instantly establish an uplink connection to the router, becoming
receiving the answer, the newly chosen sink node would separate from its parent node a new sink node in the
network. The initial sink node would detach from the router while
and instantly establish an uplink connection to the router, becoming a new sink node in retaining all downlink
connections and entering a state of inactivity. The preceding sink node would initiate a
search for prospective parents and choose the desired parent.
Also, sink node switching must need an election and is thus only supported when a
self-organized ESP-MESH network is in use. In other words, if a user-defined sink node is
used, sink node switching cannot occur.

3. Time-Division Multiple-Access (TDMA) Scheduling Algorithms


The MESH network needs to guarantee that the data is correctly received regardless
of the distance between the sensor node and the sink node. It is imperative that the
intermediate nodes and sensor nodes coordinate the time window so that the intermediate
Sustainability 2022, 14, 16630 9 of 21

node is in the receiving mode while the sensor node is transmitting data since sensors that
are beyond the communication range of routers must locate an intermediate node to route
their data.
Constantly opening the reception channel of the intermediary node is an easy solu-
tion to this coordination issue. However, an always-on receiving channel wastes energy.
Hence, we adopt a TDMA scheduling algorithm (Algorithm 1) [22] to our MESH net-
work (Figure 1b).
A setup step is required to construct the transmission schedule for the algorithm to
function properly. The setup phase includes the following actions; hello, routing messages
sent across sensor nodes, the transfer of necessary data to the sink node, the computation
of the schedule, and the sensor nodes receiving the schedule via flooding.
The sensor node is then aware of all the other sensor nodes (neighbors) within its
communication range and the next sensor node on its path toward the sink node. To
determine the appropriate TDMA schedule, each sensor node in the MESH network
(Figure 1b) transmits the above information to the root node, which uses Algorithm 1
outlined in the pseudo-code.

Algorithm 1 Pseudo-code used to define the TDMA schedule.


Input: node-list
Line-1
Response: schedule
Line-2 do
Line-3 slot = new_Slot ();
Line-4 set-send-colsn = [];
Line-5 set-recv-colsn = [];
Line-6 while node-list: length > 0 do
Line-7 node = node-list [0];
if (node.recv == 0 && (node: absent in set-send-colsn) && (node-dest: absent in
Line-8
set-recv-colsn)) then
Line-9 slot[node] = ‘SEND’;
Line-10 slot[node-dest] = ‘RECV’;
Line-11 set-send-colsn.include(node-dest-neighbors)
Line-12 set-send-colsn.include(node-dest)
Line-13 set-recv-colsn.include(node-neighbors)
Line-14 node-dest.recv–;
Line-15 node-list.eliminate (node);
Line-16 schedule: insert (slot)
Line-17 while slot: length > 0
Line-18 return schedule

As illustrated in Table 1, a “node-list” structure is produced for the network shown in


Figure 1b. To calculate the TDMA schedule, Table 1 contains the following information: the
neighbors of each node, the next hop destination for each node, the number of hops until
the router, as well as the number of reception slots required before transmission begins.
The TDMA schedule is shown in Table 2. R corresponds to a certain time slot during
which the sensor node turns on its receiver, while S represents the sending time slot for
every node. The following are descriptions of how Table 2 was generated using Table 1 and
Algorithm 1.
Sustainability 2022, 14, 16630 10 of 21

Table 1. Information about the sample network’s connectivity.

Node Neighbors Dest Hops Recv


A B, C, D ROUTER 0 3
B A, C, E, F A 1 2
C A, B, G, F A 1 1
D A, C, H A 1 1
E B, F B 2 0
F B, C, E, F B 2 0
G C, F, H C 2 0
H D D 2 0
Neighbors: The node’s one-hop neighbors. Dest: The routing protocol’s next-hop neighbor for the router. Hops:
The variety of times a packet must be forwarded to a router. Recv: Listening slots. The receiving property ensures
that the wake-up messages arrive in a TDMA frame.

Table 2. The resulting TDMA schedule S indicates that the node sends in the specified timeslot, and
R indicates that the node receives at the specified time slot.

Node 1 2 3 4 5
A R R R
B R R S
C R S
D R S
E S
F S
G S
H S

Firstly, the node set is generated, including all the network’s nodes that have yet to be
assigned a transmission slot. Next, the node set is ordered to boost the overall performance.
Specifically, the nodes with high hops are positioned at the top so they may transmit in the
first available slots, reducing the overall frame length. This is because the overall frame
span would be at a minimum as long as the index number of the existing slot plus the
value of the new node’s “hops” attribute. Furthermore, nodes with more neighbors are
prioritized over nodes with fewer neighbors since these nodes are more likely to appear in
the next collision list. A collision list is a collection of nodes that may create a collision if
they broadcast in the same timeslot. The “set-send-colsn” list includes the nodes whereby
a transmission would clash with an existing node in the timeslot. The “set-recv-colsn”
list includes the nodes that would overhear a signal based on its timeslot. A potential
broadcast toward such nodes could result in a collision, preventing the sender from joining
the timeslot. Consequently, the following node list is constructed for the MESH network,
seen in Figure 1b:
Node list = {F, G, E, H, B, C, D, A}.
Initially, the collision set contains no values. Following the preceding node list, we
begin with node F. As per Table 1, the dest node of F is B, and the “Recv” term is zero. Thus,
in Table 2, “S” and “R” are filled in slot one for nodes F and B, respectively. Node B and its
neighbors are added to the “set-send-colsn” list, transforming it into {A, B, C, E, F}. The
“set-recv-colsn” list is now populated with the neighbors of node F and becomes {B, C, E,
G}. The “Recv” term of dest node B is lowered by one, resulting in a value of one.
Now, node G is chosen. In this instance, G’s dest node is C, and the “Recv” term
equals zero. Then, we verify the availability of node G in the previous “set-send-colsn” list
Sustainability 2022, 14, x FOR PEER REVIEW 11 of 22

Now, node G is chosen. In this instance, G’s dest node is C, and the “Recv” term
Sustainability 2022, 14, 16630 11 of 21
equals zero. Then, we verify the availability of node G in the previous “set-send-colsn”
list and node C in the prior “set-recv-colsn” list before determining which slot to use.
Checking reveals that node C is included in the “set-recv-colsn” list; hence, “S” and “R”
and
are node C in the
populated in prior “set-recv-colsn”
slot two against nodes listGbefore
and Cdetermining
in Table 2. The which slot to use. Checking
“set-send-colsn” list is
reveals
now {A, that
B,node
C, F,CG} is included in the “set-recv-colsn”
and “set-recv-colsn” list;The
is {C, F, H}. hence, “S” and
“Recv” term“R”ofare
destpopulated
node C
in slot twozero.
becomes against nodes G and C in Table 2. The “set-send-colsn” list is now {A, B, C, F, G}
and “set-recv-colsn”
The dest node for is {C,
nodeF, H}.
E isThe “Recv”
B, and term of term
the “Recv” dest node C becomes
is zero. Both nodes zero.
E and B are
absent from the preceding “set-send-colsn” and “set-recv-colsn” lists; thus,Eslot
The dest node for node E is B, and the “Recv” term is zero. Both nodes andtwoB are
is
absent from the preceding “set-send-colsn” and “set-recv-colsn”
populated with them. Table 2 is populated with “S” and “R” against nodes E and B. Thelists; thus, slot two is
populated
“Recv” term withof them. Table
dest node 2 is
B is populated
decreased bywith “S” and
one and “R” against
becomes zero. nodes E and B. The
“Recv” term of dest node B is decreased by one and becomes zero.
This method is continued until every sensor node has had the chance to transmit, at
whichThis method
point is continued
the node until every
list is emptied. The sensor node has had
first investigated nodethefor
chance
each to transmit,
slot is always at
which point the node list is emptied. The first investigated node for
inserted due to the algorithm’s execution. Therefore, the procedure concludes when the each slot is always
inserted
planneddueslot to
hasthe
noalgorithm’s
nodes. Table execution.
2 displaysTherefore, the procedure
the resultant concludes when the
slot positions.
planned slot has no nodes. Table 2 displays the resultant slot positions.
4. Design and Implementation of the (Air Pollution Monitoring) APM System
4. Design and Implementation of the (Air Pollution Monitoring) APM System
4.1.General
4.1. GeneralOverview
Overview
Figure11shows
Figure showsthethe schematic
schematic illustration
illustration of
of the
the APM
APM system,
system, which
which consists
consists of
of the
the
accesspoint
access point (router),
(router), sink
sink sensor
sensor node,
node, intermediate
intermediate sensor
sensor node,
node, and
and end
end sensor
sensornode.
node.
Allsensor
All sensornodes
nodesare
areplaced
placed inside
inside thethe building
building atat different
different locations
locations for
for inside
inside air
air quality
quality
monitoringexcept
monitoring exceptone;
one;one
oneofofthe
thesensor
sensor nodes
nodes is is placed
placed outside
outside thethe building
building forfor outdoor
outdoor air
air quality monitoring. The sensors associated with each sensing node
quality monitoring. The sensors associated with each sensing node monitor the air qualitymonitor the air
quality parameters
parameters inside andinside andthe
outside outside
buildingthe and
building anddata
transmit transmit
to thedata
roottosensor
the root sensor
node. The
node. picture
actual The actual
andpicture
the blockand the block
diagram of diagram
the sensor ofnode
the sensor nodein
are shown are shown8 in
Figures andFigures
9. All
8 and 9.
sensor All sensor
nodes nodes
consist consist module
of a sensor of a sensor module
(with (with
in-built in-built
Wi-Fi), Wi-Fi),
a power a powerand
module, mod-an
ule, and
MCU an MCU
controller controller module.
module.

Sustainability 2022, 14, x FOR PEER REVIEW


Figure8.8. Hardware
Figure Hardware implementation
implementation of the sensor node consisting
consisting of
of aa sensor,
sensor, an 12and
an MCU,
MCU, of 22
and aa
powermodule.
power module.

Figure9.9.Connection
Figure Connectiondiagram
diagramof
ofthe
thesensor
sensornode.
node.

4.2. Hardware
4.2.1. Sensor Selection
Sustainability 2022, 14, 16630 12 of 21

4.2. Hardware
4.2.1. Sensor Selection
Table 3 briefly describes gas sensors (MQ-135, MQ-2, and MQ7) [23] in terms of their
applications, concentration ranges, operating voltages, power consumptions, and interfaces
to the microcontroller unit. MQ series gas sensors are cheap and easy-to-find sensors
with different models that allow us to detect different kinds of gas. It is a metal oxide
semiconductor (MOS) type of gas sensor known as a chemi-resistor. The recognition is
founded upon the modification of the resistance of the detection quantifiable when the gas
originates during the interaction with the solid. Employing simple interface electronics (a
resistance to voltage conversion), the concentrations of gas are easily sensed. The output
voltage (in the analog form) provides the sensor with variations relative to the concentration
of smoke or gas. Here, the gas concentration is proportional to the measured output voltage.
MQ gas sensors work on 5 V DC. The output signal (in the analog form) from the MQ gas
sensor is further fed to the high-precision comparator (LM393) to convert to a digital form.
Also, the sensitivity of the sensor could be adjusted by using a tiny potentiometer which
could be used to tune the concentration of the gas.

Table 3. Specifications of MQ gas sensors.

Operating Power
Sensor Detects Concentration Interface
Voltage Consumption
10 ppm–1000 ppm (C6 H6 )
Air quality (benzene,
MQ-135 10 ppm–300 ppm (NH3 )
alcohol, NH3)
10 ppm–300 ppm (Alcohol)
Methane, butane, 300–10,000 ppm 5 V ± 0.1 750–900 mW Analog
MQ-2
LPG, smoke (combustible gas)
MQ-7 Carbon monoxide 20 ppm–2000 ppm (CO)

The parameters of the environmental sensor (BME280) and Laser PM2.5 Sensor
(HM3301) are also summarized in Table 4. BME280 is a small and low-power sensor
for measuring the relative humidity, barometric pressure, and ambient temperature pro-
duced from BOSCH, with an I2 C protocol and a wide operating voltage range appropriate
for various applications [24]. The Laser PM2.5 Sensor (HM3301) is a high-precision laser
dust detection sensor that could be used for continuous and real-time dust detection in
the air. The HM-3301 is based on the advanced Mie scattering theory [25]. The HM-3301
dust sensor is composed of the foremost components, such as an infrared (IR), the laser
source, a fan, a photosensitive tube, a condensing mirror, an amplifier, and an interface
electronics circuit.

Table 4. Specifications of PM2.5 and BME280.

Laser PM2.5 Sensor (HM3301)


Operating Power
Particle Size Resolution Range Interface
Voltage Consumption
2.5 µm, 5 µm,
1 µg/m3 1~500 µg/m3 3.3 V/5 V <375 mW I2C
10 µm
BME 280
Operating Power
Parameter Resolution Range Interface
Voltage Consumption
−40 ◦ C to
Temperature 0.01 ◦ C
+ 85 ◦ C
1.71–3.6 V 6.12–12.96 µW I2C
Humidity 0.008% RH 0 to 100 %RH
Pressure 0.18 Pa 300 to 100 hPa

Its stable output, ultra-low-power consumption, and little noise render it appropriate
for intelligent air purifiers, air conditioners, and other air quality-related IoT projects.
Sustainability 2022, 14, 16630 13 of 21

4.2.2. Wi-Fi-Enabled MCU Module


As per the requirements of an indoor or outdoor sensor module (analog ports and
the I2C interface) and wireless communication module, we selected an ESP32-DevKitC
microcontroller. MQ gas sensors require an MCU, which has analog inputs, whereas
BME280 and HM3301 need an I2 C interface. The ESP32-DevKitC V4 board is a low-power,
low-cost, Wi-Fi-enabled MCU produced by Espressif. This microcontroller offers 12-bit
SAR ADC (up to eight channels), three UART, and advanced communication interfaces: up
to two I2C and SPIs, etc. These features render the ESP32-DevKitC V4 board suitable for
this proposed APM system.

4.2.3. Power Module


The main purpose of this module is to power the sensor nodes. Two types of supply
voltage are required, 3.3 V for the BME280/HM3301 and 5 V for the MCU/MQ gas sensors.
A power converter board (220–5 V, 3-A) which converts a 220 V AC supply to 5 V DC,
was used to power the nodes. An ASM1117-3.3 IC was connected to the 5 V output and
converted into a 3.3 V DC.

4.3. Software
To smoothly create an ESP-MESH network with Wi-Fi-enabled boards (e.g., ESP-32,
ESP-8266, etc.), the PainlessMesh library was used [26]. By using the Painless MESH library,
a programmer could focus on a MESH network without having to be concerned with how
Sustainability 2022, 14, x FOR PEER the MESH network is managed or structured. The flowchart of the complete software
REVIEW 14 of is
22
shown in Figure 10.

Figure10.
Figure 10. Flowchart
Flowchartofofthe
thecomplete software,
complete including
software, a library
including for developing
a library the ESP-MESH
for developing the ESP-
network.
MESH network.

Alongwith
Along withthe
thePainless
PainlessMESH
MESHlibrary,
library,other
otherlibraries
librarieswere
werealso
alsoused
usedto to interface
interface the
the
sensors with the ESP32. The Adafruit_Sensor, Adafruit_BME280,
sensors with the ESP32. The Adafruit_Sensor, Adafruit_BME280, and Seeed_HM330X and Seeed_HM330X li-
braries were used to interface the temperature,
libraries temperature, humidity,
humidity,PM2.5,
PM2.5,gasgassensors,
sensors,etc. etc.
InInPainless
PainlessMesh,
Mesh,JSON
JSONobjects
objectswere
wereused
usedfor
forall
allthe
themessaging
messagingto to create
create and
and handle
handle
theJSON
the JSONstrings
stringswith
withthe
thehelp
helpofofthe
theArduino_JSON
Arduino_JSONlibrary.
library.After
Afterincluding
including the the required
required
libraries,
libraries,MESH
MESH details, such
details, suchas MESH_PREFIX,
as MESH_PREFIX, MESH_PASSWORD,
MESH_PASSWORD, and the
andMESHthe MESH port,
were
port,included. Users could
were included. Usersrandomly choosechoose
could randomly the MESH_PREFIX
the MESH_PREFIX and MESH_PASSWORD,
and MESH_PASS-
provided that all the
WORD, provided MESH
that all thenetwork nodes had
MESH network the had
nodes samethe credentials. The value
same credentials. Theof the
value
default MESH port
of the default MESH wasport
5555.
was 5555.
Several
Severalfunctions
functionswere
wereused in the
used Painless
in the MESH
Painless MESH library. The “get
library. The Readings”
“get Readings” () func-
()
tion collected
function the readings
collected of the sensor
the readings values,values,
of the sensor such assuch
the PM 2.5, PM
as the gas 2.5,
sensor,
gas temperature,
sensor, tem-
humidity,
perature, etc., and concatenated
humidity, all the sensor
etc., and concatenated values
all the sensor with a node
values withnumber
a node on a JSON
number on
variable called “JSON Readings”. The “send Message ()” function broadcasted
a JSON variable called “JSON Readings”. The “send Message ()” function broadcasted the JSON
the JSON string of the sensor values and node number (“get Readings ()” to all other
nodes in the MESH network). Using the task “send message”, the function “sends Mes-
sage ()” would be called every second as long as the program runs. Otherwise, several
callback functions (received Callback (), new Connection Callback (), changed Connec-
Sustainability 2022, 14, 16630 14 of 21

string of the sensor values and node number (“get Readings ()” to all other nodes in the
MESH network). Using the task “send message”, the function “sends Message ()” would
be called every second as long as the program runs. Otherwise, several callback functions
(received Callback (), new Connection Callback (), changed Connection Callback (), and
node Time Adjusted Callback ()) would be called when some event on the MESH happens.
Finally, to keep the MESH running repeatedly, a functioning MESH update () was
added to the loop ().

5. Results and Discussion


To measure the values of the different air quality parameters (temperature, humidity,
PM2.5, etc.), data was taken (every 2 min) from node C (the indoor data) and node H (the
Sustainability 2022, 14, x FOR PEER REVIEW
outdoor data), as shown in Figures 11–16. The parameters were continuously monitored15 of 22
Sustainability 2022, 14, x FOR PEER REVIEW 15 of 22
for
Sustainability 2022, 14, x FOR PEER REVIEW
a duration of 72 min from 8 am to 09.12 am. All data were successfully monitored
15 of 22
at
root node A. Moreover, the sink node could be connected to the Wi-Fi-enabled router to
send the data to the cloud.

Figure 11. Indoor (at node C) and outdoor temperature (at node H) for a duration of 72 min.
Figure 11. Indoor (at node C) and outdoor temperature (at node H) for a duration of 72 min.
Figure 11.
Figure Indoor(at
11. Indoor (at node
node C)
C) and
and outdoor
outdoor temperature
temperature (at
(at node
node H)
H) for
for aa duration
duration of
of 72
72 min.
min.

Figure 12. Humidity in %RH at nodes C and H, respectively.


Figure 12.Humidity
Figure12. Humidityin
in%RH
%RHat
atnodes
nodesCCand
andH,
H,respectively.
respectively.
Figure 12. Humidity in %RH at nodes C and H, respectively.

Figure 13. Gas


Figure 13. Gas concentrations
concentrations (methane, butane, LPG,
(methane, butane, LPG, smoke)
smoke) in
in terms
terms of
of ppm
ppm measured
measuredwith
withthe
the
MQ-2
Figuregas
MQ-2 13.sensor
gas at
atnodes
nodesCCand
Gas concentrations
sensor H.
(methane,
and H. butane, LPG, smoke) in terms of ppm measured with the
Figure
MQ-2 13.
gasGas concentrations
sensor (methane,
at nodes C and H. butane, LPG, smoke) in terms of ppm measured with the
MQ-2 gas sensor at nodes C and H.
Sustainability 2022, 14, 16630 15 of 21
Figure 13. Gas concentrations (methane, butane, LPG, smoke) in terms of ppm measured with the
MQ-2 gas sensor at nodes C and H.

Sustainability 2022, 14, x FOR PEER REVIEW 16 of 22


Sustainability 2022, 14, x FOR PEER REVIEW 16 of 22
Figure 14.
Figure Airquality
14. Air quality(benzene,
(benzene,alcohol,
alcohol,NH3)
NH3)ininterms
termsofofppm
ppmmeasured
measuredwith
withthe
theMQ-135
MQ-135gas
gas
sensor at nodes C and
sensor at nodes C and H.

Figure
Figure15.
15.Gas
Gasconcentration
concentration (carbon monoxide)ininterms
(carbon monoxide) termsofof ppm
ppm measured
measured with
with the the
MQ-7MQ-7 gas
gas sensor
Figureat15.
sensor Gas Cconcentration
nodes and H. (carbon monoxide) in terms of ppm measured with the MQ-7 gas
at nodes
sensor C and C
at nodes H.and H.

Figure 16. PM 2.5 in terms of µg/m3 at outdoor node H.


Figure 16. PM 2.5 in terms of µg/ m3 at outdoor node H.
Figure 16. PM 2.5 in terms of µg/ m3 at outdoor node H.
To verify the effectiveness of the ESP-MESH network for air quality monitoring, we
To verify the effectiveness of the ESP-MESH network for air quality monitoring, we
conducted
To verifyseveral tests with real-world
the tests
effectiveness deployments.
of the ESP-MESH network for air quality monitoring, we
conducted several with real-world deployments.
conducted several tests
5.1. Network Stability Test with real-world deployments.
5.1. Network Stability Test
To conduct
5.1. Network the Test
Stability performance and network stability test, the configuration shown in
To conduct the performance
Figure 1b was used. All seven nodes and network stability
were placed in antest,
openthe ground
configuration shown in
area (without any
Figure To1bconduct
was the
used. performance
All seven nodesand network
were placedstability
in an test,
open
wall or barrier between the nodes). Each node in the MESH network was programmed the configuration
ground area shown
(without anyinto
Figure
wall 1bone
was64
or barrier
transmit used.
between
Bytes All seven
the
data nodes
nodes).
package were
Each
per placed
node
minute infor in
the andays.
MESH
five opennetwork
groundwas areaprogrammed
(without any
wall or
to transmitbarrier between
onenode
The root 64 Bytes the
data
(which nodes).
package
acts Each node
per minute
as a traffic in
monitoring the MESH
for five network was programmed
days. recorded the data packages
receiver)
to transmit
fromThe theone
all root node
nodes64 Bytesthedata
(which
as actspackage per monitoring
as a traffic
performance minute
indicator. Theforstability,
five days.
receiver) as recorded
well as thethe data pack-
reliability of all
ages The
datafrom root node
all deliveries
packet (which
the nodes for as the acts
each as a traffic
performance monitoring
indicator.using
node, was evaluated receiver)
the raterecorded
The stability, aspacket
of the
well as data
the pack-
reliabil-
delivery (RPD):
ages
ity of from all the
all data nodes
packet as the performance
deliveries for each node,indicator. The stability,
was evaluated usingas well as the
the rate of reliabil-
packet
ity of all(RPD):
delivery data packet deliveries for each node, ∑ # Received
was evaluated
j using the rate of packet
RPDj =
delivery (RPD): ∑ # Expectedj
∑ # Received
RPD ∑ # Received
RPD ∑ # Expected
∑ # Expected
where RPDj is the rate of packet delivery of the ‘jth’ node during five days. # Received is
where
the RPDjof
number is packets
the rate atof the
packet delivery
center node,ofandthe# ‘jth’ node during
Expected five days.
is the number of #packets
Received thatis
the number of
should be received. packets at the center node, and # Expected is the number of packets that
should be received.
∑ # Received
Sustainability 2022, 14, 16630 16 of 21

where RPDj is the rate of packet delivery of the ‘jth’ node during five days. # Received is
Sustainability 2022, 14, x FOR PEER REVIEW
the number of packets at the center node, and # Expected is the number of packets that 17
should be received.
∑ # Received
Sustainability 2022, 14, x FOR PEER REVIEW Total_RPDd = d 17
∑d # Expected
whereThe results of
Total_RPDd thetotal
is the RPDi rateand Total_RPDd
of packet delivery offorall the five-day
the nodes during test
thearedthshown
day. in Fi
17 and The18.number
All theof nodes
expectedshowpackets was estimated
greater than 98% based
of onRPD,the particular
and all the node with aof the T
values
specific
RPDd Thearetransmission
results
nearlyof99%.interval
the RPDi
Both (60results
s). Instead
and of evaluating
Total_RPDd
show that the the
theparameters
fornetwork five-day of a specific
test
is stable are shown
and node, inHow
reliable. Fig
the Total_ RPDd provides an outline of the system stability of the time synchronization and
17a significant
and 18. All the nodes show greater than during
98% of theRPD, and all the values of the To
time-division network constraint
multiple-access (TDMA) may arise
routing. TDMA schedule’s flooding. D
RPDd are nearly
the simplicity
The results of99%.
of the
the RPDiBoth
andresults
architecture,
Total_RPDdshow that
oneforTDMA
the the network
schedule
five-day is stable
table
test are shown was
in and
flooded
Figures reliable.
17 andto Howe
18.each no
aour
significant
All present network
the nodesarrangement. constraint
show greater than may
Nonetheless, arise during
98% of RPD, flooding the
and all thethe TDMA
table
values schedule’s
necessitates
of the Total_ RPDd flooding.
the Du
aretransmi
the nearly 99%.
simplicity Both
of results
the show that
architecture, the network
one TDMA is stable and
schedule reliable.
of several packages over the network. This strategy could increase the setup table However,
was a significant
flooded to each nod
phase
our network
presentconstraint may
arrangement. arise during the TDMA schedule’s flooding. Due to the simplicity
head and impact the time Nonetheless,
synchronization. floodingOnce the
the table necessitatesisthe
synchronization transmisa
disrupted,
of the architecture, one TDMA schedule table was flooded to each node in our present
ofslot
several packages
mismatch
arrangement. would over
Nonetheless,
the
occur, network.
resulting
flooding
This strategy
in either
the table
could
missing
necessitates
increase (a
the packages
transmission
the setup
TX/RX
of
phase o
severalwindow
head
flict)and impact
over thethe
or package
packages time synchronization.
collisions
network. (a TXs
This couldOnce
windows
strategy thethe
conflict).
increase synchronization
setup phase overhead is disrupted,
and a
slot mismatch would occur, resulting in either missing packages (a TX/RX window
impact the time synchronization. Once the synchronization is disrupted, a time slot
mismatch
flict) would collisions
or package occur, resulting in either
(a TXs missingconflict).
windows packages (a TX/RX window conflict) or
package collisions (a TXs windows conflict).

Figure 17. Rate of packet delivery (RPD) for all seven nodes in an open area for the system st
Figure 17. Rate of packet delivery (RPD) for all seven nodes in an open area for the system
test.
stability test.
Figure 17. Rate of packet delivery (RPD) for all seven nodes in an open area for the system stab
test.

Figure 18. Total rate of the packet delivery (RPD) test for five days.
Figure 18. Total rate of the packet delivery (RPD) test for five days.

FigureIn
18.our future
Total rate ofwork, we would
the packet partition
delivery thefortable
(RPD) test according to the routing rou
five days.
stead of sending the complete network table to every node simultaneously. Each m
hopIn our in
route future work, we
the network would
would partition
obtain the tableTDMA
the required according to theonly.
schedule routing rout
This str
stead
wouldof drastically
sending theminimize
completethe
network
setup table
phasetooverhead
every node simultaneously.
time Each m
without compromisin
Sustainability 2022, 14, 16630 17 of 21

In our future work, we would partition the table according to the routing route instead
of sending the complete network table to every node simultaneously. Each multi-hop
route in the network would obtain the required TDMA schedule only. This strategy
would drastically minimize the setup phase overhead time without compromising the
network’s performance.

5.2. Power Consumption


Sustainability 2022, 14, x FOR PEER REVIEWThe power consumption depends on the contributing node’s location in the MESH
network hierarchy and the network’s topology type. For every cycle, all the active nodes
transmit a 64-byte data package, including the sensor readings.
As shown in Figure 19, all the nodes are associated with the ESP-MESH protocol.
For each TDMA scheduling cycle, node E transmits a single package via the ESP-MESH
totonode
node B, and
B, and node node B advances
B advances this
this package package
plus plus
its package its package
to node to node
A via the same A
ESP-MESH
ESP-MESH network.
network.

Figure
Figure 19. 19. Establishment
Establishment of thenetwork
of the MESH MESH for
network for the performance
the performance analysis
analysis of the campus- of th
scale deployment.
deployment.
The current was measured using a True RMS meter from Fluke. Each sensor node
(ESP32 The current
+ sensors) was measured
was powered using a True RMS meter from Fluke. Each
with 5 V DC.
Table 5 depicts the average current
(ESP32 + sensors) was powered with 5 V consumption of each
DC.node. The power consumption
of different nodes was determined by the number of receive/transmit windows. It is to be
Table
noted that 5 depicts
all the the average
nodes consumed current
nearly 500 consumption
mA of current, of to
which is due each node.
the use The pow
of the
tion
air of different
quality nodes
sensors (MQ-2, wasMQ-7,
MQ-135, determined by For
and HM3301). thelow-power
numberair ofquality
receive/transmit
sensors, w
the current consumption of the nodes would be low; in that case, the
to be noted that all the nodes consumed nearly 500 mA of current, which MESH network could
have a very acceptable expected battery life across all the nodes.
use of the air quality sensors (MQ-2, MQ-135, MQ-7, and HM3301). For l
quality sensors, the current consumption of the nodes would be low; in
MESH network could have a very acceptable expected battery life across a

Table 5. Average current consumption of each node.

Sensor Nodes Average Current Consumpti


A 470.80
Sustainability 2022, 14, 16630 18 of 21

Table 5. Average current consumption of each node.

Sensor Nodes Average Current Consumption (mA)


A 470.80
H 552.10
E, F, G 462.10
B, D, C 481.80

5.3. Campus Deployment


For campus deployment, we used a college campus of a 100 m by 80 m area to place
the sensor nodes (seven nodes) at different locations. All eight deployed nodes were
continuously working for a duration of five days. A complete MESH network, shown in
Figure 19, was established for the performance analysis of the campus-scale deployment.
For the deployed network, the actual ESP-MESH link is represented by a solid line, whereas
the dotted lines represent the available links (which are not being used). The furthest node
(H) was placed 100 m away from the root node (A) and across more than four buildings
and walls.
For the evaluation of the MESH network, a 64 Byte package was transmitted for five
days at two-minute intervals, i.e., a total of 3600 (5 days × 24 h × 60 min/2 min) packages
were anticipated to transmit from each node.
The effectiveness of the network was analyzed by evaluating the rate of packet delivery
(RPD), package loss rate (PLR), and package fault rate (PFR) of all the active nodes. Similar
to the RPD, the PFR depends on the number of faulty packages, and the PLR relies on the
number of lost packages:
∑ # Faultj
PFRj =
∑ # Expectedj
∑ # Expectedj − ∑ # Receivedj
PLRj =
∑ # Expectedj
Based on the received and expected packages for each node (seven nodes), an end-to-
end RPD, PLR, and PFR are shown in Figure 20. From Figure 20a, it can be seen that the
ESP-MESH network accomplishes more than 97% RPD, except for node H. Moreover, the
PER and PLR (see Figure 20b,c) for each active node are under the limit (less than 1.8%)
except for node H. Node H showed values of a higher PER and PLR (>1.8%); we suspect
it might be due to its outdoor location. These results show that the ESP-MESH network
offers a considerably good quality of service, mainly for medium-area networks [26–28].
5.4. Evaluation of the Performance
To confirm the effectiveness of the ESP-MESH network protocol, some important
performance parameters were recorded. To measure the healing time after the sink node
and intermediate node failure, we disconnected the power supply of a node (the sink and
intermediate node) arbitrarily and measured the time spent. After many tests, several
typical values were taken out. The experimental results are shown in Table 6.

Table 6. Performance of the ESP-MESH protocol.

Performance Parameter Time Spent


Network-building time 17.32 s
Healing time after the sink node failure 4.18 s
Healing time after the intermediate node failure 3.46 s
to-end RPD, PLR, and PFR are shown in Figure 20. From Figure 20a, it can be seen that
the ESP-MESH network accomplishes more than 97% RPD, except for node H. Moreover,
the PER and PLR (see Figure 20b,c) for each active node are under the limit (less than
1.8%) except for node H. Node H showed values of a higher PER and PLR (>1.8%); we
suspect it might be due to its outdoor location. These results show that the ESP-MESH
Sustainability 2022, 14, offers
network 16630 a considerably good quality of service, mainly for medium-area networks 19 of 21
[26–28].

(a)

(b)

(c)
Figure 20. (a) Rate of packet delivery
Figure (RPD),
20. (a) Rate of (b) package
packet fault(RPD),
delivery rate (PFR), and (c) fault
(b) package package
rateloss rateand (c) package loss rate
(PFR),
(PLR) of all the active nodes for the five days of campus deployment.
(PLR) of all the active nodes for the five days of campus deployment.

6. Conclusions
In the recent developments of wireless protocols (Zig-Bee, Wi-Fi, LoRa, etc.), the ESP-
MESH networking protocol is low-cost, easy to implement, medium-range, and low-power
option. This protocol does not require any internet connection to create a wireless network.
Compared to LoRa, this protocol has a low range but is easy to implement. Devices used
to establish the ESP-MESH network are very cheap in cost. In this work, we successfully
established an ESP-MESH network that permits abundant sensor nodes spread over a large
physical area to be consistent under a single WLAN for accurately measuring air quality
and detecting air pollution events and sensors’ abnormal operations. First, we designed
and developed system hardware, which contained a gateway, a base station, and sensors
to collect indoor and outdoor air quality measurements. Then, the system software was
intended to allow for data acquisition, processing, transmission, and energy conservation
approaches for the complete system.
Moreover, a custom time-division multiple-access (TDMA) scheduling scheme for
energy efficiency was applied to construct an appropriate transmission schedule that
reduces the end-to-end transmission time from the sensor nodes to the router. To confirm
Sustainability 2022, 14, 16630 20 of 21

the effectiveness of the network, data were taken from different air quality parameters
(temperature, humidity, PM 2.5, gas concentrations, etc.) every 2 min from the indoor
node and outdoor node and continuously monitored for a duration of 72 min from 8 am to
09.12 am. The network-building time, healing time after sink node failure, and intermediate
node failure were recorded as 17.32 s, 4.18 s, and 3.46 s, respectively. Additionally, the
experiment of the sensor accuracy measurement in real physical activity was provided.
Finally, the performances of the communication interfaces were assessed, including the
package loss rate (PLR), package fault rate (PFR), and rate of packet delivery (RPD). The
results showed that the ESP-MESH network accomplished more than 97% of most nodes’
RPDs. Also, the PMR and PER for each active node were under the limit (less than 1.8%).

Author Contributions: Conceptualization, A.U.K., M.E.K. and T.I., methodology, A.U.K.; software,
A.U.K.; validation, A.U.K., M.E.K. and M.H.; formal analysis, W.Z.; investigation, W.A.; resources,
W.Z.; writing—original draft preparation, A.U.K.; writing—review and editing, A.U.K. and M.E.K.
All authors have read and agreed to the published version of the manuscript.
Funding: This research was funded by the Deputyship for Research & Innovation, Ministry of
Education in Saudi Arabia, project number ISP20-25.
Institutional Review Board Statement: Not applicable.
Informed Consent Statement: Not applicable.
Acknowledgments: The authors extend their appreciation to the Deputyship for Research & Inno-
vation, Ministry of Education in Saudi Arabia for funding this research work through the project
number ISP20-25.
Conflicts of Interest: The authors declare no conflict of interest.

References
1. Postolache, O.A.; Pereira, J.M.D.; Girao, P.M.B.S. Smart sensors network for air quality monitoring applications. IEEE Trans.
Instrum. Meas. 2009, 58, 3253–3262. [CrossRef]
2. Leung, D.Y.C. Outdoor-indoor air pollution in urban environment: Challenges and opportunity. Front. Environ. Sci. 2015, 2, 69.
[CrossRef]
3. Kang, J.; Hwang, K.-I. A comprehensive real-time indoor air-quality level indicator. Sustainability 2016, 8, 881. [CrossRef]
4. Bartolomeo, J. Detecting CO in the home. Home Autom. Build. Cont. 1995, 51, 55.
5. Pandey, Y.; Hasan, N.; Husain, M.A.; Khan, A.N.; Bakhsh, F.I.; Minai, A.F. Tabrez An Environment Friendly Energy-Saving
Dispatch Using Mixed Integer Linear Programming Relaxation in the Smart Grid with Renewable Energy Sources. Distrib. Gener.
Altern. Energy J. 2022, 37. [CrossRef]
6. Kuo, H.-W.; Shen, H.-Y. Environment. Indoor and outdoor PM2. 5 and PM10 concentrations in the air during a dust storm. Build.
Environ. 2010, 45, 610–614. [CrossRef]
7. Meadow, J.F.; Altrichter, A.E.; Kembel, S.W.; Kline, J.; Mhuireach, G.; Moriyama, M.; Northcutt, D.; O’Connor, T.K.; Womack,
A.M.; Brown, G. Indoor airborne bacterial communities are influenced by ventilation, occupancy, and outdoor air source. Indoor
Air 2014, 24, 41–48. [CrossRef] [PubMed]
8. Fung, C.-C.; Yang, P.; Zhu, Y. Infiltration of Diesel Exhaust into a Mechanically Ventilated Building. Indoor Air 2014—13th
International Conference on Indoor Air Quality and Climate. 1 January 2014; pp. 556–558. Available online: https://www.
researchgate.net/publication/286809739_Infiltration_of_diesel_exhaust_into_a_mechanically_ventilated_building (accessed on
10 August 2022).
9. Tran, T.V.; Dang, N.T.; Chung, W.-Y.J.S.; Chemical, A.B. Battery-free smart-sensor system for real-time indoor air quality
monitoring. Sens. Actuators B Chem. 2017, 248, 930–939. [CrossRef]
10. Zanella, A.; Bui, N.; Castellani, A.; Vangelista, L.; Zorzi, M. Internet of things for smart cities. IEEE Internet Things J. 2014, 1, 22–32.
[CrossRef]
11. Kumar, A.; Singh, I.; Sud, S. Indoor environment gas monitoring system based on the digital signal processor. In Proceedings
of the 2009 International Multimedia, Signal Processing and Communication Technologies, Aligarh, India, 14–16 March 2009;
pp. 245–249.
12. Abraham, S.; Li, X. A cost-effective wireless sensor network system for indoor air quality monitoring applications. Procedia
Comput. Sci. 2014, 34, 165–171. [CrossRef]
13. Ahmed, M.M.; Banu, S.; Paul, B. Real-time air quality monitoring system for Bangladesh’s perspective based on Internet of
Things. In Proceedings of the 2017 3rd International Conference on Electrical Information and Communication Technology
(EICT), Khulna, Bangladesh, 7–9 December 2017; pp. 1–5.
Sustainability 2022, 14, 16630 21 of 21

14. Firdhous, M.; Sudantha, B.; Karunaratne, P. IoT enabled proactive indoor air quality monitoring system for sustainable health
management. In Proceedings of the 2017 2nd International Conference on Computing and Communications Technologies
(ICCCT), Chennai, India, 23–24 February 2017; pp. 216–221.
15. Lee, C.-L.; Lee, J.-S. Development of indoor air quality supervision systems using zigbee wireless networks. In Proceedings of the
2018 13th IEEE Conference on Industrial Electronics and Applications (ICIEA), Wuhan, China, 31 May–2 June 2018; pp. 95–98.
16. Bamodu, O.; Xia, L.; Tang, L.J. An indoor environment monitoring system using low-cost sensor network. Energy Procedia 2017,
141, 660–666. [CrossRef]
17. Alhmiedat, T.; Samara, G. A low cost ZigBee sensor network architecture for indoor air quality monitoring. Netw. Internet Archit.
2017, 15, 140–144. [CrossRef]
18. Apte, J.S.; Brauer, M.; Cohen, A.J.; Ezzati, M.; Pope, C.A., III; Letters, T. Ambient PM2. 5 reduces global and regional life
expectancy. Environ. Sci. Technol. Lett. 2018, 5, 546–551. [CrossRef]
19. Systems, E. ESP-WIFI-MESH. Available online: https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/esp-
wifi-mesh.html (accessed on 10 August 2022).
20. Wang, E.; Xiao, L.; Han, X.; Tan, B.; Luo, L. Design of an Agile Training System Based on Wireless Mesh Network. IEEE Access
2022, 10, 84302–84316. [CrossRef]
21. Glória, A.F.; Sebastião, P.J. Autonomous configuration of communication systems for IoT smart nodes supported by machine
learning. IEEE Access 2021, 9, 75021–75034. [CrossRef]
22. Pantazis, N.A.; Vergados, D.J.; Vergados, D.D.; Douligeris, C.J.A.H.N. Energy efficiency in wireless sensor networks using sleep
mode TDMA scheduling. Ad Hoc Netw. 2009, 7, 322–343. [CrossRef]
23. Dorcea, D.; Hnatiuc, M.; Lazar, I. Acquisition and calibration interface for gas sensors. In Proceedings of the 2018 IEEE 24th
International Symposium for Design and Technology in Electronic Packaging (SIITME), Iasi, Romania, 25–28 October 2018;
pp. 120–123.
24. Shevchenko, G.V.; Glubokov, N.A.; Yupashevsky, A.V.; Kazmina, A.S. Air Flow Sensor Based on Environmental Sensor BME280.
In Proceedings of the 2020 21st International Conference of Young Specialists on Micro/Nanotechnologies and Electron Devices
(EDM), Chemal, Russia, 29 June–3 July 2020; pp. 432–435.
25. Trilles, S.; Vicente, A.B.; Juan, P.; Ramos, F.; Meseguer, S.; Serra, L. Reliability validation of a low-cost particulate matter IoT sensor
in indoor and outdoor environments using a reference sampler. Sustainability 2019, 11, 7220. [CrossRef]
26. Santos, L.; Costa, T.; Caldeira, J.M.; Soares, V.N. Performance Assessment of ESP8266 Wireless Mesh Networks. Information 2022,
13, 210. [CrossRef]
27. Guo, Z.; Ma, X.; Zhang, P.; Liu, Z. A dust sensor monitoring system using Wi-Fi mesh network. J. Phys. Conf. Ser. 2021,
1754, 012129. [CrossRef]
28. Arjadi, R.H.; Setyaningsih, E.; Wibowo, P.; Sudrajat, M. Performance evaluation of ESP8266 mesh networks. J. Phys. Conf. Ser.
2019, 1230, 012023.
Copyright of Sustainability (2071-1050) is the property of MDPI and its content may not be
copied or emailed to multiple sites or posted to a listserv without the copyright holder's
express written permission. However, users may print, download, or email articles for
individual use.

You might also like