# Study of Data Transfer in a Heterogeneous LoRa-Satellite Network for the Internet of Remote Things
## 4 Gateway Encoding and Packaging Method (GDEP)
Let us define the following variables:  
\(n\)--the number of types of sensor messages in the buffer;  
\(m\)--the number of SBD containers;  
\(b_{j}\)--the number of messages of type j, \(j\ =\ \overline{1..n}\);  
\(v_{j}\)--the volume of messages of type j (in bytes), \(j\ =\ \overline{1..n}\);  
\(x_{ij}\)--the number of messages of the j-th type in the i-th SBD container, \(i\ =\ \overline{1..m}\), \(j\ =\ \overline{1..n}\);  
\(y_{i}\)--flag indicating whether a container is empty (0) or not (1);  
\(S\)--size of the SBD container (in bytes)  
\[\min\sum_{i\ =\ 1}^{m}y_{i}. \tag{1}\]  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Number of** & **Total Number** & **Average Message Size** & **Average Message Size in** & **Message Size** \\
**Sensors** & **of Messages** & **in JSON Format (bytes)** & **the Protobuf Format (bytes)** & **Ratio (3/4)** \\ \hline
1 & 32 & 340 & 78 & 4.36 \\
2 & 90 & 369 & 82 & 4.5 \\
3 & 153 & 398 & 86 & 4.62 \\
4 & 170 & 427 & 90 & 4.74 \\
5 & 177 & 456 & 94 & 4.85 \\
6 & 143 & 485 & 9  
Subject to the following constraints:  
The total size of messages fitted into one container cannot exceed the corresponding container size  
\[v_{i}x_{i1}+\ldots+v_{n}x_{in}\leq S,\;i\;=\;1..m. \tag{2}\]  
Since all messages of each type have to be transmitted,  
\[x_{i1j}+x_{2j}+\ldots+x_{mj}\;=\;b_{j},\;j\;=\;1..n\;. \tag{3}\]  
We define the lower limit of the number of messages \(m^{\prime}\)--the number of transmitted packets, for which buffer messages from the buffer with the volume V can be transmitted with the volume of the short message \(S\), subject to the constraints (2) and (3):  
\[m^{\prime}\;=\;\frac{\sum_{j\;=\;1}^{n}v_{j}b_{j}}{S}. \tag{4}\]  
Additional constraints can be defined in simulation modelling. These can be the lifetime of a single IoT device, the rate at which new messages arrive and, as a result, the number of simultaneously open SBD containers. The total transmission time of each message from endpoint devices to the data collection system should not exceed the threshold value--\(\mathrm{T}_{\mathrm{P}}\). The main task will be to choose the most suitable algorithm that uses the smallest number of containers and introduces a delay in the process of sending messages no more than \(\mathrm{T}_{\mathrm{P}}\). Since the packing problem is NP-complete, the minimum number of required containers can be determined only by the exhaustive search method. We consider several existing approximate packaging algorithms [56; 57]:  
Algorithm 1: \"First suitable with one open container\". Messages are selected sequentially from the buffer and placed in the first container. If a new message cannot be placed in the current container, then a new container is opened. The filled container is closed and shipped. Algorithm 2: \"First suitable with multiple open containers\". Messages are selected sequentially from the buffer and placed in the first container. If a new message cannot be placed in the current container, then the next free container is used. Unlike the previous algorithm, all containers remain open and are closed only after all messages from the buffer are placed. Algorithm 3: \"First suitable with multiple open containers and message sorting\". The messages in the buffer are sorted in descending order of size. After that, messages are selected sequentially from the buffer and placed in the first container that has sufficient space. All containers remain open and close only after all messages from the buffer are placed. We compared the operation of the three algorithms using the architecture of a heterogeneous network (Figure 2). One thousand LoRa messages were generated from sensor nodes with different amounts of data--from 1 to 13 (the number of messages is determined by the Poisson distribution)--and messages were packed using the three algorithms under consideration. The simulation results are presented in Table 3.  
It can be concluded that Algorithm 1 is no more than 2% worse than algorithm 3.