<figure><img src="image_1.png" /></figure>

ifip

International Federation for Information Processing

This document is the original author manuscript of a paper submitted to an IFIP
conference proceedings or other IFIP publication by Springer Nature. As such, there
may be some differences in the official published version of the paper. Such
differences, if any, are usually due to reformatting during preparation for publication or
minor corrections made by the author(s) during final proofreading of the publication
manuscript.
# SAF: A Peer to Peer IoT LoRa System for
Smart Supply Chain in Agriculture

Aristeidis Karras¹ Ⓒ, Christos Karras¹ Ⓒ, Georgios Drakopoulos¹,² Ⓒ, Dimitrios Tsolis³ Ⓒ, Phivos Mylonas² Ⓒ, and Spyros Sioutas¹ Ⓒ

¹ Decentralized Systems Computing Group

Computer Engineering and Informatics Dept., University of Patras, Hellas
{akarras, c.karras, sioutas}@ceid.upatras.gr

² Humanistic and Social Informatics Laboratory
Department of Informatics, Ionian University, Hellas
{c16drak, fmylonas}@ionio.gr

³ Cultural Heritage Management and New Technologies Department
University of Patras, Agrinio Campus, Hellas
dtsolis@upatras.gr

**Abstract.** In the dairy industry farming as well as transportation conditions are paramount to product quality and to the overall supply chain resiliency. However, modern farms are complex installations with a broad spectrum of factors such as atmospheric conditions, including rain and humidity, ground composition, and highly irregular animal motion making difficult the deployment of digital telemetry systems. These conditions in turn translate to technical requirements including easy maintenance, scalability, wide coverage, low power consumption, strong signal resiliency, and high spatial resolution. Perhaps the best way to meet them is an LPWAN based IoT deployment. Along this line of reasoning, here is presented the architecture of SAF, an integrated IoT system built on LoRa technology for monitoring the supply chain of a dairy farm ensuring livestock and food safety with emphasis placed on monitoring the states of sheep, milk refrigerator, and milk trucks. LoRa was selected after an extensive comparison between the major latest generation LPWAN protocols. SAF is slated to be implemented in a local cooperative to monitor the production of protected designation of origin products.

**Keywords:** Internet of Things · Smart Agriculture · Supply Chain Management · Event Detection · Trajectory Modeling · LPWAN · LoRa

## 1 Introduction

Dairy product management presents some of the hardest challenges in smart agriculture due to the volatile nature of milk and the temperatures required to maintain it, which are close to those at the core of *unbroken cold chains* for handling the transportation of medical supplies. Moreover, the protected designation of origin (PDO) food and wine producers across the EU are obliged to satisfy additional quality restrictions. As a result, dairy production stakeholders
have focused their attention to farm automation and manufacturing process automation in order to boost farm productivity, ensure the safety of dairy goods, and maintain acceptable well being conditions for the animals [2].

Past attempts to introduce high tech solutions to dairy farming have had limited success [26] due to a number of factors such as atmospheric conditions including dust and humidity, irregular farm geometry preventing effective coverage unless a prohibitive number of monitoring equipment was employed, interference from nearby mountains and hills, and even in certain documented cases signal scattering attributed to high concentration of gases such as methane and ammonia caused by heated animal excrement. In this context and based on lessons from earlier attempts, integrating Internet of Things (IoT) with operations and the supply chain is the principal motivation behind this work.

The primary research objective of this paper is the presentation of the architecture and intended functionality of SAF, a system for monitoring milk production and distribution safety. The initials of SAF stand for *safe for animal and food*. The system will be based on LoRa functionality for data transmission and collection, differentiating itself from the majority of previous smart farming approaches which rely on short range protocols.

The remainder of this paper is structured as follows. In section 2 the scientific literature for smart farming is overviewed. The SAF architecture, the criteria for selecting LoRa, and the intended functionality are described in section 3 and the analytics implemented over SAF in section 4. This work concludes in section 5. Technical acronyms are explained the first time encountered in the text. Finally the notation of this work is summarized in table 1.

<table><caption>**Table 1.** Notation of this paper.</caption><thead><tr><th>Symbol</th><th>Meaning</th><th>First in</th></tr></thead><tbody><tr><td>△</td><td>Definition or equality by definition</td><td>Eq. (1)</td></tr><tr><td>⟨p || q⟩</td><td>Kullback-Leibler divergence between p and q</td><td>Eq. (2)</td></tr></tbody></table>

## 2 Related Work

Animal identification and traceability are in continual demand driven by quality control and welfare management requirements [19]. Additionally, infectious diseases like the bovine spongiform encephalopathy (BSE), popularly known as mad cow disease, have prompted the creation of such systems [15]. Safety and quality considerations developed over the past decade provide yet another reason to utilize computerized methods of farmed animal identification [21]. Radiofrequency identification (RFID) technology has been among the first to be utilized to monitor both domestic and wild animals, however RFID tag techniques have yet to be standardized [22]. Moreover, RFID technology despite its wide adoption in smart farming [26] falls short on performance factors as it is affected by
animals and the environment [1]. More recently Arduino systems for tracking
cattle position and speed have been proposed [5] as well as concurrent actuator
networks assessing environmental variables such as temperature and humidity
for remote vineyard irrigation [7]. Blockchain for smart farming is explored in
[9] and smart contracts for vineyards in [27]. LoRa systems gather vital signals
from grazing cattle as in [18]. In particular, portable nodes with STM32 micro-
controllers equipped with accelerometers and GNSS position collect data and
communicate them to a Raspberry gateway. LoRa is also used in [20] to regulate
ammonia diffusion coefficient in pig farms with gas concentration values being
processed by a neural network for event detection.

Sampling is a crucial process across every discipline. With random sampling as indicated in [17], elements are taken in a probabilistic way for further processing. While sampling across complex geometric objects as in [16] with the use of Markov Chain Monte Carlo methods appears to be a successful approach.

Streaming applications such as sensor-based deployments can often be consid-
ered as graph signal processing methods as in [10] in which, the data associated
within two graphs is processed in a compressed way. In the modern era, IoT as
well as cloud, edge, and fog computing have recently gained popularity [8] where
the latter paves the way for more research. Numerous research communities are
vested in the study of spatio-temporal events. Trajectories have been employed
in a variety of disciplines, among social sciences, genetics, pharmacy, geology,
and data mining. The robustness of each attribute trajectory can be evaluated
by stacking-based visualizations [25] or graph structural resiliency methods [12].
With the rapid emerge of Industry 4.0, graph analytics and multi-layer graphs
have developed in order to aid in process mining [11].

3 SAF Description

## 3.1 Objectives and design

SAF as stated earlier is designed for facilitating agribusiness and ensuring food
and animal safety by monitoring in real time critical variables of the primary
entities of the milk supply chain. The latter along with the associated variables
and the respective monitoring frequency are listed in detail in table 2.

The system proposed here can contribute to the dairy product quality in two
ways. First, by the timely discovery of ill animals, either by measuring its tem-
perature or by predicting an imminent abnormality through neural networks,
any disease can at best have a limited spread in the farm. Second, predictive
analytics can reveal hidden defects along the milk production process. In ei-
ther case, identifying and solving problems early in the supply chain frequently
translates to saving considerable costs, downtime, and personnel efforts.

SAF architecture can be represented as a pyramid as shown in figure 1 where
higher layers are related to management and analytics, whereas lower ones to
data collection and communication. The role of each layer is as follows:

- Sensors and microcontrollers: This is the physical layer of SAF. It includes the sensors and actuators attached to farm animals or to the other
entities transmitting the appropriate data to a LoRa gateway and subsequently to upper layers through the SAF API.

- **SAF API:** It is the system middleware for communication between the physical and the upper layers. Each API call fetches the data from the sensors and creates an HTTP post request to the database for each parameter.

- **Database:** In this layer data obtained from the SAF API in a serialized JSON format is transformed to and stored as key-value pairs in a local NoSQL database for short- and mid-term analysis purposes.

- **Cloud:** The cloud service complements the database as a reliable storage space and additionally makes the overall project available worldwide for registered farmers. Communication takes place through Google Firebase.

- **App:** The mobile application displays all monitored instances in real-time to interested parties. This allows the easy localization of problems in the supply chain and consequently their early correction.

<figure><img src="image_2.png" /><figcaption>Fig. 1. SAF layers.</figcaption></figure>

SAF constantly monitors the variables shown in table 2 along with the respective monitor frequency. For farm animals temperature is a primary health indicator and hence measurements for it are taken in real time. Moreover, as certain patterns in their respective trajectories may denote agitation, declining health, or any other abnormality, herd motion is tracked at regular intervals. Heat stress levels, caused by temperature, humidity, sun radiation, wind direction, and precipitation, is evaluated through indicators [3]. The same holds for hunger stress levels since affected animals produce significantly less [6].

Regarding the farm living conditions including temperature, humidity, and methane concentration are crucial for livestock well being and they are monitored in real time. Milk tanks have certain operating profiles determined by temperature, humidity, milk pH, and the weight and level of milk. The latter
<table><caption>**Table 2.** SAF Variables.</caption><thead><tr><th colspan="4">SAF Variables, Intervals and Technologies</th></tr><tr><th>Entities</th><th>Variables</th><th>Intervals</th><th>Technologies</th></tr></thead><tbody><tr><td>Sheep</td><td>Temperature<br>Daily Average<br>Location</td><td>5m<br>24h<br>varies</td><td>LoRa and GPS</td></tr><tr><td>Farm</td><td>Temperature<br>Humidity<br>Methane</td><td>5m<br>5m<br>5m</td><td>WiFi and RFID</td></tr><tr><td>Milk Tank</td><td>Temperature<br>Humidity<br>pH<br>Level<br>Weight</td><td>5m<br>5m<br>1m<br>30m<br>varies</td><td>WiFi and Arduino</td></tr><tr><td>Milk Truck</td><td>Temperature<br>Humidity<br>Level<br>Location</td><td>10m<br>10m<br>30m<br>varies</td><td>GSM and GPS</td></tr></tbody></table>

two are relative and they are recorded only at the start of milk production process. Finally, milk trucks must provide viable transportation environments by having low temperatures and low humidity. GPS and GSM technologies provide real time measurements with the latter consuming a significantly less energy.

For the sheep monitoring and management, the system is built around a Lilygo T-Beam LoRa transceiver module with an integrated GPS and a battery holder. The ability to either receive or transmit with a single chip reduces the complexity to one per farm animal plus one more chip acting as a stationary gateway to the cloud. This results in a p2p IoT network where each farm animal is uniquely identified by its respective chip id. In the farm itself the measurements are transferred to the cloud via a static WiFi component.

Figure 2 depicts the four instances being posted to the API and fetched through the mobile application. Initially, data is gathered from ESP32 chips. Then, HTTP post requests publish data to the cloud. The JSON objects carrying sensor data are marked by timestamps. JSON has been selected since it is a common standard for text information exchange [13]. The JSON values supplied to the Firebase API vary depending on the instance. For example, for a sheep are reported its id, temperature, latitude and longitude, and timestamp.

- doc["SheepID"] = ESP.getChipId();

- doc["SheepTemperature"] =< temperature sensor >;

- doc["SheepLat"] = GPSx;

- doc["SheepsLon"] = GPSy;

- doc["Timestamp"] =< current_time >;
<figure><img src="image_3.png" /><figcaption>Fig. 2. SAF system data flow.</figcaption></figure>

The above information is shown in the pop-up notification along with the location and temperature once an animal is identified as being ill. Additionally, beeper linked to the animal sounds to indicate its position. As a result, the affected animal will be swiftly isolated from the herd and will not be milked.

## 3.2 Wireless network protocol comparisons

The protocols suitable for livestock management are shown in table 3. Having successfully analysed all available network protocols, we select the LoRa technology for this particular use case due to high range and low-power consumption.

The main disadvantage of current animal tracking systems is the short battery life span. Given that farm animals continuously move and may well roam up to a few kilometers, the microcontroller must be power-efficient. LoRa chips besides being able to operate with few recharges can be put into a deep sleep mode for hours, thereby prolonging system life. Because of the same reasons, a long range network must be employed. LoRa provides the best combination of range, signal resilience and simultaneously free to use, which is important given the volatile conditions of large animal farms. For this case, LoRa is the superior alternative in terms of cost-effectiveness, deployment, and maintenance. Moreover, it benefits from a free world license in contrast to the SigFox subscription.

# 4 Analytics And Events

Event detection is crucial in IoT deployments. Since in the proposed architecture data comes in a streaming format, it makes sense to rely on reservoir approaches to collect samples for event detection [17].
<table><caption>**Table 3.** Comparison of LPWAN technologies (Compiled from [24][14][23]).</caption><thead><tr><th>Parameter</th><th>LoRa</th><th>SigFox</th><th>NB-IoT</th></tr></thead><tbody><tr><td>Standard</td><td>LoRa Alliance</td><td>SigFox / ETSI LTN</td><td>3 GPP Release 13,14</td></tr><tr><td>Bandwidth</td><td>250 kHz</td><td>100 Hz</td><td>200 kHz</td></tr><tr><td>Modulation</td><td>FSS/CSS</td><td>D-BPSK</td><td>QPSK</td></tr><tr><td>Spectrum</td><td>1175 kHz</td><td>200 kHz</td><td>200 kHz</td></tr><tr><td>Frequency band</td><td>EU : 868MHz</td><td>EU : 868MHz</td><td>7 – 900MHz</td></tr><tr><td>Range (urban)</td><td>2 – 5 km</td><td>3 – 10 km</td><td>1 – 5 km</td></tr><tr><td>Range (rural)</td><td>20 km</td><td>50 km</td><td>10 – 15 km</td></tr><tr><td>Max Data Rate</td><td>50kbps</td><td>100bps</td><td>200kbps</td></tr><tr><td>Throughput</td><td>50kbps</td><td>-</td><td>-</td></tr><tr><td>Energy Consumption</td><td>Very low</td><td>Very Low</td><td>Low</td></tr><tr><td>Security</td><td>AES 128b</td><td>Optional encryption</td><td>L2 security</td></tr><tr><td>Localization</td><td>TDOA</td><td>RSSI</td><td>-</td></tr><tr><td>Topology</td><td>Star-of-stars</td><td>Star</td><td>Star</td></tr><tr><td>Battery Life</td><td>~ 10 years</td><td>~ 10 years</td><td>~ 10 years</td></tr><tr><td>Cost</td><td>Moderate</td><td>Moderate</td><td>High</td></tr></tbody></table>

Under ideal operating conditions each chip will consume the same amount of energy. Still the actual distribution of the N chips of (1) may well be different.

$$p_k \triangleq \frac{e_k}{\sum_j e_j}, \quad 1 \le k \le N \qquad (1)$$

The Kullback-Leibler divergence can quantify this difference as shown in (2).

$$\langle p || r \rangle \triangleq \sum_{k=1}^{N} p_k \log \left( \frac{p_k}{\frac{1}{N}} \right) = \sum_{k=1}^{N} p_k \log p_k + \log N \qquad (2)$$

The way animals move can denote conditions such as agitation or illness depending on certain characteristics. To this end, trajectory analytics will be used. In particular, n GPS measurements are taken per a reference time interval T in latitude and longitude pair format. First, the average velocity v of each farm animal is computed as in equation (3).

$$v \triangleq \frac{n-1}{T} \sum_{k=1}^{n-1} \sqrt{(x_{k+1} - x_k)^2 + (y_{k+1} - y_k)^2} \qquad (3)$$

The least squares (LS) reference line for the i-th animal during T can be computed by the LS solution of the system (4) by any standard method.

$$\begin{bmatrix} y_1 \\ \vdots \\ y_n \end{bmatrix} = \begin{bmatrix} x_1 & 1 \\ \vdots & \vdots \\ x_n & 1 \end{bmatrix} \begin{bmatrix} a_i \\ b_i \end{bmatrix} \qquad (4)$$
Once the LS coefficients $a_i$ and $b_i$ are computed, then the deviation of each animal from the respective reference line is the residual error $r_i$ defined as in (5):

$$r_i \triangleq \sum_{k=1}^{n} |y_k - (a_i x_k + b_i)| \quad (5)$$

Once the direction coefficients $a_i$ are computed for each animal, then the general herd direction $a_0$ can be defined as the average or median value. Then the deviation angle $\vartheta_i$ for the i-th animal can be found as in (6).

$$\vartheta_i \triangleq \arctan a_i - \arctan a_0 \quad (6)$$

Finally, the temperature-humidity index (THI) of (7) is a major indicator of the farm condition where $T$ is the farm temperature is Celsius degrees and $R$ is the percentage of relative humidity [4].

$$\text{THI} \triangleq (1.8T + 32) (0.55 - 0.0055R) (1.8T - 26) \quad (7)$$

Note that the above analytics are indicative and can be enriched should the need arise. The events of interest in the context of SAF are listed in table 4. For each such event, an event notification is generated and sent to the mobile app.

<table><caption>**Table 4.** SAF events of interest.</caption><thead><tr><th>Entity</th><th>Farm event</th></tr></thead><tbody><tr><td>Animals</td><td>Deviation from the herd<br>Unusual temperatures<br>Large percentage of slow animals<br>Incoherent herd move</td></tr><tr><td>Farm</td><td>Milk production drop<br>High methane concentration<br>Low air humidity</td></tr><tr><td>Tank</td><td>Unusual temperatures<br>Unusual milk level<br>Unusual pH values</td></tr><tr><td>Truck</td><td>Unusual pH values<br>Large route deviation</td></tr></tbody></table>

# 5 Conclusions

This paper focuses on the design specifications and architecture for SAF, an integrated IoT system for monitoring milk production and ensuring dairy product quality while being as less invasive as possible. To this end, SAF will monitor the
status of the main entities of the milk supply chain including the livestock, the farm, the milk collection tank, and the milk trucks. The data collected will be transmitted over a p2p network to a central point where a range of analytics like animal trajectories and location clustering will be computed. SAF will be based on the emerging LoRa technology, which was selected among competing LP-WAN wireless communication protocols according to performance criteria such as range, coverage, signal resilience, and ease of maintenance. These are major technical specifications designed to overcome adverse geographical and environmental factors such as irregular farm geometry, high humidity, low temperatures, and high altitude. Once completed, SAF is scheduled to be deployed to a local cooperative for the production of milk and PDO cheese.

**Acknowledgment** This paper was completed in the framework of the project: "SAF: Safe for Animal and Food: Integrated System for Interactive Monitoring, Recording and Optimization of Animal Health and for the Safety and Quality of Animal Food", Case Study: Feta Cheese of Kalavryta (Designation of Origin). Contract No M16ΣΥΝ-00452, Agricultural Development Programme, Measure 16, Sub_Measure 16.1, Action 1.

## References

1. Angeles, R.: RFID technologies: supply-chain applications and implementation issues. Information systems management **22**(1), 51–65 (2005)

2. Bhat, S.A., Huang, N.F., Sofi, I.B., Sultan, M.: Agriculture-Food Supply Chain Management Based on Blockchain and IoT: A Narrative on Enterprise Blockchain Interoperability. Agriculture **12**(1), 40 (2022)

3. Correa-Calderon, A., Armstrong, D., Ray, D., DeNise, S., Enns, M., Howison, C.: Thermoregulatory responses of holstein and brown swiss heat-stressed dairy cows to two different cooling systems. International journal of biometeorology **48**(3), 142–148 (2004)

4. Council, N.R., et al.: A guide to environmental research on animals. National Academies (1971)

5. Cousin, P., Dupont, C., Fatnassi, S., Pham, C., Thiare, O., Wussah, A., Koffi, S.: IoT, an affordable technology to empower africans addressing needs in africa. In: 2017 IST-Africa Week Conference (IST-Africa). pp. 1–8. IEEE (2017)

6. Das, R., et al.: Impact of heat stress on health and performance of dairy animals: A review. Veterinary world **9**(3), 260 (2016)

7. Davcev, D., Mitreski, K., Trajkovic, S., Nikolovski, V., Koteli, N.: IoT agriculture system based on lorawan. In: 2018 14th IEEE International Workshop on Factory Communication Systems (WFCS). pp. 1–4. IEEE (2018)

8. De Donno, M., Tange, K., Dragoni, N.: Foundations and evolution of modern computing paradigms: Cloud, IoT, edge, and fog. IEEE Access **7**, 150936–150948 (2019). https://doi.org/10.1109/ACCESS.2019.2947652

9. Drakopoulos, G., Kafeza, E., Al Katheeri, H.: Proof systems in blockchains: A survey. In: SEEDA-CECNSM. IEEE (2019). https://doi.org/10.1109/SEEDA-CECNSM.2019.8908397
10. A. Karras et al.

10. Drakopoulos, G., Kafeza, E., Mylonas, P., Iliadis, L.: Transform-based graph topology similarity metrics. NCAA 33(23), 16363-16375 (2021). https://doi.org/10.1007/s00521-021-06235-9

11. Drakopoulos, G., Kafeza, E., Mylonas, P., Sioutas, S.: Process mining analytics for Industry 4.0 with graph signal processing. In: WEBIST. pp. 553-560. SCITEPRESS (2021). https://doi.org/10.5220/0010718300003058

12. Drakopoulos, G., Mylonas, P.: Evaluating graph resilience with tensor stack networks: A keras implementation. NCAA 32(9), 4161-4176 (2020). https://doi.org/10.1007/s00521-020-04790-1

13. Drakopoulos, G., Spyrou, E., Voutos, Y., Mylonas, P.: A semantically annotated JSON metadata structure for open linked cultural data in Neo4j. In: PCI. ACM (2019). https://doi.org/10.1145/3368640.3368659

14. Hossain, M.I., Markendahl, J.I.: Comparison of LPWAN Technologies: Cost Structure and Scalability. Wireless Personal Communications 121(1), 887-903 (2021)

15. Johnson, R.T., Gibbs Jr, C.J.: Creutzfeldt-jakob disease and related transmissible spongiform encephalopathies. New England Journal of Medicine 339(27), 1994-2004 (1998)

16. Karras, C., Karras, A.: DBSOP: An Efficient Heuristic for Speedy MCMC Sampling on Polytopes. arXiv preprint arXiv:2203.10916 (2022). https://doi.org/10.48550/arXiv.2203.10916

17. Karras, C., Karras, A., Sioutas, S.: Pattern Recognition and Event Detection on IoT Data-streams. arXiv preprint arXiv:2203.01114 (2022). https://doi.org/10.48550/arXiv.2203.01114

18. Li, Q., Liu, Z., Xiao, J.: A data collection collar for vital signs of cows on the grassland based on lora. In: 2018 IEEE 15th International Conference on e-Business Engineering (ICEBE). pp. 213-217. IEEE (2018)

19. Lin, J., et al.: Blockchain and IoT based food traceability for smart agriculture. In: Proceedings of the 3rd International Conference on Crowd Science and Engineering. pp. 1-6 (2018)

20. Liu, X., Huo, C.: Research on remote measurement and control system of piggery environment based on lora. In: CAC. pp. 7016-7019. IEEE (2017)

21. McKean, J.: The importance of traceability for public health and consumer protection. Revue Scientifique et Technique-Office International des Épizooties 20(2), 363-369 (2001)

22. Ntafis, V., Patrikakis, C., Xylouri, E., Frangiadaki, I.: RFID application in animal monitoring. The Internet of Things: From RFID to the Next-Generation Pervasive Networked Systems pp. 165-84 (2008)

23. Qin, J., et al.: Industrial Internet of Learning (IIoL): IIoT based pervasive knowledge network for LPWAN-concept, framework and case studies. CCF Transactions on Pervasive Computing and Interaction 3(1), 25-39 (2021)

24. Singh Bali, M., et al.: Towards energy efficient NB-IoT: A survey on evaluating its suitability for smart applications. Materials Today: Proceedings 49, 3227-3234 (2022). https://doi.org/10.1016/j.matpr.2020.11.1027

25. Tominski, C., Schumann, H., Andrienko, G., Andrienko, N.: Stacking-Based Visualization of Trajectory Attribute Data. IEEE TVG 18(12), 2565-2574 (2012). https://doi.org/10.1109/TVCG.2012.265

26. Trevarthen, A., Michael, K.: The RFID-enabled dairy farm: Towards total farm management. In: ICMB. pp. 241-250. IEEE (2008)

27. Voutos, Y., Drakopoulos, G., Mylonas, P.: Smart agriculture: An Open Field for Smart Contracts. In: SEEDA-CECNSM. IEEE (2019). https://doi.org/10.1109/SEEDA-CECNSM.2019.8908411