# Data Collection in Areas without Infrastructure Using LoRa Technology and a Quadrotor
## 3 Configuration and Programming
```
1:Define Libraries
2:Define Variables
3:Trigger Directories and files
4:Define PERIOD, Package creation interval
5:while True do
6:Open file.log
7:Get last recorded file position
8:Diffine LastFileName with last recorded file name
9:if Time Minutes%PERIOD == 0 then
10:Define FileName with gmtime
11:else
12:Define FileName as LastFileName
13:endif
14:if FileName!= LastFileName then
15:Set last file status as READY
16:Write package status in.log file
17:Write new package name (FileName) in the.log file
18:Generate new package file
19:endif
20:endwhile
```  
**Algorithm 2** File manager  
Communication between the monitoring station and the reception system is an essential factor, so it is necessary to implement a sequence to request that the stations send the data packages that have been collected over a given time interval (the frequency with which the UAV performs the route). The amount of packages to be sent in each UAV trajectory is based on the time frame that allows connection between the reception and transmission devices, and the average required time to transmit each of the packages. During the recollection tests, three packages were received from each buoy. In addition, the receiver must be able to identify the device that sends the information, and thus store it in the section dedicated to that station (see Algorithm 3). At this stage, the objective is to cover four main conditions, which are to evaluate the relationship between the power of a signal and the power of the SNR, where a value greater than 0 indicates that the received signal operates above the noise level [24]. The received signal strength indicator (RSSI) transmits a message to the UAV when the signal quality is in an appropriate range, transmits the data packages in the \"READY\" state, and sends a message to the transceiver when the transmission is complete. For this reason, the Algorithm 3 was designed to send the data stored locally in the station to the UAV receiver, covering the established requirements. Wireless communication uses REYAX RYLR896 model transceivers, which use a LoRa communication protocol. Therefore, Algorithm 4 is designed to perform six tasks: configure the transceivers to work on the same network; request and identify the station from which the data are transmitted; receive the data sent by the station; locally store the data collected by each station; classify the information into directories for each of the stations; and generate a file with a record of the packages received, as well as their status. ```
1:Define Libraries
2:Define Variables
3:Define Transceiver configuration
4:while True do
5:while not connectedToDrone do
6:Receive Buffer data in rcv
7:if rcv in good quality range then
8: Send CONTACT message
9:endif
10:ifSTART in rcv then
11: connectedToDrone = True
12:endif
13:endwhile
14:while connectedToDrone do
15:Open.log file
16:Search Package with READY status
17:if There are no packages to send then
18:while No confirmation received do
19: Send END TRANSMISSION message
20:endwhile
21: connectedToDrone = False
22:endif
23:if Package status as READY then
24:Get Package name
25:Open Package File
26:while No confirmation received do
27: Send Message with package name
28:endwhile
29:for Data in package file do
30:while No confirmation received do
31: Send message with data record
32:endwhile
33:endfor
34:while No confirmation received do
35: Send End of package message
36:endwhile
37:To update Package status in.log file
38:endif
39:endwhile
```  
**Algorithm 3**Sender  
It is important to mention that a stage was added to validate each of the messages received during transmission, to collect all the data in the correct format, and to reduce the loss of information [25; 26]. For this, regular expressions corroborate the package name, data, and control messages. At the end of the routine, it must be decided whether it is possible to proceed to the next reception phase or whether a request is sent to the sender device to retransmit the last message until it is validated as a valid message format.