# Multi-Gateway-Based Energy Holes Avoidance Routing Protocol for WSN
## 6 Proposed Algorithm  
The Algorithm 1 describes the MGBEHA protocol.The notations used in the Algorithm 1 are as follows:  
1. Let \(N\) be the number of sensor nodes and \(R\) the number of cluster regions. 2. \(E_{\text{init}}\) is the initial energy. \(E_{\text{ch}}\) is the energy of cluster head. \(E_{\text{mem}}\) is the energy of a cluster member node. \(E_{\text{norm}}\) is the energy of a normal sensor node. 3. Area is a monitored network area. Area 1 is the area around the sink and Area 2 is the area around the gateway. 4. \(E_{\text{TX}}\), \(E_{\text{RX}}\), and \(E_{\text{DA}}\) are the energies consumed in transmission, receiving, and aggregating, respectively. The size of each message is \(k\) bits. 5. \(D_{\text{CC}}\) is the distance between a CH and the gateway node of its region. \(D_{\text{CS}}\) is the distance between the cluster head and the sink node. ```
1. Initialize \(R\), \(N\), \(E_{\text{TX}}\), \(E_{\text{RX}}\), \(E_{\text{DA}}\), \(k\), \(E_{\text{init}}\), Area, Area 1, Area 2. 2. \(E_{\text{ch}}\gets E_{\text{init}}\), \(E_{\text{mem}}\gets E_{\text{init}}\) and \(E_{\text{norm}}\gets E_{\text{init}}\)
3. Divide the Area into \(R\) regions. 4. Deploy sink at mid-point of Area. 5. Set Area 1 around the sink. 6. **while** (a gateway node not set) do
```  
**Algorithm 1**  
```
1. Initialize \(R\), \(N\), \(E_{\text{TX}}\), \(E_{\text{RX}}\), \(E_{\text{DA}}\), \(k\), \(E_{\text{init}}\), Area, Area 1, Area 2. 2. \(E_{\text{ch}}\gets E_{\text{init}}\), \(E_{\text{mem}}\gets E_{\text{init}}\) and \(E_{\text{norm}}\gets E_{\text{init}}\)
3. Divide the Area into \(R\) regions. 4. Deploy sink at mid-point of Area. 5. Set Area 1 around the sink. 6. **while** (a gateway node not set) do
```  
**Algorithm 2**  
```
1. Start cluster set up phase in Cluster regions. 2. End-for
3. Nodes in Area 1 send data to sink and nodes in Area 2 send data to gateway. 4. \(E_{\text{norm}}\gets E_{\text{norm}}-E_{\text{TX}}\)
5. Member nodes in cluster regions send data to their cluster head. 6. \(E_{\text{mem}}\gets E_{\text{mem}}-E_{\text{TX}}\)
7. \(E_{\text{ch}}\gets E_{\text{ch}}-E_{\text{RX}}\)
8. **for**\(i=1\) to \(R\)
9. Calculate distance (\(D_{\text{CG}}\)) between cluster head and gateway. 10. Calculate distance (\(D_{\text{CS}}\)) between cluster head and sink. 11. if(\(D_{\text{CG}}>D_{\text{CS}}\))
12. 13.1.1 Cluster head transmits aggregated data to the sink. 13.4 else cluster head transmits aggregated data to the gateway. 13.4.1 \(E_{\text{ch}}\gets E_{\text{ch}}-(E_{\text{DA}}+E_{\text{TX}})\)
13.5 End-if
13.6 All gateway nodes aggregate and send data to the sink. 13.7 End for

## 7 Usefulness of Protocol in Real Life Scenario

The proposed protocol can be used in the building automation scenario. To measure the level of carbon monoxide (CO), CO sensors are deployed in the building. The sensors alert a security service if the level of CO exceeds the dangerous level. Let the sensors be deployed in different buildings of a society. A different setup is required for each building to transmit the data to the sink. However, if our proposed protocol is used, there is no need of a separate transmission mechanism for each building, one gateway is sufficient between two buildings. Sensors in two buildings can send data to the common gateway which transmits it to the sink. By reducing the transmission distance, sensors will consume less energy and a larger area can be covered by additional gateways. ## 8 Energy Consumption Analysis

In order to validate the simulations, we theoretically analyzed the energy consumption in the network and compared the theoretical and simulation results. Let us revisit the first-order radio energy model. The notations used in the analysis are as follows:

1.