# Monitoring Perishable Commodities Using Cellular IoT:
## 2 Materials and Methods
### Software Architecture
#### 2.3.3 Acceleration, Communications and Readings  
The acceleration value for each measurement (\(a_{i}\)) is obtained as the total resultant acceleration of the three axes relative to gravity. The range of \(\pm 8\) g with an accelerometer sensitivity of 64 LSB/g is used. Therefore, if the accelerometer makes a three-axis measurement of \(\mathbf{a_{ADXL}}\), the value in g units will be \(\mathbf{a_{measured}}=\mathbf{a_{ADXL}}/64=\left(a_{x},\,a_{y},\,a_{z}\right)\). Then, for each measurement, the recorded acceleration is obtained as expressed in Equation (2). If a total of \(n_{a}\) accelerations is measured in those 15 min, i.e., \(\mathbf{a}=\left[a_{1},\ \dots,\ a_{n_{a}}\right]\), the average (\(a_{avg}\)) and maximum (\(a_{max}\)) acceleration values are obtained as shown in Equation (3), where \(\max(\mathbf{a})\) returns the maximum value of the set of \(\mathbf{a}\) values and \(i=1,\ \dots,\ n_{a}\). \[a_{i}=\sqrt{a_{x}^{2}+a_{y}^{2}+a_{z}^{2}}-1 \tag{2}\]  
\[a_{avg}=\frac{1}{n_{a}}\sum_{i=1}^{n_{a}}a_{i}\hskip 28.452756 pta_{max}=\max( \mathbf{a}) \tag{3}\]  
Regarding the communications, the structure of the data stored in the flash memory in CSV format is as follows: Packet Counter, Timestamp, Luminosity, CO\({}_{2}\), Relative Humidity, Temperature, Acceleration Maximum, Acceleration Average, Vibrations Number, Battery, Cell Tower. The CayenneLPP, or the Cayenne Low Power Payload format, achieves payload size optimization designed for IoT applications, making it possible to easily send data using LPWAN networks, such as NB-IoT, in a compact way. The payload structure using CayenneLPP consists of a byte indicating the channel, a byte indicating the data type and a series of bytes containing the data to be sent, which will depend on the data type being used. In this case, the data to be sent in CayenneLPP format are listed in Table 4. \begin{table}
\begin{tabular}{c c} \hline \hline
**Parameter** & **Threshold** \\ \hline Luminosity & 50 lux \\ \hline CO\({}_{2}\) concentration & 200 ppm \\ \hline Temperature & 1 \({}^{\circ}\)C \\ \hline Relative humidity & \(\infty\) \\ \hline Acceleration & 0.5 g \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Thresholds to be exceeded with respect to the previous measurement. The space occupied by the data in CayenneLPP format is 55 bytes, as indicated in Equation (4), using Table 2. The time that the flash memory can store the data in this format is, approximately, 715 days, and this can be calculated as shown in Equation (5), knowing that the sampling is every 15 min, assuming a usage of 90% of the total memory capacity and knowing that the data are stored in two different files. \[11\times(1\;\text{byte }channel+1\;\text{byte }data\;\text{type})+33\;\text{ bytes }data=55\;\text{bytes} \tag{4}\]  
\[\frac{0.9\times 8\;\text{MB}}{2\times 55\;\text{bytes}}\times 15\;\text{min} \cong 715\;\text{days} \tag{5}\]  
Furthermore, adding 8 bytes of the UDP header and 24 bytes of a typical IP header gives a total of 87 bytes each time sampled data are sent. With this, the number of bytes sent per month can be determined as depicted in Equation (6), assuming that three data are sent every 45 min by default, as will be detailed later:  
\[3\times 87\;\text{bytes}\times\frac{24\;\text{h}\times 60\;\text{min}}{45\; \text{min}}\times 30\;\text{days}\cong 245\;\text{kB/month} \tag{6}\]  
This demand could be more than covered, for example, by contracting a monthly service providing a capacity of 250 kB per month, which would be very economical. In the case of the operator used in this project, it offers a SIM card with a capacity of 500 MB.