# Data Collection in Areas without Infrastructure Using LoRa Technology and a Quadrotor
## 3 Configuration and Programming  
In the state of Hidalgo, Mexico, we developed version 1 of the software for data collection and monitoring systems, which consists of five different programs in Python [21]. These programs were run independently in the operating system loaded in the Raspberry OS for each of the monitoring stations or for the UAV. The programs Receiver and Uploader, which belong to the data collection system (see Figure 3), were run in the Raspberry Pi OS installed in the Raspberry Pi Zero. The monitoring system was divided into three different programs: Sensors, File Manager, and Sender (see Figure 2). These programs were run simultaneously on different consoles within the operating system Ubuntu, which was installed in a Raspberry Pi 4. The algorithm for each of these programs is explained below. The sensor program is responsible for identifying the file in which the sensor readings can be recorded. Once it accesses that package, it performs the measurements with the sensors and writes the data in the corresponding file. Thus, a package is generated with all the data obtained during the indicated time interval, taking care to have a low bit rate and stable connectivity [22]. The size of each package depends on the frequency of the sensor's measurements (e.g., 30 s, 1 min) and the time frame for each of the packages (e.g., 20 min, 1 h, 2 h), so the file size can be around 500 bytes to 2500 bytes. This process of these tasks is described in Algorithm 1. ```
1:Define Libraries
2:Define Variables
3:Define PERIOD, Package creation interval
4:while True do
5:if Time Minutes % PERIOD == 0 then
6:Open file.log
7:Get package name with status WRITING
8:endif
9:if fileName is defined then
10:Open package file
11:while Time Minutes % PERIOD!= 0 do
12:Read Temperature
13:Read Turbidity
14:Read Conductivity
15:Read Dissolved oxygen
16:Write sensors data in package file
17:endwhile
18:endif
19:endwhile
```  
**Algorithm 1** Sensor reading  
A LoRa communication system generally consists of LoRa nodes and a gateway, which is essential for interacting with the environment and transferring data to the network server for analysis [23]. However, a data processing stage must be created focused on storing data in packages created at specific time intervals in order to generate a tracking history. In addition, a control mechanism should also be implemented to indicate which program can access such packages. The second algorithm is the main program of the monitoring system. The file manager is responsible for creating files that the sensor subsystem will use. These files are used to record the measurements made by the sensors. Subsequently, a data package is created periodically as well as a history file, with all the created packages files information that contains the name, file location, date and time of creation, and their current status. The  
Figure 3: UAV system diagram for data collection. status is used to manage the access to the packages, so each of the system's programs can access the status and know if the packages are being written, are ready to be sent, or have been transmitted to the UAV. This is described in Algorithm 2. It is important to mention that the algorithm is constantly requesting and confirming the reception of the information, as is shown in Algorithms 3 and 4; therefore, in case of a momentary loss of connection, the transmission will continue from the point at which it was interrupted.