# A Collaborative UAV-WSN Network for Monitoring Large Areas
## 2 Materials and Methods
### WNS Clustering Mechanism  
Clustering is a suitable routing technology for large-scale monitoring systems, with a number of advantages such as scalability, data convergence, lower load, low power consumption, robustness [31]. The WSN clustering algorithm described in this paper is conceived from the premise that a number of sensor nodes have been selected and informed by the UAV node about their cluster head role. Thus, Figure 8 illustrates a simplified clustering sequence. The clustering mechanism is based on the RIME communication stack and exchanging of broadcast and unicast messages between neighbour nodes in a random manner. Every node randomly broadcasts a message comprising its RIME unique address, current cluster membership, its role in the cluster (CH or simple) and an estimated number of cluster members. This is illustrated in Algorithm 4. ```
(1) define unicast_received(msg, from)(
2) for(every node \(i\) in list) do (3) if(i.addr and from.addr are equal)then (4) update \(i\) node values: (5) i.last_E = msg.E; (6) if(current_t = i.t)then (7) if(i.RSSI_MAX < msg.RSSI)then (8) i.RSSI_MAX = msg.RSSI; (9) endif (10) i.U = U + 1; else (11) if(i.RSSI_MAX < msg.RSSI)then (12) i.RSSI_MAX = msg.RSSI; (13) i.RSSI_MAX = msg.RSSI; (14) t = sequence_number; (15) i.U = 1; endif (17) if(i.LQI_MIN>msg.LQI)then (18) i.LQI_MIN = msg.LQI; (19) endif (20) endfor (21) if(no address matches from.addr (i==NULL))then (22) add node to the list; (23) initialise node's fields; endif (24)
```  
**Algorithm 4** The RIME algorithm for the RSSI and energy levels of the nodes. When a neighbor node receives a broadcast message, first it checks whether the sender node is or not in its list of neighbors. If it is not found, then it will be immediately added. Thereafter, it checks the sender information and decides whether to join or not the neighbor group. This decision is made depending on the number of hops to CH, the estimated signal strength (RSSI) and other criteria. This is illustrated in Algorithm 5. A node decides to join the sender's cluster starting from the main following rules: the node is not yet associated to a cluster; the node belongs to a different cluster but the number of hops to the CH is smaller or the number of hops is the same but RSSI is higher. After decision, the node informs the sender whether it has joined or not the cluster, such that both can update the number of nodes inside the cluster. After receiving a unicast message, the node checks if the sender is included in the neighbor list and updates or adds the sender's information. The next step is to update the cluster size information. This routine is described in Algorithm 6. Note that cluster size information is only roughly calculated using an average consensus estimation. Average consensus estimation refers to the fact that each node within a cluster updates its local value for cluster size based on the values reported by its known neighbors. This occurs without the existence of a central entity propagating this value throughout the network but by means of a distributed process of message exchange among neighbors. Cluster sizes might vary during the deployment of the network as nodes might become unavailable or the UAV might reinitiate the CH assignment process. Figure 8: Clustering sequence. ```
Input: msg, cluster, isCH, hopsToCH, clusterSize, CH_RSSI Output: Unicast_msg, cluster, isCH, hopsToCH, clusterSize
1. If sender is defined in the neighbor list then update neighbor node data node.cluster \(\leftarrow\) msg.cluster; node.isCH \(\leftarrow\) msg.isCH; node.hopsToCH \(\leftarrow\) msg.hopsToCH; node.RSSI \(\leftarrow\) max(RSSI);
2. Else add new neighbor to the list initialize new neighbor data node.cluster \(\leftarrow\) msg.cluster; node.isCH \(\leftarrow\) msg.isCH; node.hopsToCH \(\leftarrow\) msg.hopsToCH; node.RSSI \(\leftarrow\) msg.RSSI;
3. If cluster = 0 or node.cluster \(\
eq\) cluster then
4. If (node.isCH = 1 and isCH \(\
eq\) 1) then
5.