# A Collaborative UAV-WSN Network for Monitoring Large Areas
## 2 Materials and Methods
### WSN Discovery and Clustering Support  
Prior to the initial photogrammetry trajectory, the sensor network decides on its cluster partitioning and selects the cluster heads. This information is sent as well to the UAV during its initial flight. Thus, the second purpose of the \"flight probe\" is to classify and identify the best suitable sensor nodes for the CH position. Sensor nodes are evaluated according to a selection algorithm that uses several relevant indicators:  
* the number of unicast messages received by the aerial vehicle from each sensor node \(i\) denoted \(U_{i}\), \(U_{i}\in M=\{U_{1},\ldots,U_{n}\}\), where \(M\) is the sensor node set; a set of sensor nodes consists of the individual sensors nodes which reply to the broadcast sequence \(t\) sent by the UAV towards the ground network;
* the maximum received signal strength indicator (RSSI) value (in dBm) of the unicast messages received from each sensor node \(i\) denoted RSSI_MAX\({}_{i}\), where \(i\in M\);
* the minimum link quality indicator (LQI) value of the unicast messages received from each sensor node \(i\) denoted LQI_MIN\({}_{i}\), where \(i\in M\);
* the last battery/energy level indicator value (in %) received from each sensor node \(i\) denoted E\({}_{i}\) where \(i\in M\);
* the broadcast sequence number \(t\), which is used to distinguish nodes belonging to groups selection. To be able to evaluate the node's parameters it is necessary to define a dynamic list in the program memory of the UAV's node. The node structure is composed of unique address, unicast number, signal strength and quality indicator, battery level and broadcast sequence (Algorithm 1). For ease of implementation and understanding, we have defined a file in which the ground sensor responses are retained, including the unique address, the signal strength (RSSI) at the reception and the time label. ```
(1)define the structure of a node{ (2) pointer to the next_node (in the list of nodes); (3) RIME_address; (4) number of unicast messages received U; (5) energy level last_E; (6) maximum RSSI value RSSI_MAX; (7) maximum LQI value LQI_MIN; (8) broadcast sequence t; (9) }
```  
**Algorithm 1**Node structure and memory allocation pseudo-code. The dialogue between sensor nodes is based on the RIME communication stack, using unicast and broadcast messages [30]. Two threads are required for this mechanism. Figure 6 illustrates the sequential diagram of the UAV-WSN survey dialogue. The broadcast process (Algorithm 2) manages the broadcast packet transmission sequence. In order to meet the mandatory requirement, to fully cover the area of interest, the broadcast routine is periodically called at a specific sample time, which is closely related to the flight speed. UAV navigation speed during the experiments is around 3 m/s which had been found suitable to allow communication with the ground sensors. Packet collision is handled at the lower stack of the communication protocol using the CSMA/CA mechanism. Given the fact that we use a quadcopter system with no minimum navigation speed this allows good performance for WSN packet collection. Such a broadcast/unicast message exchange sequence is described in Figure 7. Time between broadcast calls is marked with \(t\). Unicast responses of sensor nodes are illustrated with green concentric circles and denoted \(u_{i}\), where \(i\) is the current number of unicast received from the same ground sensor node at different sequences. Sensor node's radio cover range is marked with a grey dotted circle. Similarly, UAV's cover range is marked with red concentric circles. The UAV enables the broadcast session by time (\"survey_ON\" is assigned true). A \"PING\" broadcast message including the broadcast sequence number \(t\) is sent. The second process thread manages the unicast messages received from ground sensor nodes. When sensor nodes receive a \"PING\" broadcast message, they respond to the UAV node with a unicast message in which the current battery level is transmitted.