# A Microservice-Based Smart Agriculture System to Detect Animal Intrusion at the Edge
## 1 Introduction  
Smart agriculture harnesses cutting-edge information technology, integrating big data, mobile Internet, cloud computing, and the Internet of Things (IoT) technologies to enable the precise tracking, monitoring, automation, and analysis of agricultural operations. Currently, cloud-based infrastructures are prevalent in supporting various smart agriculture applications and data processing. In this setup, data from smart sensors in agricultural fields are transmitted to the cloud via the Internet, where they are stored and processed for decision-making purposes. However, the utilization of cloud-based infrastructures in smart agriculture comes with two significant limitations, as highlighted in recent research [1]: (i) The transmission of sensor data over the Internet requires continuous connectivity, consuming high bandwidth and resulting in delays, rendering it impractical for rural areas with unstable internet connectivity. (ii) Transmitting large volumes of data from IoT devices to the cloud for storage and processing quickly depletes the energy of battery-powered IoT devices. To overcome these limitations, we propose a LoRa (Long Range)-enabled, fog-based smart agriculture infrastructure. This approach intelligently distributes computational workloads to Raspberry Pi devices, thereby reducing the volume of data transferred to the server and facilitating the delivery of latency-sensitive services in real-time. Following a survey conducted with farmers to discern the primary challenges amenable to solutions through smart agriculture, animal intrusion emerged as the most pressing concern. Given that farms are typically situated in rural settings, adjacent to natural habitats, the incursion of animals poses a significant threat to farm owners, necessitating prompt action to address the resulting havoc and destruction. Unlike other smart agricultural services such as smart irrigation, crop quality monitoring, and pest control, detecting animal intrusion presents unique challenges due to its inherent uncertainty, lack of control, and unpredictability. Animals may disrupt crops and roam freely across fields at any given moment, leading to substantial losses in production. Consequently, recovering from such damage entails considerable time and financial resources to mitigate the associated costs effectively. In this paper, building upon our previous research [2], we introduce a cost-effective, energy-efficient integrated fog and LoRa-enabled microservice-based infrastructure designed specifically for smart agriculture. This infrastructure is complemented by an innovative strategy for detecting animal intrusion, which combines passive infrared (PIR) sensors with a rotating camera. Our primary aim is to expedite the detection and localization of animal intrusions for farmers. While a straightforward approach to field monitoring would involve relying solely on cameras without PIR sensors, this method entails the use of a greater number of high-resolution cameras to cover the same area, resulting in higher costs and increased energy consumption compared to PIR sensors. Additionally, employing only cameras necessitates fixing them in a single direction, potentially diminishing the effectiveness of animal identification when an animal approaches the boundary of the camera's field of view. By incorporating a rotating camera, we ensure that the animal is captured at the center of the image, significantly enhancing the success rate of animal identification. Furthermore, our work includes an in-depth analysis of power consumption and a comparison with the camera-only strategy, highlighting the efficiency and efficacy of our proposed approach. The paper is structured as follows: We commence by illustrating how LoRa's low-power, low-bandwidth, and long-range capabilities revolutionize rural agricultural lands into smart agriculture systems.