Blockchain-Based Cloud-Enabled Security Monitoring Using Internet of Things in Smart Agriculture

: The Internet of Things (IoT) has rapidly progressed in recent years and immensely inﬂu-enced many industries in how they operate. Consequently, IoT technology has improved productivity in many sectors, and smart farming has also hugely beneﬁted from the IoT. Smart farming enables precision agriculture, high crop yield, and the efﬁcient utilization of natural resources to sustain for a longer time. Smart farming includes sensing capabilities, communication technologies to transmit the collected data from the sensors, and data analytics to extract meaningful information from the collected data. These modules will enable farmers to make intelligent decisions and gain proﬁts. However, incorporating new technologies includes inheriting security and privacy consequences if they are not implemented in a secure manner, and smart farming is not an exception. Therefore, security monitoring is an essential component to be implemented for smart farming. In this paper, we propose a cloud-enabled smart-farm security monitoring framework to monitor device status and sensor anomalies effectively and mitigate security attacks using behavioral patterns. Additionally, a blockchain-based smart-contract application was implemented to securely store security-anomaly information and proactively mitigate similar attacks targeting other farms in the community. We implemented the security-monitoring-framework prototype for smart farms using Arduino Sensor Kit, ESP32, AWS cloud, and the smart contract on the Ethereum Rinkeby Test Network and evaluated network latency to monitor and respond to security events. The performance evaluation of the proposed framework showed that our solution could detect security anomalies within real-time processing time and update the other farm nodes to be aware of the situation.


Introduction
The surging human population in the world indicates the importance of agriculture and farming to grow and produce food for all the people around the world. Most countries' economies heavily rely on their performance in the agriculture sector [1]. A performance boost in the agriculture sector reinforces a country's economy. However, the profit margins on products and goods obtained by farmers are comparatively less than people working in various other sectors such as computers, construction, education, and more. Consequently, farmers are losing interest in continuing to work in agriculture, as more manpower is required to cultivate goods or food products in the agriculture sector compared to manual work required in many other sectors, and the farmer work incentives are much lower than desired. As a matter of fact, the financial risk associated with agriculture or farming is also higher due to the direct impact of sudden natural calamities on agriculture if farmers are not prepared for unexpected situations. The emergence of technologies such as the Internet of Things (IoT) changed the landscape of how farming is performed and enhanced operating capabilities in the agriculture sector [2]. The integration of IoT technology within agriculture and farming is termed smart agriculture and smart farming. The global agriculture robot market is predicted to reach USD 15.93 billion by 2028, with an annual compound growth rate of 20.31% during 2021-2028 [3]. The agriculture sector is becoming a soft target for adversaries to launch cyber attacks, as digital infrastructure integration within agriculture is growing and the agriculture economy market is thriving. For instance, a meat processing company, JBS, in food supply suffered a ransomware attack, which resulted in the halting of 13 meat plant operations. The company had to pay USD 11 million dollars ransom to bring back the operations [4]. Therefore, security is considered a massive problem in sectors such as agriculture, and advancement in agriculture security solutions is highly desired.
Smart agriculture and farming may produce high crop yields, and efficient usage of resources to improve productivity [5]. The recent trends in IoT show that smart agriculture is one of the potential applications for IoT for major process improvements [6,7]. Several IoT applications in smart agriculture include soil-state monitoring, pest-control monitoring, crop-growth monitoring, animal-herd monitoring, water-level control, environmentalcondition monitoring, and more. Sensor devices are installed on the farm near the premises and surrounding the agriculture area to sense the operating and environmental conditions and convert the sensed analog data into a digital form. Some of the most prominent sensors in smart agriculture include temperature, humidity, light, and pressure and proximity sensors. These sensing devices are connected to the internet through edge gateways or routers to constantly update the sensing information in the cloud. Although communication to the cloud provides data analytics and storage capabilities, a smart device's internet connectivity introduces security and privacy issues. These issues in smart agriculture are not well addressed in the literature [8,9].
The existing security solutions proposed in smart farming and agriculture mostly cover food-supply-chain management [9] and the monitoring of various activities [10] using cloud technologies, ML-and AI-based data-analytic techniques [11], and authentication and authorization solutions for constrained IoT devices [12,13]. Cloud-based monitoring smart agriculture solutions can still have security consequences, if the secured code procedures are not considered during the development and IoT security best practices are not followed. To support the previous statement, we have historically seen that IoT devices exposed to the Internet have been compromised and used as a weapon to perform large-scale denial-ofservice attacks or other malicious activities such as manipulating the sensor values to data exposure [14,15]. Therefore, the existing cloud-based solutions or gateway-based security solutions for monitoring smart agriculture applications are not sufficient for providing the full pledged security.
Decentralized applications and storage have security advantages compared to traditional applications and storage in terms of secured events storage, traceability, immutability, and improved security and privacy. Blockchain technology is known to be used for decentralized application development. Apart from blockchain-based digital currency, smart-contract-based applications are popular and used for many applications, including digital identities, financial security, secured storage, and supply chain management [16]. Researchers explored blockchain technology opportunities in resolving IoT security and privacy problems [17], including smart agriculture security. Some of the blockchain applications in smart agriculture are food-production supply-chain management, and secured transaction storage [8,18]. Blockchain enables keeping track of the sequence of events to maintain transparency and, in the end, farmers are fairly treated and gain profits. Considering the blockchain technology advantages in smart agriculture, we were inspired to utilize blockchain technology for implementing a smart farming-security-monitoring solution.
The current security monitoring solutions in smart agriculture either focus on cloudbased options or blockchain technology [10,19]. Furthermore, as discussed earlier, most of the cloud-or blockchain-based solutions mainly address supply-chain issues. The advantages of cloud and blockchain technology can be considered to propose optimal security solutions in smart agriculture. Overall, to overcome the limitations of the existing cloudbased solutions [10] and improve security using blockchain applications, we leveraged a cloud and blockchain solution to constantly process the sensing data in the cloud and store anomalies in blockchain transactions. Additionally, none of the existing solutions provided an end-to-end solution using cloud and blockchain implementation for smart agriculture and evaluating the network latency performance. Therefore, we implemented an end-to-end solution using an Arduino sensor kit with a Wi-Fi module, AWS cloud, and Ethereum smart-contract network for testing real-time application, and evaluated their performance in terms of security, usability, and performance. Ultimately, our contributions to this paper are as follows: • We implemented an end-to-end smart agriculture security-monitoring prototype using Arduino sensor kit, AWS cloud components, web graphical user interface, and Ethereum smart-contract network. • We monitored and processed various sensor-type data suitable to generate in a smartagriculture environment and store the essential monitoring digital data in Ethereum smart contract transactions. • We presented a cloud-and blockchain-based smart-agriculture architecture, which enables remote monitoring and automation to control the smart-agriculture environment. • We proposed a smart farmer-community-based monitoring solution to update security alerts to neighbor farmers and disseminate security awareness information across the farming community. • We evaluated the performance of the proposed architecture and implemented a cloudand blockchain-based solution and showed that our solution incurs negligible network latency to perform the operations in real time.
The remainder of the paper is organised as follows. Section 2 discusses the background and work related to the proposed work. Section 5 describes the proposed cloudand blockchain-based architecture for smart-agriculture security alert monitoring. Section 6 shows the implementation of the end-to-end smart agriculture architecture with a discussion of the different components used in the application. Section 8 includes the discussion and future work on the proposed smart-agriculture solution. Section 9 concludes the paper.

Background
In this section, an overview of the IoT applications in agriculture, existing cloud-based security solutions in smart agriculture, and the existing blockchain-based security solutions in smart agriculture are discussed.

IoT Smart-Agriculture Background
IoT technology offers many benefits in agriculture, including improving productivity and high yields [20]. There are number of prior works discussing the role of IoT in agriculture, IoT applications in agriculture and the advantages of IoT in the agriculture field [5,9,10,[20][21][22][23]. Olakunle et al. [24] presented a review of IoT integration with smart agriculture and data-analytics benefits and challenges. The future trends and opportunities are categorized based on technologies, applications, business, and marketing. Farooq et al. [23] performed a detailed study of the technologies involved when using IoT in smart agriculture. The technologies covering the network protocols, architecture, cloud computing, and big-data analytics were leveraged to discuss the existing works in IoTbased smart agriculture. Additionally, the security issues, the policies proposed by different countries to support smart agriculture, and the existing smart-device-based applications are presented in the article. Othmane et al. [9] presented a review of the various advanced technologies used in IoT-based smart agriculture solutions. Additionally, various smart-agriculture applications using IoT are categorized in the article. Furthermore, the existing blockchain solutions for supply-chain management in agriculture are discussed. The articles [25,26] discussed the usage of wireless sensor networks to regulate water and monitor water level in agriculture. The authors emphasized that IoT plays a major role in water management. However, those articles focused on specific water-management applications in agriculture.
The authors of [10] performed a survey of different applications used in smart agriculture with technologies, and cloud computing is used as a backend technology stack for application implementation. Amera et al. [5] also performed a survey on using IoT in smart agriculture. The taxonomy is defined using a smart-agriculture architecture and technologies and classified the literature works based on the taxonomy categories. The authors of [20] also reviewed smart agriculture based on IoT architecture, application, software, hardware, principal advantages, and open research and challenges in the future. Brewster et al. [7] highlighted the data governance, security, and privacy requirements and concluded that a cultural shift is needed to adopt the IoT solutions in agriculture. Overall, based on the state-of-the-art IoT-based smart-agriculture survey, we can conclude that IoT can have many applications in agriculture. IoT technology has already been integrated with smart-agriculture applications. However, there are still many challenges and research issues regarding security and privacy, network issues, regulations, scalability, reliability, and resource optimization.

Cloud Solutions in Smart Agriculture
Cloud-computing integration with smart agriculture is needed to perform the IoT sensing data storage and analytics, including big-data applications. Researchers proposed solutions to address the issues in IoT-based smart agriculture using cloud computing. Nurzaman et al. [2] proposed a fog-computing-based network architecture for smart farming and agriculture to monitor farms and control agriculture operations. The authors introduced a cross-layer-based channel access and routing solution to optimize the network communication connected to smart-farming endpoints. This improved the network latency of the IoT farming devices connected to the cloud. However, the paper did not discuss the security and privacy aspects of IoT-based smart agriculture. Chen et al. [27] presented an IoT platform to cultivate turmeric outdoors for precision agriculture. The author's application enables the farmers to control the turmeric farm with GUI, improving the quality and productivity of the turmeric while maintaining the network latency that approximately matches real-time communication. However, this work is specific to smart-agriculture turmeric-cultivation application implementation. Ref. [28] proposed an intelligent security system to monitor devices in the agriculture field. The authors implemented the system on Rasberry pi 2. The system can communicate data remotely and send SMS alerts to a remote user. However, the work did not consider blockchain technology to create smart contracts and securely store the data when monitoring the devices in agriculture. Li et al. [11] discussed the limitations of using big-data solutions in IoT-based smart agriculture. The authors use the K-means algorithm to perform the agriculture data analytics and highlighted that data is insufficient to apply big-data solutions. Anandarup et al. [29] proposed a method for detecting link failures between local nodes and master nodes and identifying local nodes from the network packets. The MLP hosted in remote nodes is used to test the identification of the nodes. Overall, the literature indicates that cloud solutions benefit the agriculture industry by remotely monitoring and improving productivity in agriculture. However, the cloud-based solutions are prone to data exposures and may lead to security breaches on the cloud service provider if security controls are not properly implemented.

Blockchain Solutions in IoT Agriculture
Blockchain technology has advantages such as secure storage, anonymity, and transparency. The user identity and private key will not be disclosed in public, although the user's public key and transaction information can be seen in the public blockchain. Some researchers explored the usage of blockchain technology in IoT applications [19,[30][31][32]. Ferrang et al. [33] described blockchain protocols in IoT and presented threat models to blockchain protocols in IoT. The IoT application domains for blockchain are discussed, and the state of the art of blockchain technologies in the Internet of things are discussed, emphasizing security and privacy. The research challenges and future directions for utilizing blockchain in IoT are discussed. Ref. [8] studied the security and privacy issues in green IoT-based agriculture.The application of blockchain technology in preserving privacy in green IoT-based agriculture is discussed. Anusha et al. [31] performed a literature review of the information-security research progress in blockchain-based smart-agriculture applications. Oscar et al. [32] performed a detailed study of using blockchain in smart agriculture. The authors highlighted that security and privacy issues are one of the main concerns of smart agriculture. The state-of-the-art review on using the blockchain in agriculture [32] described that most of the works focused on solving the food or agriculture supply-chain problem, and secure data storage, remote monitoring, and automation are the least focused on areas in blockchain-enabled smart agriculture. To sum up, the prior blockchain technology in IoT agriculture review articles indicate that blockchain solutions can improve the security and privacy of smart agriculture. However, challenges such as data storage capacity in blockchain and high network connection rates in rural areas to perform consensus activity still need to be addressed in the agriculture application context.
Saikat [12] proposed a blockchain-based IoT architecture for the food supply chain. RFID sensors captured the identification ID from the product package from different stakeholders in the food supply chain and were added to the blockchain to maintain integrity. Any stakeholder can verify the public blockchain data regarding the products' status. Mubariz et al. [34] introduced blockchain-based cloud nodes to verify the service provided by the edge servers for service authentication to IoT devices. The proof-ofauthority (POA) mechanism is considered for maintaining the consensus among blockchain cloud nodes. IoT devices give the rating to the edge servers based on the edge-server service provided and used for determining the service authentication. Mohamed et al. [19] explored blockchain technology to implement security solutions and their performance. The authors highlighted that large throughput and storage capacity are the technical challenges in implementing security solutions. Overall, blockchain solutions have been used in the literature to address some issues in smart agriculture.

Related Work
In this section, the relevant state of the art is discussed and it is highlighted how our contributions are important in comparison with the existing works.
The authors of [35] implemented a smart contract based on soil-and climate-condition monitoring metrics in smart agriculture. However, a detailed smart-contract implementation are not provided. Moreover, the real-time experiments sensing the agricultural conditions and testing the proposed smart-contract-based metric monitoring are not performed. Ref. [36] discussed Ethereum blockchain-based smart-agriculture supply-chain data solutions. The authors monitored the agriculture sensor data using Ethereum. However, the solution did not mention data storage usage in the cloud. Ref. [37] performed a proof of concept for implementing the Ethereum blockchain solution to store agriculture sensor details. However, the performance of the implemented solution is not determined in their work. Realistic test experiments by setting the sensor devices are also not performed. Caro et al. [38] proposed AgriBlockIoT, a blockchain-based solution for agriculture food supply-chain management. The Ethereum and hyper ledger blockchain-based implementation is performed to store the Agriculture IoT device's data. The authors showed that the Hyperledger latency is much lower than the Ethereum network latency. However, the end-to-end implementation of the Agriculture blockchain, including enabling the sensors to send data in real time, is missing. Additionally, the message network latency to update the transactions in the blockchain is higher. We address those issues and implemented a more realistic blockchain-based solution to send the sensor alert data as a transaction in blockchain.
The authors of [39] designed a smart-contract-based IoT device-to-device and deviceto-gateway authentication mechanism in smart agriculture. The block is formed by the edge server deployed in the IoT environment. The blockchain nodes in the cloud perform the consensus mechanism and add the blocks to the blockchain. A hybrid blockchain hyperledgersawtooth platform simulates the author's proposed method. Although blockchain and cloud technologies are involved in the author's work, the main focus of their work is on the design of IoT device authentication mechanisms. On the other hand, we focused on monitoring smart agriculture environmental conditions using cloud and blockchain technologies. We implemented an end-to-end production level Ethereum smart-contract solution. Table 1 compares our work with the prior works using cloud or blockchain technology in smart agriculture. Table 1 shows that prior works either focused on proposing cloud-based smart-agriculture methods or blockchain-based smart-agriculture methods. Cloud-based solutions are required to store sensitive information such as farmer data and environmental-conditions data in the cloud. Securing cloud storage is challenging, as the data is stored in databases or object-based storage solutions. Blockchain-based solutions require decentralized storage, and an agriculture data processing module is necessary to perform the operations on data. A decentralized solution alone is not sufficient to realize the full capabilities of IoT security monitoring using data anomalies. Additionally, none of those prior works implemented end-to-end smart-agriculture monitoring solutions to perform the experiments and evaluate performance and application capabilities. Our work is inspired by the lack of cloud-and blockchain-based solutions for monitoring the smart agriculture environment, whose implementation is realistic while ensuring security when data is processed and stored in the implementation prototype.

Smart Agriculture, Sensing Technology and Security Attacks
A typical cloud-enabled IoT smart agriculture is shown in Figure 1. The cloud-based architecture is comprised of the IoT device connected to the farms and agricultural land to monitor various physical conditions such as fertilizer usage, proper seed spilling, weather state, food growing quality, and storage environment conditions. Various sensors such as temperature, humidity, and pressure are used to monitor the farming condition. The IoT devices are connected to the common gateway to pass the state information to the third-party cloud vendor, who provides the product services. The gateway can be a generic or dedicated router designed for the smart farm. The cloud provider can be any primary service provider such as AWS, Google Cloud, Microsoft Azure, or a self-managed cloud. The gateway is connected to the cloud resources to process the IoT device requests.  Table 2 describes the various IoT sensors and their applications in smart agriculture. Temperature sensor: The sensor detects temperature changes within the application. The water temperature, the surrounding-air temperature, and plant temperaturemonitoring capabilities improve the effectiveness of agriculture duties.
Humidity sensor: The humidity sensor measures the humidity changes in the agricultural land environment. The humidity sensor helps measure the soil moisture and water consumption rate, tracking waterfall trends for future irrigation-requirements estimation. The normal humidity ranges are 0%RH-100%RH.
Light sensor: The light sensors in agriculture monitor the light in the agricultural greenhouse, cloud shadow, and the required light to grow the plants.
Accelerometer sensor: Accelerometer sensors in agriculture help to maintain the agriculture or farming equipment. The movement and vibration changes in the equipment are monitored to detect the equipment replacement needs.
pH sensor: The pH sensors in agriculture improve the productivity of crops. The pH sensor detects the unwanted chemicals in the soil and soil nutrient deficiencies. Soil-pH fluctuation monitoring can help the farmers to take precautions and effectively grow plants.
GPS sensors: An animal herd or any objects in the agricultural location can be monitored using a GPS sensor. The remote monitoring and location tracking help to achieve precise agriculture.
Pressure sensor: A pressure sensor in agriculture may be used to monitor pipes and tanks. The pressure sensor improves water management, irrigation management, and precision farming.
Infrared sensor: Infrared sensor integrated with drones monitors the crop and measures the plant's strength. The plants can be adjusted and optimized for the agriculture resources to manage agriculture activities effectively. The IoT attack surface in smart agriculture opens up a new range of cyber attacks, and few security protection capabilities can be embedded into IoT devices due to processing and memory limitations. Therefore, we may need to rely on gateway-or network-level security detection and protection mechanisms. In this work, we try to address the following attacks using IoT status and anomaly data monitoring solutions.
Denial of service (DoS): An adversary may send malicious network traffic to the victim farmer network to shut down the services, including the sensor devices and routers connected to the network. This may interrupt the operations if we consider that these devices are used for food supply-chain applications. The attack might also originate from diverse source IP addresses, making it difficult to detect and block the attack traffic. DoS attack scenarios in IoT include consuming the IoT device resources, IoT device and gateway communication bottlenecks, or flooded the gateway with malicious attack traffic.
Physical security attacks: Intruders trespass on the agriculture fields and farm premises to destroy the property or with other bad intents such as theft, arson, etc. The camera sensors installed on the farm premises send the data to monitor and alert the farm owners when physical attacks happen in smart agriculture. An adversary may also visit the farm site to install or compromise the farm network.
Sensing-data-manipulation attack: The IoT sensor-data manipulation with malintent prior to going to the destination is another kind of attack seen in IoT. The adversary may perform a man-in-the-middle attack to read the data passing through the communication channel and embed malicious data to perform the attacks. A zero-day vulnerability in the IoT devices can also be exploited to compromise the sensor device and fake the sensor data to hide the malicious activity. There are various ways to get into the network and manipulate the data unless we have good security controls covering the data-link-layer to application-layer protocols.

Proposed Approach
The proposed approach improves smart agriculture/farming monitoring and security by incorporating technologies in multi layers of the smart-agriculture architecture. Internet of Things (IoT) technology was added near farming premises to connect with the internet and add intelligence. Cloud technology is used in the data processing layer to support the solution's scalability and achieve production-level performance. The Ethereum blockchain is used in another layer to run the smart contract and trigger events when anomalies are identified during the smart-agriculture security monitoring. Figure 2 illustrates the layer-wise architecture of the proposed approach. The smartfarm layer contains various sensor devices in the farming premises for different purposes. A smart-agriculture community is formed with IoT sensor devices installed on every piece of farmland. These sensor devices constantly generate events such as device health, device data, etc. The generated events are transmitted to the cloud using an edge gateway or routing device connected to the sensor device. The cloud layer consists of components constantly listening to the sensor events and processing the event data to retrieve the intended information. MQTT is the typical protocol for passing the data in packets from one end to the other. We defined a lambda function in the AWS cloud to parse the data from the AWS IoT core component and extract the required data from the sensor devices connected to the farms. Whenever the lambda function logic determines the security alert observed from the sensor generating data, the lambda function performs POST request infura API to update the Ethereum blockchain. The updated transaction may include the sensor data anomaly values, status of the device, etc.The blockchain contains Ethereum nodes distributed across the network operated by an individual to perform the mining, or someone uses the Ethereum full node for their transaction processing. The infura runs Ethereum nodes and provides APIs to update the transactions from the user's accounts if they have an account with them. The updated blockchain transactions will be updated to all the nodes in the Ethereum network. Although the user layer is not shown in Figure 2, the GUI interface can read the Ethereum node transactions using API calls and display the details in the GUI when the user wants to see the smart-agriculture alerts.
The description of the main components used in the proposed approach is discussed in the following paragraph.
AWS IoT core: A number of IoT sensing devices exist in the smart-farming environment. An IoT message-processing infrastructure is needed to support the IoT message protocols such as MQTT and accommodates the network bandwidth to collect messages from numerous IoT devices. We selected AWS IoT core service to perform the smartagriculture IoT data processing. The AWS IoT core offers low latency and high throughput performance, and these characteristics support the build of real-time production-level IoT monitoring systems.
AWS Lambda: The collected IoT data should be processed and given as input data to the Ethereum blockchain. Therefore, the AWS Lambda runs the code in the backend and stores the smart-farming information in the Blockchain. AWS Lambda is a serverless computing service to run code virtually without provisioning the server infrastructure.
Infura API: We did not rely on deploying the Ethereum full node to create and run the farming smart contracts. Infura is an Ethereum API service to run smart contracts in Ethereum nodes and perform Ethereum-based transactions. We leverage the Infura API calls to interact with Ethereum nodes once we collect and process the farming sensor data.
Ethereum: We implement the Ethereum-based smart contract to store the farming sensor data and check the farming environment conditions. The Ethereum first version works on the proof-of-stake (POS) consensus mechanism to approve and add the transactions to the Ethereum blockchain. A Web3 frontend application is implemented to review and alert the farmers when security events are detected. Advantages of our proposed approach: Our solution inherits the advantage of secured data storage using blockchain. It includes only the authorized farming owners who can see the smart-farming records. The cloud-based data storage poses the security risks of data breaches due to misconfigured access controls. The blockchain allows secured storage of records and no storage maintenance cost. Our solution is scalable in the cloud and offer solutions to various security use cases in smart agriculture The immutability of the blockchain transaction alert data can be used as evidence for legal proceedings, insurance claims for protecting the farmer's agriculture assets and property, and backing up the security investigation data without data corruption. For instance, natural disasters may have a severe impact on agriculture fields. Evidence of when, what, where, and how can be captured as blockchain transaction data and used for insurance claims. The farms cannot deny the ownership of the transaction once the transaction is added to the blockchain. This property may be used to identify malintent farmer activity and maintain transparency. Some of the smart-agriculture use cases of the proposed approach are discussed below.
Sensor health status: The sensors should constantly monitor the physical conditions in the agricultural land and farms and send this data to the farmers or crop owners to effectively manage the farms for high yield, low loss, and better productivity. The sensors/actuators must work continuously to obtain updates regularly. Sensors are targeted with passive and active attacks. Therefore, the health status monitoring of these device sensors is essential and continuously monitored. The farmer should be notified within a mobile application whenever the device's health status is off. Then, the farmer may find the root cause and fix the issue.
Sensor data anomalies: Sensor data irregularities can be flagged for attention and to look for anomalies. A threshold can be set up to trigger the alert and monitor the smart-agriculture applications. For instance, the temperature of the farming storage unit is constantly monitored to store commodities safely. A temperature sensor is installed on the storage unit and monitors the storage-unit temperature. Whenever the temperature exceeds the threshold temperature, our blockchain-based monitoring solution sends an alert to the storage unit owner. Similarly, the image sensor installed near the storage unit is used to identify moving objects. An image-processing technique was applied to detect unauthorized access to the storage unit facility. The cloud resources incorporated in our solution can process the images and produce the output.
Community farming blockchain: The crop productivity or quality impact on any single farm may gradually affect other farms in the community or nearby farms in the surrounding area. The effect can be due to the infection of bugs, severe weather disturbing the crop's life cycle or more. Communication of this information to the community farmers may save their crops from infection and stop the infection from spreading. Therefore, the blockchain-based community can use this as a farm blockchain for sharing the latest updates among the farmers and keep connected to be aware of what is happening on the surrounding people's farms for awareness. For instance, a burglar with unauthorized farmland storage access can be reported to the farmers around the premises using the proposed blockchain-based application. The number of applications are numerous using the smart-farm community blockchain.

Implementation
In order to evaluate the proposed smart-agriculture security monitoring approach using blockchain and cloud technologies, we implemented a prototype using the Arduino Sensor kit with Wi-Fi capabilities to mimic the various sensors deployed in the farmland, AWS cloud components to process the sensor data, Ethereum blockchain to store the monitoring alerts and other essential information using smart contracts, and developed a web frontend to display the alerts to the users.
Experimental setup: The following software or hardware components such as Arduino sensor kit, EP8266 Wi-Fi module, AWS IoT core component, AWS lambda function, infura Ethereum API Account, and Web Javascript were used to perform the experiments. The Arduino module with Wi-Fi was connected to the home Wi-Fi router for communicating to the cloud. Our security monitoring application can be developed as a product or third-party security monitoring tools for smart-agriculture IoT device's security.
Arduino sensor kit contains Potentiometer, light sensor, sound sensor, air pressure sensor, temperature sensor, and accelerometer sensor to monitor and capture various environmental, physical, and other conditions. The breadboard is used to connect these sensor devices to the communication equipment, i.e., Wi-Fi module. The Wi-Fi module also acts as edge gateway for all the sensor devices mentioned in our experimental setup. The Arduino C language code was written to connect the Wi-Fi module with the home router, and external communication to the remote AWS IoT nodes for event updates. The SSID and password key details of the Wi-Fi home router are provided in the Arduino to connect to the internet. The AWS IoT core service is created in AWS Cloud with few generic configuration settings. The AWS IoT core runs on the Free RTOS operating systems for IoT-device data processing and exchanging the data using the MQTT protocol. The AWS IOT core could display the sensor device data and can be stored in cloud storage such as S3. The AWS Lambda function was written in JavaScript programming language to constantly poll the sensor-events' data from AWS core. The monitoring logic is implemented in the AWS lambda function to identify the sensor status and sensor data anomalies. The infura API calls were also performed using the AWS lambda function to update the sensor monitoring data for permanent storage in the blockchain. The infura account is needed to generate the API key and establish a connection to the Ethereum network. Therefore, the alert data is updated to the blockchain and stored in the transaction. To implement the end-to-end application, the infura API calls are used to retrieve the alert transaction from the Ethereum blockchain. The farmer may download the mobile application or web app to monitor the farm alerts remotely. Figure 3 displays the Arduino microcontroller used to control and connect to the IoT sensing devices. The temperature sensor and humidity and light sensor are connected to the microcontroller, and the microcontroller supports a Wi-Fi connection to communicate with cloud services. The sensors can be considered as agriculture application end devices. As shown in Figure 3, the temperature and light sensor positive terminals such as A3, and D3 are connected to the microcontroller PINS. The negative terminals are grounded to prevent short-circuiting issues. The microcontroller is power supplied with 5V, which is shown in Figure 3 with a red wire connection. As shown in Figure 4, the sensing device's status will be monitored using the desktop application. The Arduino controller is connected to the laptop via wired communication. The sensor measures real-time activity such as temperature and light in the farming. We installed the Arduino software application on the laptop machine to run the C code on the Arduino kit. The code comprises the WIFI connection credentials; AWS IoT Core connection requirements such as Client ID, AWS Host URL; and the MQTT topic name and the programming logic to read the sensor data as an MQTT topic and publish the MQTT topic in the AWS IoT cloud using the network connection. The code is dumped on the Arduino micro-controller to run the application and post the data in AWS IoT Cloud. Figure 4 displays the print statements indicating the Arduino kit connected to the author's home WIFI network "maverickcreek-7-709" and initiating a connection to the AWS Cloud. Once it is connected to the AWS, the sensor data is published as an MQTT topic with values temperature: 26, light: 26, and humidity: 51.The data publish-success message can also be seen in the Figure 4. The MQTT publish messages and can also log in to the AWS IoT Core. Figure 5 displays the published IoT sensor data in the AWS Cloud. As seen in Figures 4 and 5, the data publication time in the IoT core cloud is 2 s. The highlighted red boxes in Figure 5 indicate the timestamp and sensing temperature, humidity, and light values in the Arduino kit environment. The AWS lambda function written in JavaScript reads the AWS IoT Core published data and compares the sensor threshold values for anomaly detection. The code may trigger a sensor device health alert if the data is not received for a specific time interval. To interact with the Ethereum blockchain, the Infura API credentials are stored as variables, and the AWS lambda function reads the credentials to connect with Infura maintained Ethereum main node. The metamask application is used for the software wallet and to interact with the Ethereum blockchain. The wallet details are also provided in the AWS lambda function to perform the transactions in Ethereum. The smart-contract code is written using solidity programming language and sends the alert triggered data as a transaction in the Ethereum blockchain. Figure 6 shows the Ethereum transaction details when the temperature-threshold-exceeded alert is seen in the AWS IoT core. The transactions include the block number, from and to address, transaction fee, gas price, and timestamp. Based on the timestamps observed in the end-to-end blockchain-and cloud-based implementation, we determined that the time to update the farmer when the agriculture environment anomaly alerts trigger is 9 s. The Ethereum transaction completion time is 7 s. However, we used the Rinkeby testing network to test the Ethereum network, and the overall alert notification network latency will not be the same in the Ethereum production network. Overall, we prove that network latency is minimal when performing agriculture security monitoring using blockchain and cloud services and alerting the farmers.  Figure 7 indicates the data field format in the Ethereum transaction. The sensor threshold value, current value, and alert message are stored in the data transaction. This data will not be tampered with and will be stored securely in the blockchain. The boxes highlighted in red clearly show that the temperature value of 25 does not exceed the threshold value of 26. The experimental transaction performed on the rinkeby network can be seen publicly for reader understanding. Figure 8 displays the list of transactions stored in the Ethereum test network. The from and to address, transaction hash value, and the block ID can be seen for each transaction. The details of the transaction can be explored by browsing the URL "https://rinkeby.etherscan.io/address/0x001aed30b8dabb3e7ccc7a4cb06ad34115 1ea390 (accessed on 19 August 2022)". We developed the web frontend application to receive the agriculture security alerts such as anomaly and device-status alerts. The frontend application displays the alert notifications in the form of Ethereum transactions. Figure 9 displays the alert notifications with details about the sensor data and policy violations. For example, block number 9363208 in Figure 9 notifies the farmer regarding the temperature variations in the monitoring environment. When the temperature exceeded the threshold value, the policy violation message was displayed on the frontend test web application. We used vercel web platform to develop our test web application. The web URL "https://smart-agriculture.vercel.app (accessed on 19 August 2022)" shows the live experimental data obtained from our smart agriculture end-to-end application.
A user might also want to update the transactions using the frontend application. For instance, the user needs to store the sensing-device anomaly data for future reference purposes. We integrated this functionality into the frontend web app to update the violated sensing data conditions into the blockchain. Figure 10 shows the frontend web application with interactive options to update the transactions in the Ethereum test network. This feature helps the farmer or the web-application operating user to control the blockchain platform used for agriculture security monitoring.
To add a new transaction using the web frontend, the user should be connected to their wallet and fill in the transaction details. The temperature, humidity, and light sensor values and their optimum values are entered and those values submitted using a web application. The infura API is connected with the blockchain node and adds a new transaction when the setup sensor data policies are violated. The other users can see the transaction data once the transaction is updated into the blockchain.  Our blockchain solution can be used on the farming community blockchain platform. As shown in Figure 10, a farmer can update the real-time agriculture environment condition to fellow farmers so that fellow farmers do not have to visit the farming location and can effectively make decisions from home to perform daily agriculture and farming operations. Although we only used three sensors to test our prototype, our solution can be easily tweaked to support processing multi-sensor data and our implementation used for various IoT applications.

Performance Evaluation
Monitoring system performance: The end-to-end system performance needs to be evaluated to estimate the solution's effectiveness. The network latency and throughput are the indicators seen in the literature as performance factors for blockchain-based applications. The time taken to receive the sensor alert when an anomaly occurs in the sensor environment directly indicates the network latency. Our test results on Rinkeby show that the network latency is a few seconds. The network throughput was not tested using our implementation due to the infura API free-access limitation.
Performance comparison with existing works: Our solution performance is compared with the existing works using blockchain in smart contracts. Although none of the existing works implemented the end-to-end solutions with AWS cloud and smart contracts, we included the closely related smart-contract implementation for smart agriculture. Table 3 depicts the message network latency comparison of our work with existing works. The authors [38] implemented Ethereum-based smart contracts to update the IoT sensing data to the blockchain and evaluated the network latency of issuing a transaction in the blockchain. The authors reported a total network latency of 16.55 s. This work is closely related to our work in terms of adding the IoT sensor data into the blockchain. Our solution performed much better than the work [38] because we used real-time implementation applications, including IoT core and smart contracts using Infura API. The additional latency in [38] can also be caused by the blockchain node running in the virtual machine. The work [27] performed simulations to test the IoT devices sending updates to the blockchain and estimated the network latency. They considered 4G as a communication medium to model the communication link and obtained less than 0.2 s latency. We utilized the home WiFi to perform the experiments and obtained the matchable performance with [27]. The authors [34] also used Ethereum to build the agriculture smart contract. The authors reported that it took 272 s to complete one transaction. The high network latency may be caused by the usage of the real Ethereum network. Our solution reported a total network latency of 0.11 s, which is real-time alert reporting. We also determined the mean time to detect (MTTD) when the 95% confidence interval is used. The MTTD is reported as 0.115 with a margin of error of 0.00919 and a standard deviation of 0.016.

Discussion, Limitations and Future Work
We implemented a real-time scenario agriculture security-monitoring system, which monitors the sensor device's health status and sensor anomalies to perform precision agriculture and productive farming. However, we did not deploy the sensors in the agriculture field to capture the farmland environment conditions. We envision that the network latency will be negligible, considering the wide spread of the internet in rural areas. Our solution can even monitor the agricultural conditions in rural areas as long as an internet connection is available.
We did not implement the IoT gateway in our work. We used the home router as an IoT gateway and connected the IoT sensor devices to the network via home WiFi. This is one of the limitations of our work. Implementing an IoT network with an IoT gateway and various sensing devices to mimic the realistic smart-agriculture environment is one of the extensions of our work.
The current implementation only works on the Ethereum proof-of-work (POW) consensus mechanism blockchain. One future work will be implementing the current solution in the Ethereum 2.0 network, which is supported by the proof-of-stake (POS) consensus.
There are numerous IoT applications to monitor the IoT environment, including agriculture applications, smart homes, smart health, smart transportation applications, etc. Therefore, we envision our prototype will also be used to implement the monitoring solutions in other fields.
The network traffic can be collected from a smart-agriculture edge gateway and store the network events data in the cloud. The network events can be used to apply machine-learning and deep-learning techniques and identify the anomaly network traffic in a smart-agriculture network. One future work will be implementing ML-and DL-based network-security monitoring solutions in smart agriculture and using blockchain to store the network anomaly events as transactions.
The production Ethereum blockchain gas price is high. Therefore, blockchain technologies such as Cardano and Solano-based blockchain implementation are considered to design low network-latency applications and reduce the end user/farmer transaction cost in smart agriculture.

Conclusions
In this article, we proposed a cloud-and blockchain-based security monitoring solution for smart-agriculture IoT applications. The end-to-end application prototype was implemented using an Arduino sensor kit, AWS cloud components, web application GUI, and the Ethereum blockchain smart contract to alert the farmers of security anomalies and sensor-device status. The prototype was able to alert the farmers in real-time, allow remote monitoring of the farm and agriculture environment, and enable the farming community to communicate via blockchain. The performance evaluation in terms of network latency is shown to be nominal with our prototype and it could be stated that the delay can even be reduced with the implementation of high-performance transaction blockchain technologies such as Cardano. We discussed the limitations and future opportunities to improve the security of smart agriculture.