# An Energy Centric Cluster-Based Routing Protocol for Wireless Sensor Networks
## 4 The Protocol Details
### Cluster-Head Election Phase  
During this phase, cluster heads are elected whose duration is \(T_{2}\). A cluster head is elected on the basis of rank of the member nodes in a cluster. Two different ways of cluster-head election technique are adopted. At the first round (\(r=1\)), each node broadcasts a _Node_Msg_ within its adjustable transmission range \(R_{\text{a}}\) (distance from a node to the farthest alive node in a cluster) with the following values: rank and residual energy. At the same time, every node in the same cluster receives the message and updates its CMT. A node calculates its \(d_{avg}\) from other member nodes which are plugged-in during the node's rank calculation as in Equation (4). We can see from the equation that a node with a higher residual energy and the minimum average distance from the member nodes has the higher rank. A node with the higher rank is elected as a cluster head. In a situation, if multiple nodes have the same rank, the node with the higher residual energy is selected as a cluster head. Once a node is elected as a cluster head, it sends the time-division multiple access (TDMA) schedule list to all its member nodes by broadcasting a _Schedule_Msg_.  
\[d_{avg}=\frac{1}{m-1}\Bigg{(}\sum_{j=1,i\
eq j}^{m-1}d(s_{i},s_{j})\Bigg{)}\]  
where \(m\) is the number of member nodes in a cluster and \(d(s_{i},s_{j})\) is the distance between two member nodes \(s_{i}\) to \(s_{j}\).  
\[rank(s_{i})=\frac{\alpha\times E_{res}}{E_{ini}}+\frac{(1-\alpha)}{d_{avg}} \tag{4}\]  
where \(\alpha\) is a weight factor interval of [0,1]. \(E_{ini}\) and \(E_{res}\) are the initial and residual energy of a node \(s_{i}\), respectively.  
From the second round (\(r>1\)), a cluster head is elected by the former cluster head of the previous round (\(r\)-1) in a cluster. Here, the role of a former cluster head is a caretaker for the current cluster-head election. It elects a node with a higher rank as a cluster head among the member nodes, where the rank value of the member nodes has been piggybacked along with the local data, which is sent by the member nodes during the intra-cluster communication. Then it sends a _Handover_Msg_ to the elected node with the following information: cluster head _id_ and missing node _id_. The elected node receives the message and updates its CMT and sends the TDMA schedule list to its member nodes by broadcasting a _Schedule_Msg_. Upon receiving the message, a member node updates its CMT. If a node has not sent its local data to its respective cluster head during the intra-cluster communication, it is considered a missing node or a dead node. A missing node will be excluded from the network and from the rest of the process. If no _Schedule_Msg_ has been broadcasted from a cluster head within a predefined time, _Node_Msg_s are broadcasted among the member nodes followed by the competition of the cluster-head election that has been described as in the first round. Otherwise, a cluster head is elected by the former cluster head in a cluster recursively throughout the network lifetime. This phase is given by the pseudo-code in Algorithm 2.  
```
1:start (cluster head election among nodes)
2:while (\(T_{2}\) has not expired) do
3:\(state\leftarrow\)Candidate
4:if (round, \(r==1\)) then
5: Broadcast Node_Msg
6: Receive and update CMT[\(s_{i}\)]
7: Find a higher rank node
8:\(state\leftarrow\)Normal
9: CMT[\(s_{i}\)]_state\(\leftarrow\)Head
10: Broadcast Schedule_Msg
11:elseif (round, \(r>1\) && \(s_{i}\) is a former cluster head of \(r-1\)) then
12: Find a member node with a higher rank
13: Find missing node _id_
14: Send Handover_Msg
15: Find cluster head _id_
16:\(state\leftarrow\)Normal
17: CMT[\(s_{j}\)]_state\(\leftarrow\)Head
18: Broadcast Schedule_Msg
19:if (no Schedule_Msg has received) then
20: Repeat the cluster head election process as \(r==1\)
21:endif
22:endif
23:endif
```  
**Algorithm 2**Cluster Head Election