# LoRaWAN Networking in Mobile Scenarios Using a WiFi Mesh of UAV Gateways
## 3 The LoRaUAV System
### Connection Recovery and Maintenance (CRM) Algorithm  
In LoRaUAV, partitions of the UAVs are difficult to avoid. Disconnections might be caused by difficult environmental conditions or by one or more UAVs that go too far from nearby UAVs due to strong attractive forces. Some mechanisms are therefore integrated in the system to recover the connectivity with the UAV formation and with the BS. After the connection to the BS is recovered, a connection maintenance procedure is triggered. Figure 2 shows the developed CRM algorithm. The CRM algorithm has three mobility modes: the VSF mobility described in Section 3.2, the Network Recovery Mobility (NRM), which consists in moving the drone towards the BS to recover the connection, and the Stationary Mobility (SM), which forces the drone to hover over a location. The _pause_ and _persist_ parameters are used to select the mobility mode. The _pause_ parameter is a positive integer that specifies for how many time intervals the UAV has to remain stationary. When a connection with the BS is recovered thanks to the NRM, the SM is activated and kept active for \(pause\times\Delta T\) time intervals in order to avoid further disconnections. Every UAV sets _pause_ according to the following expression:  
\[pause=\left\lfloor P_{max}\frac{R_{max}}{D_{BS}}\right\rfloor\,, \tag{10}\]  
where \(P_{max}\) is the maximum number of pause intervals, \(R_{max}\) is the maximum communication range and \(D_{BS}\) is the current distance from the BS. \(R_{max}\) is updated progressively thanks to the position information periodically exchanged with neighboring UAVs. Equation (10) assigns a more conservative behavior to drones that are closer to the BS and therefore more likely to cause the disconnection of a larger part of the network. On the contrary, peripheral UAVs can act more freely, since their temporary disconnection is less likely to cause the partition of other parts of the network. The _pause_ parameter is ignored only when the _load_ parameter is zero. This parameter measures the number of relayed packets during a time window of fixed length \(t_{load}\) and it can therefore be used to select inactive UAVs free to move without the constraints imposed by the CRM algorithm. The _persist_ parameter is a positive integer that specifies for how many time intervals the UAV has to keep using the VSF mobility even without a connection to the BS, with the hope that a connection can be recovered thanks to the rearrangement of other UAVs. The _persist_ parameter is set according to the following expression:  
\[persist=\left\lfloor(hops-1)\frac{D_{BS}}{R_{max}}\right\rfloor\,, \tag{11}\]  
where _hops_ is the last recorded hop distance between the UAV and the BS. Equation (11) allows peripheral UAVs to be dragged by VSF forces for a longer time, even if they are isolated. On the contrary, UAVs closer to the BS are less tolerant to disconnections and try to recover a connection faster. It is possible that a group of UAVs, sharing some covered GNs, gets isolated from the swarm. In this case, the typical _persist_ behavior would not exploit the redundant UAVs to recover the connectivity. Instead, all the UAVs would trigger the NRM at almost the same time and all would loose the connection with the covered GNs. To avoid this situation, UAVs that are covering a set of GNs determine, after loosing the connection, the neighboring UAV with which they share the highest percentage of GNs. If this percentage is above a certain threshold \(p_{shared}\), one of the two UAVs is redundant. Every UAV has a fixed ID that has been assigned before the operation. The UAV with the lowest ID among the two cuts by half its _persist_ intervals, while the other UAV doubles those intervals. In the next time steps, the UAV with the lowest value of _persist_ triggers the NRM before the othersand repositions itself closer to the BS. This helps to recover a connection with the UAV swarm without loosing the GNs.