# Cluster-Based Routing Protocol with Static Hub (CRPSH) for WSN-Assisted IoT Networks
## 4 Proposed Protocol
### Cluster Head Selection and Cluster Formation  
Initially, the energy levels of all devices are equal. The hub computes and tracks the remaining energy of every device after building the peer adjacency matrix. The hub selects CHs in the network based on the following criteria:  
1. Two CHs should not be located adjacent to one another. Let Device \(\alpha\) be selected as CH; \(P_{2}(\alpha)\) is a set peer device of the Device \(\alpha\); **if** (\(\beta\in P_{2}(\alpha)\)) **then** Device \(\beta\) cannot be CH. **end if**
2. Each CH's residual energy, \(E_{R}(CH)\), should be larger than the threshold value. 3. Each cluster head should have a peer count of at least \(\gamma\) /2. Let \(k\) be the number of devices in the network and \(c\) denote the ideal number of CHs. Then, \(\gamma\) = (\(k\)-\(c\))/\(c\). In the ideal situation, \(\gamma\) is the average number of devices in a cluster. So each CH should satisfy \(P_{2}(\alpha)\geqslant\gamma\) /2. After choosing the CH, the hub calculates the path from hub to the CH. The hub checks the peer adjacency matrix and ensures that the selected sensor device's energy level is more than the threshold. Moreover, The routing path's total energy usage should be kept to a minimum. To inform the sensor devices that have been selected as CHs, the hub unicasts the announcement packet (\(CH_{announce}\)) to the cluster heads through the path determined in Algorithm 2. The \(CH_{announce}\) packet then proceeds along the route to the CH. Reverse connections are made by the sensing devices along the way to the CH. A \(CHannounce\) message causes the CH to send a \(CHack\) acknowledgment packet to the hub. The \(CH_{ack}\) packet takes the same way back as the \(CH_{announce}\) packet. If the hub does not receive an acknowledgment packet from the CH within a specified time period, it takes a different routing. ```
1:Hub sends \(CH_{announce}\) packet to the Cluster Heads. 2:
3:Cluster Heads send \(CH_{ack}\) packet to the hub. 4:\(Route(k)\) is a collection of sensor devices that form the route between node k and the hub. 5:Each relay device maintains a routing table \(Realy_{Table}(\alpha)\) with two columns: cluster head \(id\) and \(next\_device\), which is initialized to \(\phi\). 6:Device \(\alpha\) receives the \(CH_{announce}\) packet from the Device \(\beta\);
7:\(CH_{announce}:<CH_{announce}\), \(Route(CH)\), \(ID_{\beta}\), \(ID_{CH}>\)
8:if (\(ID_{CH}==ID_{\alpha}\)) then
9: Forward the ACK Packet \(CH_{ack}:<CH_{ack}\), \(ID_{\alpha}\), \(next\_device>\) towards the hub. 10:else
11:if (\(\alpha\in\)Route (CH) && \(ID_{CH}\
otin Realy_{Table}(\alpha)\)) then
12: Update the \(Realy_{Table}(\alpha)\) by updating \(cluster\) head \(id\) as \(ID_{CH}\) and \(next\_device\) as \(ID_{\beta}\);
13: Broadcast \(CH_{announce}:<CH_{announce}\), \(Route(CH)\), \(ID_{\alpha}\), \(ID_{CH}>\) packet. 14:else
15: Discard the packet;
16:endif
17:endif
18:\(CH_{ack}:<CH_{ack}\), \(ID_{\beta}\), \(next\_device>\)
19:if (\(next\_device==ID_{\alpha}\)) then
20:if (\(ID_{\alpha}==ID_{Hub}\)) then * \(Time\_out\gets false\);
* **else**
* Find the \(next\_device\) of \(CH\)\(\beta\) from the \(Realy_{Table}(\alpha)\);
* Forward the ACK Packet \(CH_{ack}:<CH_{ack}\), \(ID_{\beta}\), \(next\_device>\) towards the hub. * **end if**
* **else**
* Drop the packet. * **end if**

**Algorithm 3** Cluster Formation

Afterward, the cluster head broadcasts the \(CH_{info}\) advertisement packet to create a cluster as shown in Algorithm 3. The devices that receive several \(CH_{info}\) packets pick the cluster head based on the RSSI value that is the highest RSSI. After the CH selection, a device sends the \(CH_{join}\) packet with the joining request. Each interested device sends an equivalent \(CH_{join}\) packet to the cluster head. Following receipt of all joining requests, the cluster head broadcasts information to the hub about each cluster member.