###### Abstract
The Federal Bureau of Investigation (FBI) is alerting the agricultural sector that attackers may target farms more frequently during crucial planting and harvesting seasons and interrupt business activities, which would have a detrimental effect on the food supply chain. In a recently released alert, the FBI warned that ransomware attacks ([[https://www.beefmagazine.com/news/fbi-warns-cyberattacks-during-critical-ag-seasons](https://www.beefmagazine.com/news/fbi-warns-cyberattacks-during-critical-ag-seasons)]([https://www.beefmagazine.com/news/fbi-warns-cyberattacks-during-critical-ag-seasons](https://www.beefmagazine.com/news/fbi-warns-cyberattacks-during-critical-ag-seasons)), accessed on 14 December 2022) on six agricultural organizations during the autumn 2021 harvest and well as two strikes in early 2022 might affect the planting season due to the sabotage of seeds and fertilizer delivery. One of the largest meat processing companies, JBS, spent about USD 11 million in ransom to end a cyberattack last year ([[https://www.bbc.com/news/science-environment-61336659](https://www.bbc.com/news/science-environment-61336659)]([https://www.bbc.com/news/science-environment-61336659](https://www.bbc.com/news/science-environment-61336659)), accessed on 14 December 2022). A leading US agricultural company, AGCO, was the target of a ransomware attack in  
Figure 1: UAV-assisted precision agriculture scenario. May 2022 that majorly impacted their output. A consortium of authorized governmental cyber security experts from the United Kingdom, United States, and Australia issued a warning in April alerting that supply chains, a crucial component of the Western national infrastructure, might be targeted by state-sponsored Russian attackers. The cybersecurity of technology that enables precision agriculture is a significant obstacle to its widespread adoption. To address this challenge, it is essential to develop a comprehensive framework that enhances the security of precision agriculture [15]. This research focuses on a subset of attacks that target the disruption of UAV data communication through techniques such as distributed denial-of-service (DDoS), unauthorized access, brute force, and infiltration. Compromised UAVs can significantly reduce the efficiency of the data collection system by reporting false data and consuming excessive energy for flight and hovering activities. They also compete for charge times on shared charging stations, thereby negatively impacting uncompromised UAVs. This work proposes a smart farming framework that allows securing the use of UAVs for data collection through deployed sensors. Comprehensive models for sensors and UAV energy consumption and threat vectors have been developed. Furthermore, algorithms have been developed for farm data transmission and collection utilizing a fog computing architecture. A fog broker, a key central element that manages interactions between the UAVs and sensors, is utilized for deploying an intrusion detection system (IDS). The IDS that utilizes machine learning classification is developed to detect and flag compromised UAVs based on their behaviors. Flagged UAVs are then penalized through a coin-based system where the greater number of coins collected allows for a greater amount of charge. UAVs lose coins and ultimately charge proportionally to the degree of malicious behavior to minimize the level of disruption to the overall system. The main contributions of the proposed work are listed as follows:  
1. A novel toolkit was developed that supports UAV-based data collection mechanisms in smart farming. The data were collected from sensors deployed in the fields. A fog broker was used to manage all of the responsibilities and interactions of the UAVs, sensors, data transmission, and data collection. 2. A machine learning model was trained at the edge station based on the UAV-to-UAV communication logged and shared after every round. The trained model was then deployed to the UAVs and the model outcomes were shared with the fog node for identifying malicious behavior. 3.