# An Internet of Things (IoT) Application on Volcano Monitoring
## 3 IoT Thermometers Network
### Software
#### 3.2.1 Gateway Software  
As mentioned, the gateway is in charge of managing the wireless network running the master_main.py script (Figure 7). First, it tests if the repeater is available. If so, the gateway  
\begin{table}
\begin{tabular}{c c c c} \hline \hline
**Device** & **Software/Script** & **Execution** & \begin{tabular}{c} **Pregamming** \\ **Language** \\ \end{tabular} & **Purpose** \\ \hline \multirow{4}{*}{Gateway} & master\_main.py & \
\begin{tabular}{c} Every 10 min \\ (default) \\ \end{tabular} & Python & Asks the end devices for temperature value \\ \cline{2-4}  & synch.sh & Every 10 min & Linux Rash-shell & Synchronizes data between gateway and server \\ \cline{2-4}  & Rssi.py & At user’s will & Python & Asks for the RSSI of any device in the network \\ \cline{2-4}  & master\_sample.py & At user’s will & Python & Asks the end devices for temperature value \\ \hline \multirow{2}{*}{Repeater} & Repeater.cpp & Continuous & C & Relays messages between the gateway and the end devices \\ \cline{2-4}  & End device & End\_device.cpp & Continuous & C & Temperature measurement \\ \hline \multirow{2}{*}{Data Analysis Center} & join.py & Every 10 min & Python & Joins all temperature daily files in a single one \\ \cline{2-4}  & LoRa\_represent.py & Every 10 min & Python &
\begin{tabular}{c} Takes the joined file and creates a graphical \\ representation in HTML. \\ \end{tabular} \\ \hline \hline \end{tabular}
\end{table}
Table 5: Network software. RSSI: received signal strength indicators.  
Figure 6: Measurement protocol.  
sends the temperature acquisition command to the repeater, which resends the instruction to the end devices. If the repeater is not available, the process ends until the next acquisition.  
The gateway waits a specific time for the returned raw data. When data are received, the calibration curve of each temperature sensor (included in master_main.py) is applied, and then they are time stamped and stored in a USB flash drive. If a thermometer does not respond, its stored value will be \"Nan\". The storing memory has a structure of nested folders as follows: /thermometer_data/year/month, in which files are stored on a daily basis.  
Using the sync.sh script, running by default every 10 min, stored data is fully mirrored to a remote computer (data center). Data transfer is performed using rsync Linux utility [89], which minimizes the volume of data transmitted, since it employs a delta encoding algorithm that only stores bytes that have been modified since the previous version of the file.  
A master_onesample.py script operates in the same way as master_main.py, but when sending the measurement command to the end devices, they will remain in receive mode instead of going to sleep mode. This slight difference allows using this script during the installation and/or when it is desired to obtain temperature values at specific times. If the end devices' consumption and power supply are not a problem, this script can be used to manage the network.  
The last script running in the gateway is Rssi.py, which is only executed under the user's request. This script allows knowing the RSSI level of every device in the wireless network. First, it tests if the repeater is available, and if so, it sends the RSSI request for a certain device of the network, repeater, or end device, and waits during a fixed time period for the requested information. If the repeater is asked, the RSSI level is the power level of the radio signal received in the gateway emitted by the repeater. If an end device is asked, the RSSI level is the power level of the radio signal received in the repeater emitted by the end device.