Grid-Based Routing Model for Energy Efﬁcient and Secure Data Transmission in WSN for Smart Building Applications

: Presently, due to the establishment of a sensor network, residual buildings in urban areas are being converted into smart buildings. Many sensors are deployed in various buildings to perform different functions, such as water quality monitoring and temperature monitoring. However, the major concern faced in smart building Wireless Sensor Networks (WSNs) is energy depletion and security threats. Many researchers have attempted to solve these issues by various authors in different applications of WSNs. However, limited research has been conducted on smart buildings. Thus, the present research is focused on designing an energy-efﬁcient and secure routing protocol for smart building WSNs. The process in the proposed framework is carried out in two stages. The ﬁrst stage is the design of the optimal routing protocol based on the grid-clustering approach. In the grid-based model, a grid organizer was selected based on the sailﬁsh optimization algorithm. Subsequently, a fuzzy expert system is used to select the relay node to reach the shortest path for data transmission. The second stage involves designing a trust model for secure data transmission using the two-ﬁsh algorithm. A simulation study of the proposed framework was conducted to evaluate its performance. Some metrics, such as the packet delivery ratio, end-end delay, and average residual energy, were calculated for the proposed model. The average residual energy for the proposed framework was 96%, which demonstrates the effectiveness of the proposed routing design. of iterations and throughput values in the X- and Y-axes, respectively. The throughput of the proposed method was 23.48%, 4.02%, 2.68%, and 2.01% higher than those of EEGRA, I-LEACH, EBAR, and ER-SRP, respectively. These two comparison studies demonstrate the effectiveness of the proposed routing approach in comparison with existing routing techniques.


Introduction
Advancements in the field of information communication technology have paved the way for the establishment of WSNs [1,2]. Generally, WSNs consist of tiny and low-cost sensors whose major function is to sense information from a particular environment and transmit it through a wireless network to the monitoring zone. WSNs have a wide range of applications in various fields such as defense, agriculture, healthcare, smart cities, smart building emergency rescue, and vehicular applications. The main processing unit in the sensors is a battery [3,4] for the effective functionality of sensor node. The batteries are powered with minimum energy owing to the minor nature of the sensor nodes. At the same time, it is very complex to replace the sensors once they are deployed. Therefore, energy efficiency is a major concern in WSNs [5]. Previous research on WSNs has shown that significant energy is consumed during data transmission. This transmission process relies mainly on routing protocols. Thus, it is essential to design an energy-efficient routing strategy to reduce energy consumption, thereby improving the network lifetime [6,7].

•
To design a grid-based network structure for attaining energy conservation and securing data transmission in smart building WSNs. • An optimal routing path selection based on a fuzzy interference system attains an enhanced packet delivery ratio.

•
To select the best grid organizer, a meta-heuristic algorithm, namely the sailfish optimizer, was utilized.

•
For the optimal selection of the grid organizer, the residual energy and distance were considered as objective functions. • A two-fish encryption algorithm is used to achieve trust-based routing.
The remainder of the manuscript is organized as follows: Section 2 reviews articles related to various routing approaches in WSNs. Section 3 discusses the background of the proposed methodology. A detailed explanation of the proposed framework is provided in Section 4. Section 5 presents the results obtained through the implementation. Finally, Section 6 concludes the study.

Literature Review
In recent years, many researchers have developed various routing protocols to minimize energy consumption and to improve the network lifetime. Some of the articles related to various routing approaches in WSNs are reviewed below.
Sinde et al. [16] designed Energy-Efficient Scheduling using the Deep Reinforcement Learning (DRL) (E 2 S-DRL) algorithm in WSNs. E 2 S-DRL contributes three phases to prolong network lifetime and to reduce network delay: clustering, duty-cycling, and routing phases. E 2 S-DRL's clustering phase reduces the energy consumption incurred during data aggregation. This was achieved through a Zone-based Clustering (ZbC) scheme. In the ZbC scheme, hybrid Particle Swarm Optimization (PSO) and Affinity Propagation (AP) algorithms were utilized.
Sonam Lata et al. [17] designed the LEACH-Fuzzy Clustering (LEACH-FC) protocol and implemented a fuzzy logic-based cluster head selection and cluster formation to maximize the network's lifetime. For the selection of cluster head and cluster formation, a centralized approach was used instead of distributed ones, and fuzzy logic was employed to select the vice cluster head.
Ramprakash et al. [18] designed an efficient routing mechanism called power-aware energy-efficient routing (PAEER) to meet the network lifetime. The maximization and energy efficiency in WSNs and the different contributions of the PAEER approach are: (a) the multi-sink node approach which can lead to an increase in the node network lifetime 3 of 22 and event detection mechanism that meets the reliability requirement of the WSNs; and (b) using the PAEER mechanism, the data are sent to the sink node by covering multipath routes to aggregate the node data.
Dowlatshahi et al. [19] designed an energy-optimized algorithm. Owing to the heterogeneity of the sensor nodes in the WSNbased Internet of Things(IoT) for smart cities, one approach for scheduling the sensing activity is to cluster the sensors intoKmutually different subsets in such a way that every subset of sensors alone can cover all targets of the network. In this case, finding the maximum number of sensor subsets, or equivalently, the sensor covers the problem by converting it to the SET K-COVER problem. To solve the SET K-COVER problem, the proposed Grouping Memetic Algorithm (GMA) is proposed.
Ifzame et al. [20], aimingto reduce communication costs and resilience against different WSNs security attacks, used a Paillier Cryptosystem and Compressive Sensing-based Routing (PC 2 SR) to design three mechanisms: a pallier cryptosystem-based vital for distribution and management, intra-cluster data gathering, and secure data transmission. The PC 2 SR provided a pallier security key to each device for data authentication.
Neelam Sharma et al. [21], aimed to develop a protocol architecture that can extend network lifetimes, balance, and reduce the energy consumption of networks, reduce redundancy, and increase information validity and integrity. P Maheshwari et al. [22] discussed minimizing the overall energy consumption and maximizing the network lifetime. In this study, the Butterfly Optimization Algorithm (BOA) is employed to choose an optimal cluster head from a group of nodes. The performance measures of the proposed methodology are analyzed in terms of alive nodes, dead nodes, energy consumption, and data packets received by the BS. The disadvantage is the latency.
Alghamdi et al. [23] attempted to develop a new clustering model with optimal cluster head selection by considering four major criteria: energy, delay, distance, and security. Furthermore, to select the optimal CHs, this paper proposes a new hybrid algorithm that hybridizes the concept of dragon fly and firefly algorithms, termed fire fly re-placed position update in dragonflies.
AAH Hassan et al. [24] proposed an improved energy-efficient clustering protocol (IEECP) to prolong the lifetime of a WSN-based IoT. P Rawat et al. [25] proposed a clustering protocol named Energy Efficient Clusterhead Selection Scheme (ECSS). The proposed protocol is designed for a heterogeneous environment and aims to minimize energy usage in the network, thereby improving the lifespan of the network.
Joonyoung Lee et al. [26] presented a secure and efficient authentication protocol based on a three-factor authentication by taking advantage of biometrics and used a honeylist technique to protect against brute force and stolen smartcard attacks. By using the honey-list technique and three factors, the proposed protocol can provide security even if two of the three factors werecompromised. Q Shi et al. [27] proposed a new secure routing protocol for WSNs in the presence of malicious nodes. For each relay node in the route, associated information, such as its trust value and status, areconsidered in the protocol. V Sivasankarareddy et al. [28] describes surveying extraordinary different optimization techniques below the multi-objective facet that takes the region in tradeoffs. Information extracting in sensing unit networks is the technique of obtaining software-enabled plans in addition to patterns with gratifying accuracy from a constant, speedy, perspective in addition to a probable non-ended flow of facts streams from sensor networks. V Sivasankarareddy et al. [29] proposes that Vitality safety is the primary concern in many of the implementations in remote sensor hubs.This is criticalas the improvement in the life time of the device depends primarily on restricting the usage of vitality in sensor hubs.

Background of Proposed Methodology
A Wireless Sensor Network (WSN) is an emerging communication technology that impressed its footprint in almost every field of application. Recently, this sensor network has been utilized in urban areas to monitor living environments. The inclusion of wireless communication in these urban areas has transferred it to smart cities. The present research focuses on the deployment of WSNs with better security and energy efficiency in smart building applications. The crucial constraints faced in any type of sensor network are security and efficient energy. Many scholars have designed an enormous routing protocol to achieve efficient energy and security. The clustering method is the most commonly used approach for framing routing protocols in WSNs. However, this traditional clustering has limitations, such as complexity, time consumption, and difficulty in achieving an improved packet delivery ratio. The proposed architecture is designed based on grid clustering to attain energy-organized and trust-based routing for achieving enhanced data transmission in WSNs for smart building applicationsto overcome these limitations. The basic architecture of the proposed WSN framework for smart city applications is shown in Figure 1. TheWSN framework designed specifically for smart building applications is illustrated in the previous diagram. The proposed routing model was processed in two phases. An energy-efficient routing protocol is designed in the first phase, and in the second phase, a trust-based algorithm is included to enhance data security. The process carried out in the first phase is explained as follows: The initial step considered in any type of WSN is node deployment. Approximately eight sensor nodes that perform various functions, including temperature and air monitoring, were deployed in each building. The nodes deployed in each building were considered to be static. The primary purpose of each deployed node is to transmit the sensed information to the base station and from the base station to the server via the gateway for monitoring. Data transmission in the proposed study was performed using a grid-based clustering approach. In this approach, the formation of grids with the help of the deployed nodes was initially achieved. The grid organizer is elected using the sailfish optimizer in the second step, and the best relay node is selected using a fuzzy expert system to design the optimal routing protocol in the third step. In the second phase, a two-fish encryption algorithm is introduced to enhance the security of the transmitted data. The stepwise process involved in the proposed framework is briefly described in the following section.

Sensor node deployment in building
Grid formation based on communication range Election of grid organizer based on sailfish optimizer In this approach, the formation of grids with the help of the deployed nodes was initially achieved. The grid organizer is elected using the sailfish optimizer in the second step, and the best relay node is selected using a fuzzy expert system to design the optimal routing protocol in the third step. In the second phase, a two-fish encryption algorithm is introduced to enhance the security of the transmitted data. The stepwise process involved in the proposed framework is briefly described in the following section.

Stepwise Process Enclosed in Proposed Research
The proposed framework is designed mainly to improve sensor networks' energy efficiency and security in smart building applications. As explained previously, the performance of WSNs is hampered mainly by energy depletion and various malicious attacks. Therefore, the proposed framework is developed in two stages to improve the performance of WSNs in residential buildings. In the first stage, an optimal routing protocol is designed to overcome the issue of energy depletion, and in the second stage, a trust-based model is introduced to overcome the security threat during data transmission. The two stages enclosed in the proposed architecture are described in the next section. Initially, the design of the network model is explained as follows.

System Model
Initially, for experimental purposes, a building located within 1000 × 1000 m 2 is considered. The major sensors considered within a smart building are contact, electric current monitoring, temperature, motion, air quality, water quality, humidity, and smoke sensors. The design of the network structure is illustrated in Figure 2. Based on this network structure, some assumptions were made, which are explained as follows.


The weights and energies were 100 g and 10 J, respectively, and were similar for every deployed node.  The nodes in one grid can communicate with the nodes in the neighboring grid in only a single hop.

First Stage: Design of Optimal Routing Protocol
The optimal routing protocol is designed using a grid-based clustering and fuzzy expert system to address the limitations of energy depletion in smart building WSNs. The sequence of steps starting from grid formation until relay node selection is described in this section.

Node Deployment in Building
The first and most significant process in any WSN is node deployment. Eight different sensors were deployed in a building to sense various types of information. The eight sensors deployed in a building include contact, electric current monitoring, temperature, motion, air quality, water quality, humidity, and smoke sensors. Generally, the node that is referred to as the source node initiates communication by broadcasting a Route Request (RREQ) packet to every node [30]. This RREQ packet contains specific details such as ID, source IP address, destination IP address, and location. The nodes within the communication limit will receive this RREQ packet and reply with the Route Reply (RREP) packet, which contains ID, location, and lifetime information. The ultimate

•
Every sensor node is deployed randomly, and there is no significant pattern for node deployment.

•
The deployed nodes were assumed to be static and not in motion.

•
The base station is located within any one of the grids. • A battery powers each node, and once the battery is depleted, the specified node is left over.

•
The weights and energies were 100 g and 10 J, respectively, and were similar for every deployed node.

•
The nodes in one grid can communicate with the nodes in the neighboring grid in only a single hop.

First Stage: Design of Optimal Routing Protocol
The optimal routing protocol is designed using a grid-based clustering and fuzzy expert system to address the limitations of energy depletion in smart building WSNs. The sequence of steps starting from grid formation until relay node selection is described in this section.

Node Deployment in Building
The first and most significant process in any WSN is node deployment. Eight different sensors were deployed in a building to sense various types of information. The eight sensors deployed in a building include contact, electric current monitoring, temperature, motion, air quality, water quality, humidity, and smoke sensors. Generally, the node that is referred to as the source node initiates communication by broadcasting a Route Request (RREQ) packet to every node [30]. This RREQ packet contains specific details such as ID, source IP address, destination IP address, and location. The nodes within the communication limit will receive this RREQ packet and reply with the Route Reply (RREP) packet, which contains ID, location, and lifetime information. The ultimate objective of these deployed nodes is to transmit sensed information to the base station.

Formation of a Grid
The entire region considered for the experiment was partitioned into a square-shaped grid of equal size. The size of a single grid is calculated based on the communication range of the node. The mathematical formula used for calculating the size of a single grid is given by Equation (1): Equation (1), a denotes the size of the grid and R signifies the communication range of the node. Each grid is indicated with a different grid identifier number, and this number for each node is known using a GPS tracking system. In addition to the grid identifier number, each node has a different identification number.

Election of Grid Organizer Based on Sailfish Optimization
Generally, in the case of a grid structure, every node is deployed randomly, and each node has a unique identification number. The nodes within the specified grid are referred to as grid associates. A grid organizer is selected to equalize the load in every grid. The elected node functions as a grid organizer for a particular period. Once the period of time for that particular node is terminated, the old grid organization selects the new grid organizer based on the selection process criteria. The old grid organizer broadcasts the new grid organizer to its grid associates. The two significant criteria considered for choosing the grid organizer are distance and leftover energy.
The distance between a particular node and the sink is calculated based on the Euclidean distance formula. The locations of the deployed nodes are tracked using a GPS tracking system. The Euclidean distance formula used for calculating the distance between a particular node and the sink is given in (2).
In Equation (2), points (A 1 , A 2 ) are referred to as location coordinates for a specified node, and point (B 1 , B 2 ) is termed as the location coordinate for the sink node or base station. Another crucial criterion considered for the election of the grid organizer is the excess energy in the node. The mathematical expression used for calculating the excess energy in the battery of the sensor is given in Equations (3) and (4). R e is the Residual energy. T e is the Totaled energy and E u is the energy utilized Equation (4) represents the mathematical expression used to calculate the energy utilized by the node during data transmission. C1 and C2 denote the constant value that keeps changing based on the wireless network application, and β represents the path loss constant. c(a, b) signifies the estimation of the energy utilized by the sensor and d(a, b) represents the distance between the sensor nodes. These two criteria are considered objective functions in the sailfish optimizer. The natural behavior of sailfish and its optimization characteristics are discussed in the following section.
• Natural Behavior of Sailfish The prey for these sailfish is smaller fish, such as sardines, attacking groups such as grey wolves. Certain behaviors of sardines, such as acceleration and maneuverability, are considered quite challenging for sailfish while hunting these sardines [31]. Attacking sardines, sailfish attempt a slashing motion by injuring many sardines or else hits a single sardine and makes it inactive. The injured sardines are detached from the driving school and are easily captured by the sailfish. The sailfish keep their bodies stable by keeping their pelvic and dorsal fins more erect. Additionally, they change color to communicate with other sailfish. The behavior of both sailfish and sardines was modeled and used to frame an optimization algorithm.

•
Advantages of sailfish optimizer over other methods.

1.
Determiningthe distance between sensor nodes is faster.

2.
Grid organizer selection is easier.

3.
By grid selection criteria and shortest path establishment, energy consumption is less, thereby increasing the lifetime of the network.
The steps enclosed in the sailfish optimizer are described as follows.

• Steps Enclosed in Sailfish Optimization
The sequence of steps included in sailfish optimization starting from initialization until hunting prey is given below.

•
Step 1: Initialization The sailfish were considered as candidate solutions, and the variable related to the problem was considered the sailfish's position in the search space. The mathematical expression used to represent the sailfish population, and their position is given by (5).
Based on this initialized population, the fitness function of each sailfish is computed using the following expression given in (6): Subsequently, the population of sardines, along with their fitness function, was elucidated similarly.

•
Step 2: Elitism In this algorithm, the best solution of sailfish is saved in each iteration, and is referred to as the elite. This elite sailfish is taken as the fittest sailfish and can defend the acceleration and maneuverability of the sardine during capture. Furthermore, the position of the injured sardines in every iteration is also saved to select it as the best goal for an attack. The positions of the injured sardines and elite sailfish are denoted as Z i injure S and Z i elite SF respectively.

•
Step 3: Attack-alteration approach The sailfish can attack in every direction as a shrinking circle, and they keep updating their position according to the position of the prey. The new position of the sailfish can be represented as follows: Equation (7), Z i elite SF represents the position of elite sailfish at the i th iteration, rand(0,1) is the random number, Z i injure S represents the position of the injured sardine at the ith iteration, Z i old SF denotes the current position of the sailfish, and δ i represents the coefficient, which can be calculated as follows: PD is the density of the prey, which means the number of prey present at every iteration, and the PD can be calculated as follows: In Equation (9), N SF is the number of sailfish and N S represents the number of sardines in each iteration.

•
Step 4: Attacking Prey Subsequently, in this step, the current position of the sardine gets updated. The new position of the sardine can be obtained using (10).
where Z i elite SF denotes the best position of elite sailfish, Z i old S denotes the current position of sardine, r is a random number in the range 0 and 1, and AP denotes the attack power of the sailfish. The updating process continues until convergence is achieved. A flow chart explaining the sequences of the sailfish optimization algorithm is shown in Figure 3.
Subsequently, in this step, the current position of the sardine gets updated. The new position of the sardine can be obtained using (10).  The grid organizer among the grid members was selected using the sailfish optimization algorithm. As explained previously, the elected grid organizer is the head of the Start Initialize sailfish and sardine in a random manner Evaluate the fitness function

Is max criteria satisfied
To determine elite sailfish and injured sardine Update the position of sailfish using equation (7) Update the position of sardine using equation (8) Best position of sailfish Yes No End Figure 3. Flow chart of sailfish optimization.

• Sailfish Optimizer for Choosing Grid Organizers
The grid organizer among the grid members was selected using the sailfish optimization algorithm. As explained previously, the elected grid organizer is the head of the grid cluster for a particular period. After a certain period, the election process of the grid organizer commences once again. The steps followed in the sailfish optimization for the election of the grid organizer are described below.

•
Step 1: Initialization The population considered for the analysis was initialized at this stage. Generally, the variables related to the problem are termed population or candidate solutions. The variables considered for our research problem are the residual energy of the sensors and the distance between the nodes and sink. The mathematical expression used to represent the population initialization is given by Equation (11).
Equation (9), d n represents the population of the distance between nodes and rs n represents the population of residual energy in nodes.

•
Step 2: Fitness Function Based on the initialized population, the fitness function can be represented as follows: According to this equation, the fitness function for this optimization problem is to maximize the residual energy in the sensors and minimize the distance between the sensor nodes.

•
Step 3: Updating The values of distance and residual energy related to nodes get updated in each iteration to find the best solution within the search space.

•
Step 4: Termination The search process was terminated once the required criteria were satisfied. A grid organizer is selected for each grid by performing the optimization protocol. The grid members in each grid transmit the sensed data to the grid organizer. From the grid organizer, the data must be forwarded to the sink. Therefore, a relay node is selected to achieve optimal routing. A fuzzy expert system is used to select a relay node. The relay-node selection process is briefly discussed in the next section.

Relay Node Election Based on Fuzzy Expert System
The process of relay node selection is carried out to forward the data from the grid organizer to the sink. In this study, the work grid organizer is referred to as a relay node. The grid organizer (source node) selects its neighbor grid organizer for data transmission. This selection process was performed based on fuzzy rules. The procedure followed in the relay node selection using the fuzzy rule is as follows: The other membership function for the choice of grid organized and the residual energy in joules have been obtained with the same triangular function, and the limitation of each zone is described in Table 1.

Fuzzification
The initial process carried out in a fuzzy expert system is fuzzification. The transformation of our system input to the fuzzy set is referred to as the fuzzification process. Then, with the assistance of this crisp value, a membership function was drawn [32]. The membership function can be drawn in either a triangular or trapezoidal form. The system input for this study was the residual energy, distance, and degree of the grid organizer. These three input parameters are converted into a fuzzy set between 0 and 1 and framed into a triangular membership function. The triangular membership function is drawn for these three parameters based on the crisp value shown in Figure 4 The membership function graphed for the input variable using linguistic values is illustrated in the previous figure. In the case of distance, it is drawn in meters. The distance value (0-600) was low, (300-900) medium, and (600-1000) high.

Membership Function
The search process was terminated once the required criteria were satisfied. A grid organizer is selected for each grid by performing the optimization protocol. The grid members in each grid transmit the sensed data to the grid organizer. From the grid organizer, the data must be forwarded to the sink. Therefore, a relay node is selected to achieve optimal routing. A fuzzy expert system is used to select a relay node. The relay-node selection process is briefly discussed in the next section.

Relay Node Election Based on Fuzzy Expert System
The process of relay node selection is carried out to forward the data from the grid organizer to the sink. In this study, the work grid organizer is referred to as a relay node. The grid organizer (source node) selects its neighbor grid organizer for data transmission. This selection process was performed based on fuzzy rules. The procedure followed in the relay node selection using the fuzzy rule is as follows: The other membership function for the choice of grid organized and the residual energy in joules have been obtained with the same triangular function, and the limitation of each zone is described in Table 1. Residual Energy in Joules 0, 3, 6 3, 6, 9 6, 9, 10 Choice of Grid organized 0, 3, 6 3, 6, 9 6, 9, 10

Fuzzification
The initial process carried out in a fuzzy expert system is fuzzification. The transformation of our system input to the fuzzy set is referred to as the fuzzification process. Then, with the assistance of this crisp value, a membership function was drawn [32]. The membership function can be drawn in either a triangular or trapezoidal form. The system input for this study was the residual energy, distance, and degree of the grid organizer. These three input parameters are converted into a fuzzy set between 0 and 1 and framed into a triangular membership function. The triangular membership function is drawn for these three parameters based on the crisp value shown in Figure 4 The membership function graphed for the input variable using linguistic values is illustrated in the previous figure. In the case of distance, it is drawn in meters. The distance value (0-600) was low, (300-900) medium, and (600-1000) high.

Low
The search process was terminated once the required criteria were satisfied. A grid organizer is selected for each grid by performing the optimization protocol. The grid members in each grid transmit the sensed data to the grid organizer. From the grid organizer, the data must be forwarded to the sink. Therefore, a relay node is selected to achieve optimal routing. A fuzzy expert system is used to select a relay node. The relay-node selection process is briefly discussed in the next section.

Relay Node Election Based on Fuzzy Expert System
The process of relay node selection is carried out to forward the data from the grid organizer to the sink. In this study, the work grid organizer is referred to as a relay node. The grid organizer (source node) selects its neighbor grid organizer for data transmission. This selection process was performed based on fuzzy rules. The procedure followed in the relay node selection using the fuzzy rule is as follows: The other membership function for the choice of grid organized and the residual energy in joules have been obtained with the same triangular function, and the limitation of each zone is described in Table 1. Residual Energy in Joules 0, 3, 6 3, 6, 9 6, 9, 10 Choice of Grid organized 0, 3, 6 3, 6, 9 6, 9, 10

Fuzzification
The initial process carried out in a fuzzy expert system is fuzzification. The transformation of our system input to the fuzzy set is referred to as the fuzzification process. Then, with the assistance of this crisp value, a membership function was drawn [32]. The membership function can be drawn in either a triangular or trapezoidal form. The system input for this study was the residual energy, distance, and degree of the grid organizer. These three input parameters are converted into a fuzzy set between 0 and 1 and framed into a triangular membership function. The triangular membership function is drawn for these three parameters based on the crisp value shown in Figure 4 The membership function graphed for the input variable using linguistic values is illustrated in the previous figure. In the case of distance, it is drawn in meters. The distance value (0-600) was low, (300-900) medium, and (600-1000) high.

Medium
The search process was terminated once the required criteria were satisfied. A grid organizer is selected for each grid by performing the optimization protocol. The grid members in each grid transmit the sensed data to the grid organizer. From the grid organizer, the data must be forwarded to the sink. Therefore, a relay node is selected to achieve optimal routing. A fuzzy expert system is used to select a relay node. The relay-node selection process is briefly discussed in the next section.

Relay Node Election Based on Fuzzy Expert System
The process of relay node selection is carried out to forward the data from the grid organizer to the sink. In this study, the work grid organizer is referred to as a relay node. The grid organizer (source node) selects its neighbor grid organizer for data transmission. This selection process was performed based on fuzzy rules. The procedure followed in the relay node selection using the fuzzy rule is as follows: The other membership function for the choice of grid organized and the residual energy in joules have been obtained with the same triangular function, and the limitation of each zone is described in Table 1. Table 1. Membership function for residual energy and grid organized choice.

Fuzzification
The initial process carried out in a fuzzy expert system is fuzzification. The transformation of our system input to the fuzzy set is referred to as the fuzzification process. Then, with the assistance of this crisp value, a membership function was drawn [32]. The membership function can be drawn in either a triangular or trapezoidal form. The system input for this study was the residual energy, distance, and degree of the grid organizer. These three input parameters are converted into a fuzzy set between 0 and 1 and framed into a triangular membership function. The triangular membership function is drawn for these three parameters based on the crisp value shown in Figure 4 The membership function graphed for the input variable using linguistic values is illustrated in the previous figure. In the case of distance, it is drawn in meters. The distance value (0-600) was low, (300-900) medium, and (600-1000) high.

Knowledge Base
In this phase, fuzzy rules are generated using the membership function drawn from the previous phase. The ability to obtain a resolution for a problem from a set of statistics is essential for an expert approach. Initially, the collected data are converted into a conditional statement, which signifies evidence. With the assistance of this evidence, reasoning rules were generated. Two types of facts are included in the generated rule. Of these, one premise and the other are related consequences. Furthermore, in the event explaining uncertainty, the confidence factor is enclosed in each rule. The relay node choice by input metrics: residual energy, distance, and grid organizer are listed in Table 2.  Similarly, in the case of residual energy, it is sketched in joules. The values of residual energy are between (0-6) low, (3-9) medium, and (6-10) high. In the case of a grid organizer degree (0-6) low, (30-9) medium and high (6-10). Fuzzy rules are generated using these linguistic variables in the next section.

Knowledge Base
In this phase, fuzzy rules are generated using the membership function drawn from the previous phase. The ability to obtain a resolution for a problem from a set of statistics is essential for an expert approach. Initially, the collected data are converted into a conditional statement, which signifies evidence. With the assistance of this evidence, reasoning rules were generated. Two types of facts are included in the generated rule. Of these, one premise and the other are related consequences. Furthermore, in the event explaining uncertainty, the confidence factor is enclosed in each rule. The relay node choice by input metrics: residual energy, distance, and grid organizer are listed in Table 2.
The membership function of the output variable is shown in Figure 5. The generation of fuzzy rules based on input variables is displayed in tabular format in the previous section. From the above table, it is found that if the residual energy for the grid organizer is high and the distance is low, then the specified grid organizer is elected as the relay node. If the residual energy and distance are medium, then the degree of the grid organizer is also considered in that situation. If the degree of the grid organizer is low, then that particular grid organizer is elected as a relay node or not taken as a relay node. If the residual energy is low and the distance is high, the specified grid organizer is not elected as a relay in the third situation. The membership function of the output variable is shown in Figure 5. The generation of fuzzy rules based on input variables is displayed in tabular format in the previous section. From the above table, it is found that if the residual energy for the grid organizer is high and the distance is low, then the specified grid organizer is elected as the relay node. If the residual energy and distance are medium, then the degree of the grid organizer is also considered in that situation. If the degree of the grid organizer is low, then that particular grid organizer is elected as a relay node or not taken as a relay node. If the residual energy is low and the distance is high, the specified grid organizer is not elected as a relay in the third situation.

Defuzzification
Generally, defuzzification is the inverse process of a fuzzy set, and it refers to the process of converting fuzzy output into crisp results.It can also be defined as the conversion of qualitative data into a quantitative one. The output gathered from the fuzzy set was represented as 0 and 1. The value 0 denotes that the grid organizer is not selected as a relay node, and a value of 1 signifies that the grid organizer is selected as the relay node.
Finally, based on this fuzzy expert system, the grid organizers that act as relay nodes

Defuzzification
Generally, defuzzification is the inverse process of a fuzzy set, and it refers to the process of converting fuzzy output into crisp results.It can also be defined as the conversion of qualitative data into a quantitative one. The output gathered from the fuzzy set was represented as 0 and 1. The value 0 denotes that the grid organizer is not selected as a relay node, and a value of 1 signifies that the grid organizer is selected as the relay node.
Finally, based on this fuzzy expert system, the grid organizers that act as relay nodes for data transmission are selected. The data are transmitted from the grid organizer to the sink using a relay node selection process. Based on the present research, the optimal routing protocol is framed for data transmission in smart building WSNs. From the sink, the data are aggregated and forwarded to the server to monitor and render alterations in case of any emergency. Before data transmission from the sink, the data are encrypted using a two-fish encryption algorithm to secure data from various malicious attacks. The encryption process found in the two-fish encryption algorithm is discussed in the next section.

Second Stage: Trust-Based Model for Secure Data Transmission
In this stage, to protect the data from various security threats, a trust-based model is used. The transmitted data are encrypted using an encryption algorithm and then decrypted at the receiver end using this trust model. The algorithm used to encrypt the data in the proposed method is two-fish encryption. The outline of the two-fish algorithm is as follows:

Two-Fish Algorithm
The two-fish algorithm is a cipher algorithm with a block size of 128bits and can admit a variable length of key [33]. This cipher algorithm is composed of a bijective F function and is a sixteen-round network. The F-function performed three functions: pseudo-Hadamard transform (PHT), distance separable matrices (MDS), and key-dependent S-boxes. These three F-functions are briefly discussed in the following steps.

•
Initially, the input data consisting of 128 bits are segmented into four parts, each containing 32 bits, based on the little-endian convention.

•
Out of the four parts, two parts of the bits are correct, and the rest of the bit is left. • Then, these four input parts are XOR with four keys, and this process is referred to as whitening. The expression for describing whitening is given by Equation (13).
• In Equation (13), C 0 represents the converted bit, P signifies the input bit, and K i is used for encryption.

•
The resultant bit obtained by performing the XOR operation is rotated either left or right by one bit, and again, it is swapped to produce a new result. This rotation in the initial argument is based on the second argument. This process is repeated 16 times; therefore, it is termed a two-fish round. • S-box: This S-box is a substitution operation that is based on a table. Normally, four types of S-boxes are used in the two-fish algorithm. These four S-boxes are merged with the MDS to generate the h-function. Using this S-box, the input and output sizes can be randomly altered. Rather, the S-box contains an 8-bit permutation with an XOR with two sub-keys. • MDS matrix: The MDS matrix is termed as a building block to the cipher because it guarantees a certain degree of diffusion. This MDS matrix is coupled with an S-box and acts as the main diffusion mechanism. If one of the input elements is changed, then every output element must be altered. • Pseudo-Hadamard Transform (PHT): This PHT is a mixing operation that is necessary for software. This is a simple reverse diffusion mechanism. The expression used to represent this transform is given by Equation (14).
• Finally, after performing this transform, the final encrypted data, which is referred to as ciphertext, will be obtained. Based on this two-fish algorithm, the aggregated data in the sink are encrypted. The encrypted data are sent to the server via a gateway for monitoring.
Based on this proposed architecture, energy-efficient and secure data transmission in smart building applications can be achieved. An experimental investigation is carried out using MATLAB software to evaluate the functionality of the proposed framework, and the results gathered through implementation are briefly discussed in the following section.

Results and Discussion
The proposed grid-based routing model for smart building applications was tested using MATLAB software with the following system configurations: • Processor: Intel (R) Core ™ i5-3330s CPU @ 2.70 GHz • Memory (RAM): 8.00 Gb (7.88 Gb usable) • System type: 64-bit operating system, x64 based processor The experimental analysis was carried out with the help of sensor nodes deployed within 1000 × 1000 m 2 dimensions, and the total energy of the deployed node was fixed at 10 J. In addition, some of the simulation setups considered for analysis is listed in Table 3. Initially, the nodes are deployed in the specified region of the building to sense various types of information. Approximately 20 sensor nodes were deployed in each building. The location coordinate for the sink is (4,4), and the location coordinate for the server is (4, 1). These deployed nodes are then formed into grids based on the intercommunication range. The formation of the grid using the intercommunication range is shown in Figure 6. The nodes that are present within the grid are referred to as grid members.
From each grid, one node was selected as the grid organizer. The elected grid organizer functions as the head for a specified period of time. Using the sailfish optimization algorithm, the grid organizer is selected based on two significant parameters: distance and residual energy. The election of the grid organizer is represented in a pictorial format in Figure 7. The selection of the grid organizer in each grid is displayed in the previous figure.
In each grid, the node highlighted in green is referred to as the grid organizer. The sensed information from every grid member is transmitted to the grid organizer. Then, from the grid organizer, the data must be transmitted to the sink.
The source grid organizer selects its neighbor grid organizer based on the relay-node selection technique to perform this function. In this study, the grid organizer is referred to as a relay node. The relay node is selected using a fuzzy expert system. The input for creating the fuzzy rule is the grid organizer's distance, residual energy, and choice. Based on this parameter, the relay node is selected to transmit data from the grid organizer to the sink. The grid organizer selected as the relay node is displayed in pictorial format in Figure 8.      In the above figure, the grid organizers selected as relay nodes are illustrated. The grid organizers selected as relay nodes are highlighted in red. Using these relay nodes, the grid organizer transmits the acquired data to the sink using the shortest path. Then, from the sink, the data are transmitted to the server for further monitoring. Prior to the transmission of data to the server, the data were encrypted using a two-fish algorithm. The encrypted data were then transmitted to the server. At the server end, the encrypted data are decrypted again for visualization. Finally, based on this routing protocol, smart building applications can attain energy-efficient and secure data transmission. Performance metrics were evaluated to perform an experimental study of the proposed framework. The evaluation of various performance metrics related to the experiment is described in the next section.

Experimental Investigation
An experimental study on the proposed energy-efficient and secure routing protocol was carried out using specific parameters. The parameters considered for analysis are average residual energy, packet loss, throughput, packet delivery ratio, end-end delay, the amount of packet received, decryption time, and encryption time. These parameters are evaluated for the proposed framework and conventional approaches to prove the optimal functioning of the proposed routing approach in comparison with conventional routing techniques. The conventional routing approaches considered for comparison studies are the energy-efficient region source routing protocol (ER-SRP) [13], energy-efficient load-balancing ant-based routing algorithm (EBAR) [14], improved LEACH protocol [16], and energy-efficient grid-based routing approach (EEGRA) [30]. Table 4 lists the estimated metric values for the proposed and conventional routing approaches. A comparison of the average residual energy metric between the proposed and existing routing protocols is shown in Figure 9. The graph shows a comparison between several techniques and the average value of the residual energy as a percentage. The average residual energy was found to be more significant for the proposed method. In the above figure, the grid organizers selected as relay nodes are illustrated. The grid organizers selected as relay nodes are highlighted in red. Using these relay nodes, the grid organizer transmits the acquired data to the sink using the shortest path. Then, from the sink, the data are transmitted to the server for further monitoring. Prior to the transmission of data to the server, the data were encrypted using a two-fish algorithm. The encrypted data were then transmitted to the server. At the server end, the encrypted data are decrypted again for visualization. Finally, based on this routing protocol, smart building applications can attain energy-efficient and secure data transmission. Performance metrics were evaluated to perform an experimental study of the proposed framework. The evaluation of various performance metrics related to the experiment is described in the next section.

Experimental Investigation
An experimental study on the proposed energy-efficient and secure routing protocol was carried out using specific parameters. The parameters considered for analysis are average residual energy, packet loss, throughput, packet delivery ratio, end-end delay, the amount of packet received, decryption time, and encryption time. These parameters are evaluated for the proposed framework and conventional approaches to prove the optimal functioning of the proposed routing approach in comparison with conventional routing techniques. The conventional routing approaches considered for comparison studies are the energy-efficient region source routing protocol (ER-SRP) [13], energy-efficient loadbalancing ant-based routing algorithm (EBAR) [14], improved LEACH protocol [16], and energy-efficient grid-based routing approach (EEGRA) [30]. Table 4 lists the estimated metric values for the proposed and conventional routing approaches. A comparison of the average residual energy metric between the proposed and existing routing protocols is shown in Figure 9. The graph shows a comparison between several techniques and the average value of the residual energy as a percentage. The average residual energy was found to be more significant for the proposed method.   The average residual energy for the proposed method is 21.87%, 18.75%, 11.45%, and 4.16% higher than those of EEGRA, I-LEACH, EBAR, and ER-SRP, respectively. Figure 10 shows a comparison study performed using the end-end delay parameter for the existing and conventional routing protocols. In this graph, the graph is plotted between the number of sensor nodes and end-end delay in milliseconds on the X-and Y-labels. The end-to-end delay value obtained in the proposed method is 2.42% less than EEGRA, 1.80% less than I-LEACH, and 0.864% less than EBAR. A comparison study performed using these two parameters revealed better functioning of the proposed routing framework in comparison to existing routing approaches. The average residual energy for the proposed method is 21.87%, 18.75%, 11.45%, and 4.16% higher than those of EEGRA, I-LEACH, EBAR, and ER-SRP, respectively. Figure 10 shows a comparison study performed using the end-end delay parameter for the existing and conventional routing protocols. In this graph, the graph is plotted between the number of sensor nodes and end-end delay in milliseconds on the X-and Y-labels. The end-to-end delay value obtained in the proposed method is 2.42% less than EEGRA, 1.80% less than I-LEACH, and 0.864% less than EBAR. A comparison study performed using these two parameters revealed better functioning of the proposed routing framework in comparison to existing routing approaches. Figure 11 shows a comparison study conducted using the packet delivery ratio metric. The graph for this metric is plotted between various techniques and packet delivery ratio (PDR) in percentage on both axes. The value of PDR for the proposed routing technique is 16.66% more than EEGRA, 12.22% greater than I-LEACH, 6.66% greater than EBAR, and 2.22% greater than ER-SRP. A comparison study conducted using the throughput parameter is shown in Figure 12. The graph shows the number of iterations and throughput values in the X-and Y-axes, respectively. The throughput of the proposed method was 23.48%, 4.02%, 2.68%, and 2.01% higher than those of EEGRA, I-LEACH, EBAR, and ER-SRP, respectively. These two comparison studies demonstrate the effectiveness of the proposed routing approach in comparison with existing routing techniques.  Figure 11 shows a comparison study conducted using the packet delivery ratio metric. The graph for this metric is plotted between various techniques and packet delivery ratio (PDR) in percentage on both axes. The value of PDR for the proposed routing technique is 16.66% more than EEGRA, 12.22% greater than I-LEACH, 6.66% greater than EBAR, and 2.22% greater than ER-SRP. A comparison study conducted using the throughput parameter is shown in Figure 12. The graph shows the number of iterations and throughput values in the X-and Y-axes, respectively. The throughput of the proposed method was 23.48%, 4.02%, 2.68%, and 2.01% higher than those of EEGRA, I-LEACH, EBAR, and ER-SRP, respectively. These two comparison studies demonstrate the effectiveness of the proposed routing approach in comparison with existing routing techniques.    Figure 11 shows a comparison study conducted using the packet delivery ratio metric. The graph for this metric is plotted between various techniques and packet delivery ratio (PDR) in percentage on both axes. The value of PDR for the proposed routing technique is 16.66% more than EEGRA, 12.22% greater than I-LEACH, 6.66% greater than EBAR, and 2.22% greater than ER-SRP. A comparison study conducted using the throughput parameter is shown in Figure 12. The graph shows the number of iterations and throughput values in the X-and Y-axes, respectively. The throughput of the proposed method was 23.48%, 4.02%, 2.68%, and 2.01% higher than those of EEGRA, I-LEACH, EBAR, and ER-SRP, respectively. These two comparison studies demonstrate the effectiveness of the proposed routing approach in comparison with existing routing techniques.  The comparison analysis performed based on packet loss for the proposed and existing routing protocols is shown in Figure 13. The graph is sketched between various techniques and packet loss in percentage on both the X-and Y-axes. The packet loss for the proposed routing approach is 58.3% less than EEGRA, 45.83% less than I-LEACH, The comparison analysis performed based on packet loss for the proposed and existing routing protocols is shown in Figure 13. The graph is sketched between various techniques and packet loss in percentage on both the X-and Y-axes. The packet loss for the proposed routing approach is 58.3% less than EEGRA, 45.83% less than I-LEACH, 33.3% less than EBAR, and 23.02% less than ER-SRP. Figure 14 illustrates the comparison study carried out using the number of received packets in the existing and proposed routing protocols. The number of received packets for the proposed method is 5.70% greater than EEGRA, 3.80% greater than I-LEACH, 3.04% greater than EBAR, and 1.90% greater than ER-SRP. Based on this comparison study, it is proved that the performance of the proposed method is better than that of the existing routing methods. The comparison study carried out based on encryption and decryption times for the proposed and existing routing approaches is displayed in Figures 15 and 16. The encryption time for the proposed approach is 18 ms, and for the existing techniques such as EEGRA, I-LEACH, EBAR, ER-SRP, the encryption time is determined to be 22 ms, 22 ms, 21 ms, and 19 ms, respectively. Similarly, the decryption time for the proposed methodology is 0.4 ms and for the technique such as EEGRA, I-LEACH, EBAR, ER-SRP the decryption time is determined to be0.49 ms, 0.48 ms, 0.47 ms, and 0.44 ms respectively. Finally, based on this comparison study, it is revealed that the performance of the proposed architectural framework is superior to that of the conventional approach. By utilizing the optimal routing design and encryption algorithm, less energy utilization and improved security can be achieved in a better way. The analysis also revealed that a grid-based routing design is more suitable for smart building applications.

Conclusions
This study focuses on designing an optimal routing protocol for smart building WSNs to minimize energy utilization and improve data security. Recently, due to the widespread of innovations in information technology, urban areas have been modernized by including wireless sensor technology to achieve automatic monitoring. The significant issue addressed in the WSNs over the past years is energy depletion and security threats. These two parameters influence network performance. To improve the performance of WSNs, an ideal network model was designed in this study using a grid-based clustering approach. The election of the grid organizer was considered significant, and it was performed using the sailfish optimization algorithm. The sensed information from the grid members is transmitted to the grid organizer. Further, relay node selection is performed based on fuzzy rules to transmit the data from the grid organizer to the sink with minimal energy consumption. Then, to secure the transmitted data from attacks, a

Conclusions
This study focuses on designing an optimal routing protocol for smart building WSNs to minimize energy utilization and improve data security. Recently, due to the widespread of innovations in information technology, urban areas have been modernized by including wireless sensor technology to achieve automatic monitoring. The significant issue addressed in the WSNs over the past years is energy depletion and security threats. These two parameters influence network performance. To improve the performance of WSNs, an ideal network model was designed in this study using a grid-based clustering approach. The election of the grid organizer was considered significant, and it was performed using the sailfish optimization algorithm. The sensed information from the grid members is transmitted to the grid organizer. Further, relay node selection is performed based on fuzzy rules to transmit the data from the grid organizer to the sink with minimal energy consumption. Then, to secure the transmitted data from attacks, a two-fish algorithm was introduced. An experimental investigation was conducted to estimate the performance of the proposed scheme. The performance metrics were calculated and compared with traditional routing approaches to demonstrate the excellent performance of the proposed framework.