An Efficient Wireless Sensor Network Based on the ESP-MESH Protocol for Indoor and Outdoor Air Quality Monitoring

As part of the first step, the hardware platform for the air quality sensors, which includes 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;

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:

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.

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 NH), methane, butane, LPG, smoke, and carbon monoxide.

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 CHand 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 Oonly, based on the IoT technology.

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 advancement of IoT technology, information communication technology (ICT), and sensor technology [ 10 ]. In [ 11 ], Kumar et al. proposed an inexpensive indoor pollution gas monitoring 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 COgas concentrations with a deviation of ±5% from the standard data set.

The effects of poor air quality could be felt immediately, even after exposure to pollutants 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.

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.

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 ].

Contamination inside our homes is also considered an alarming issue, as well in offices and schools. Indoor actions, such as smoking and cooking, could create impurities. Typically, in manufacturing nations, the inhabitants devote approximately 80–90% of their time inside houses and are consequently exposed to detrimental interior contaminants. Indoor air quality is commonly evaluated by distinctly gauging the CO, temperature, and humidity [ 4 ]. These statistics, even if merged, are deficient in permitting a good depiction of the inside air quality.

Air quality could be articulated by the absorption of numerous pollutants, such as carbon NOx, SO, O, 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 ].

The oxygen present in the air is essential for human life. The air combines oxygen, nitrogen, inert gases, and water vapor. In the atmosphere, human actions release unwanted elements, some of which could be the source of complications for living beings (plants, humans, and animals). Polluted air also affects plant growth in precision agriculture [ 1 ].

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.

The newly chosen sink node sends a switch request to the existing sink node, and the current sink node responds with an indication that it is prepared to switch. Upon receiving the answer, the newly chosen sink node would separate from its parent node and instantly establish an uplink connection to the router, becoming a new sink node in the network. The initial sink node would detach from the router while 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.

The ESP-MESH protocol does not switch the sink node automatically until the root node fails. The sink node would stay unaffected even if its router RSSI declines to the point of disconnection. Sink node switching is actively initiating a fresh election in which a node with a stronger router RSSI is chosen as the new sink node. This may be an effective strategy for adjusting to the deteriorating sink node performance. When the existing network requires a sink switch, the sink node must explicitly use the “esp_mesh waive_sink()” function to initiate a fresh election. At this time, the sink node would request that all other nodes in the network transmit and scan the beacon frames through a broadcast, after which it would stay networked. If another node wins more votes than the current sink node, the sink switching procedure would begin; otherwise, the sink node would remain unaltered.

If the network started up simultaneously, node D would have been the root since its router RSSI is the highest (−10 dB). To put it another way, the network architecture built under synchronous power on circumstances would look quite different from the one produced under asynchronous power on conditions.

Condition 3: If an idle node has a specified intermediate node that is delayed when switching on, it would not try to create any upstream links in the lack of its specified intermediate node. The inactive node would stay inactive forever until its assigned intermediate node arrives.

Condition 2: When a delayed node establishes an upstream link and becomes an intermediate node, it may also become the favored intermediate of the adjacent nodes. It would result in the neighboring nodes switching their upstream links to join the delayed node.

Condition 1: If there is an existing sink node in the network, the delayed node would not try to vote in a new sink node, even if it had a greater RSSI. Instead, the delayed node would connect to a suitable intermediary node and join the network as any idle node would. If the delayed node is the assigned sink node, all other network nodes would remain inactive until it activates.

The sequence in which nodes the switch on may influence the formation of the ESP-MESH networks. If specific nodes within the network turn on asynchronously (i.e., delayed by a few minutes), the network’s final configuration may vary from the ideal scenario in which all nodes turn on synchronously. The following conditions would apply to nodes that are delayed when powering on:

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.

If the sink node and many descending layers subsequently failed (for example, the root node, second layer, and third layer), the shallowest layer that was still operational would initiate the root node election. Figure 5 demonstrates the self-healing mechanism after a root node failure. Sink node A would attempt to reconnect if it becomes disconnected. The second layer nodes initiate the voting process by transmitting their RSSIs after numerous unsuccessful attempts to rejoin. Node D’s router RSSI is the greatest. Node D is chosen as the sink node and starts to accept the downstream links. The other nodes on the second layer, B and C, establish upstream links with node D, restoring the network to regular operation.

If the sink node breaks down, the nodes connected with it would promptly detect the failure of the sink node. The second layer nodes would initially attempt to reconnect with the sink node. Nonetheless, after numerous unsuccessful attempts, the second layer nodes would initiate a fresh round of sink node election. The second layer node with the highest router RSSI would be selected as the new sink node, while the other second layer nodes would establish an upstream link with the newly chosen sink node.

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.

The administrator may also nominate the sink node, which would result in the specified 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.

The threshold for the vote percentage may also be set using the “esp_mesh_set_vote_percentage()” function. Setting a low vote threshold percentage may result in two or more nodes becoming sink nodes in the same ESP-MESH network, forming several networks. If such is the case, the ESP-MESH provides internal capabilities to resolve the sink node disagreement autonomously. Multiple sink node networks would be merged into a single network with a single sink node. In addition, setting a small number of iterations and a low voltage threshold percentage might cause network instability owing to RSSI variations [ 19 21 ].

Using the “esp_mesh_set_attempts()” function, the minimum number of election process iterations may be configured. Users must modify the number of iterations dependent on the number of network nodes (i.e., the more extensive the network, the greater the necessary number of scan iterations).

The sink node may be automatically set up or chosen by the administrator. The signal intensities of all idle nodes relative to the router determine the automatic selection of a sink node. Each idle node would send its addresses (MAC) and router RSSI values through Wi-Fi beacon packets. Then, every node concurrently scans for beacon packets from other idle nodes. If a node identifies a beacon packet with a greater router RSSI, it would initiate sending the frame’s information. The broadcast and scanning procedure would continue for a predetermined minimum number of iterations (10 iterations is 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.

The following diagram shown in Figure 3 represents the arrangement of an ESP-MESH packet and its linkage with a Wi-Fi data frame. The header contains the media access control (MAC) addresses for both the transmitter and receiver nodes. The actual data are available in the payload of the MESH packet. The payload of an ESP-MESH packet comprises the definite application data and may contain either encoded data (MQTT, JSON, and HTTP) or raw binary data.

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 2 b). 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 2 b). 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.

A network of ESP-MESH nodes may consist of three types: the sink node, the intermediate 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 1 b.

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.

The ESP-MESH overcomes the limitations of outdated infrastructure Wi-Fi networks in such a way that in ESP-MESH, the nodes are free to connect with their nearby nodes (there is no need to connect to a central node), shown in Figure 1 b. Each node is commonly accountable for communicating with each other’s transmissions. This results in the ESP-MESH network covering a considerably better exposure area without requiring it to be in the range of the central node. Also, ESP-MESH seems to be less prone to congestion as there is no requirement for any node to connect the single central node.

By using the ESP-MESH protocol, a huge number of Wi-Fi-enabled devices (e.g., ESP-32, ESP-8266, etc.) could be interconnected beneath a single wireless local-area network (WLAN) over a wide physical area. The main feature of this protocol is its self-healing and self-organizing property (the network could be built and sustained independently). The main disadvantages of the outmoded Wi-Fi network substructure are (1) the limited coverage area with the single access point shown in Figure 1 a and (2) overloading (the capacity limitation of the access point).

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 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 solution 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 network ( Figure 1 b).

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.

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

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 1 b) transmits the above information to the root node, which uses Algorithm 1 outlined in the pseudo-code.

As illustrated in Table 1 , a “node-list” structure is produced for the network shown in Figure 1 b. 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.

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 1 b:

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 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” are populated in slot two against nodes G and C in Table 2 . The “set-send-colsn” list is now {A, B, C, F, G} and “set-recv-colsn” is {C, F, H}. The “Recv” term of dest node C becomes zero.

The dest node for node E is B, and the “Recv” term is zero. Both nodes E and B are absent from the preceding “set-send-colsn” and “set-recv-colsn” lists; thus, slot two is populated with them. Table 2 is populated with “S” and “R” against 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 which point the node list is emptied. The first investigated node for each slot is always inserted due to the algorithm’s execution. Therefore, the procedure concludes when the planned slot has no nodes. Table 2 displays the resultant slot positions.