# Cluster-Based Routing Protocol with Static Hub (CRPSH) for WSN-Assisted IoT Networks
## 4 Proposed Protocol
### Peer Discovery  
After sensor devices are deployed, the IoT hub starts the peer discovery phase. Each sensor device broadcasts the \(P_{z}D_{control}\) packet once in this configuration. Each device has knowledge about its peers at the completion of the peer discovery phase. The sender id is contained in the\(P_{z}D_{control}\) packet. When a device obtains a \(P_{z}D_{control}\) packet, it checks the peer list for the source device IDs. If the source ID is not yet in the peer list, it must be added; otherwise, the packet will be dropped. If the recipient device's \(P_{z}D_{control}\) packet is set to false, the recipient device sets it to true and broadcasts the \(P_{z}D_{control}\) packet.  
The Algorithm 1 explains the above operations. The phase of topology building follows the phase of peer discovery. During this process, each device broadcasts information about its peers to the IoT hub. Each device does this by employing a multicasting approach rather than flooding. The devices begin transmitting peer information to the hub via relay devices. As explained in Algorithm 1, the sender device selects a relay device from \(P_{z}(\alpha)\) and passes peer information to the hub. A sensor device transmits the \(P_{z}D_{info}\) packet just once to avoid network loops. Each device does this by maintaining a list of received peer information. As a result, it lowers network traffic and conserves energy. When the hub receives the \(P_{z}D_{info}\) from the sensor devices, it constructs the peer adjacency matrix. This peer adjacency matrix represents the network structure. The hub determines the cluster heads and the routing paths between them based on the peer adjacency matrix.  
```
1:Peer Discovery Control Packet
2:Return Hub Adjacency Matrix
3:\(P_{z}(\alpha)=\phi\) where \(P_{z}(\alpha)=\{w:w\) are the Peer/ Neighbor Device of the device \(\alpha\}\);
4:\(P_{z}Table(\alpha)=\phi\) where \(P_{z}Table(\alpha)\) is the Peer/ Neighbor table of the IoT Device \(\alpha\);
5:\(E_{R}(\alpha)\) is the remaining energy level of the IoT Device \(\alpha\);
6:Initially \(P_{z}D_{control}(\alpha)=\) False;
7:Set \(P_{z}D_{control}(\alpha)=\) True when the the IoT Device \(\alpha\) sends the \(P_{z}D_{control}\) packet;
8:\(Spot_{\alpha}\) is the location of the IoT Device \(\alpha\);
9:Device \(\alpha\) receives the control packet \(P_{z}D_{control}:<P_{z}D_{control}\), \(ID_{\beta}\)\(E_{R}(\beta)\), \(Spot_{\beta}\)\(>\) from the Device \(\beta\);
10:if\(\beta\
otin P_{z}Table(\alpha)\)then
11:\(P_{z}(\alpha)=P_{z}(\alpha)\bigcup\beta\);
12: Update \(P_{z}Table(\alpha)\) with \(<ID_{\beta}\), \(E_{R}(\beta)\), \(Spot_{\beta}>\);
13:if\(P_{z}D_{control}(\alpha)==\) falsethen
14:\(P_{z}D_{control}(\alpha)\)\(\leftarrow\) True;
15: Broadcast \(P_{z}D_{control}:<P_{z}D_{control}\), \(ID_{\alpha}>\); \(\triangleright\) Broadcast \(P_{z}D_{control}\) packet;
16:else
17: Discard the packet
18:endif
19:Device \(\alpha\) receives the control packet \(P_{z}D_{info}:<P_{z}D_{info}\), \(P_{z}Table(\beta)\), \(ID_{\beta}\), \(ID_{relay}>\) from the Device \(\beta\);
20:if\(ID_{relay}=ID_{\alpha}\)then
21:if\(\beta\
otin P_{z}D_{info}(\alpha)\)then
22:\(P_{z}D_{info}(\alpha)=P_{z}D_{info}(\alpha)\bigcup\beta\);
23:if\(ID_{\alpha}=ID_{Hub}\)then
24: Update peer adjacency matrix using \(P_{z}Table(\beta)\);
25:else
26: Forward the \(P_{z}D_{info}\) packet to the selected relay node;
27:endif
28: Discard the packet
29:endif
```  
**Algorithm 1** Peer Discovery30 Discard the packet
31: **endif**