# Monitoring Perishable Commodities Using Cellular IoT:
## 2 Materials and Methods
### Software Architecture
#### 2.3.2 Strategies for Communications and Sending Frequency  
Moreover, when sending data wirelessly with the SIM7000G, the possibility that there is no NB-IoT coverage in the area where the data area transmitted is taken into account. The strategy used is illustrated in the flowchart in Figure 5. To do this, when connecting the communication module, first, the use of LTE antennas is forced by an AT command so that it can first find the NB-IoT and LTE-M networks. First, the NB-IoT preference is set, and a check is made to see if the connection can be established. If not, the LTE-M preference is enabled as the second option and is again checked to see if it can connect in this mode. In case none of the previous LPWANs work, the module is configured to use the GSM or LTE antennas automatically and connect to the network that is able, including the GSM and EGPRS networks. During this connection establishment stage, sufficient time is allowed to elapse between AT commands so that the configuration can be correctly applied to the SIM7000G. Figure 5: Flowchart of the strategy used to establish wireless connection. The radiofrequency synchronization of the timestamp is performed only when the system sends the data, taking advantage of that moment of communication to optimize the energy consumption of the system. The rest of the measurements every 15 min are recorded with the timestamp obtained from the internal RTC of the microcontroller, and, to avoid the possible drift that may occur in the long term, this synchronization is carried out. Along with the hardware used to optimize battery consumption, a series of software improvement strategies related to the frequency of wireless data transmission was implemented to further extend system autonomy, in addition to those already mentioned so far. First of all, it is recalled that, by default, the system wakes up, takes sensor measurements and saves them in flash memory with their timestamp every 15 min. The sending of the data wirelessly by NB-IoT will depend on the state of the battery, the number of vibrations and the difference with respect to the previous measurement. The setting of the data sending frequency depending on these factors is illustrated in the flowcharts in Figure 6.  
When the battery falls below certain preset thresholds, the data transmission frequency decreases. At the lowest threshold, the accelerometer interrupt wake-up is disabled, though it still measures vibration when the system wakes up. Normally, with a fully charged battery, the system sends data wirelessly every 45 min. The specific battery voltage values and transmission frequencies are shown in Table 2.  
If there is excessive vibration, for example, on a rocky road, where the predefined vibration threshold is exceeded many times in a short time, the accelerometer wake-up is not enabled until 30 min after the end of that section. If there is an excess of vibrations in between, the wait is reset to 30 min. This excess of vibrations was defined as waking up by vibration 20 times or more. If this threshold is not exceeded, the external accelerometer interrupt wake-up is enabled. \begin{table}
\begin{tabular}{c c} \hline \hline
**Battery Voltage** & **Sending Frequency** \\ \hline Battery charged (\(>\)3.9 V) & Sending every 45 min \\ \hline Battery \(<\) 3.9 V & Sending every 1 h \\ \hline Battery \(<\) 3.8 V & Sending every 1 h 30 min \\ \hline Battery discharged & Sending every 2 h and no enabling \\ (\(<\)3.7 V) & accelerometer wake-up \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Battery voltage values and sending frequencies. Figure 6: Flowcharts of the data sending frequency establishment strategy.