# APTM: A Model for Pervasive Traceability of Agrochemicals
## 5 Implementation and Evaluation
### Deployment Aspects  
In tier 1, a cabinet for the positioning of sensors and microcontrollers was created. Arduino was used as a microcontroller. Communication with tier 2 was performed using Ethernet shields. The collected data is sent via a computer network. The code that handles data received via sensors was written in C++ to run on Arduinos. An Arduino was used for each sensor. The arrangement of these sensors can be seen in Figure 13, showing a container or cabinet, sensors, microcontrollers, and agrochemical packaging. In this figure, the left side (A) is the internal part exposed, receiving various sensors, such as vibration, ultrasonic, camera, light, a package for testing purposes with an RFID tag in its base, and installed inside this cabinet the weighing scale module. The center (B) shows a perspective view from the right top. The right side (C) is the back of the cabinet where one can see the Arduino, a protoboard, network, and some wiring cables (USB/serial, network, and power supply).  
All programs that run on these tiers were developed in Python. In tier 2, a SQL database (MariaDB) receives data from the first tier in a temporary table of collected data. The table stores data accordingly to pre-established patterns, i.e., depending on classification, grouping, and prediction operation. Data that will be sent to the blockchain comes from this table. In this tier, there are scripts made in Python that perform several functions, such as: logging in of new products, opening a cabinet door, sending alerts, handling products, leaving empty packaging, sending data to the blockchain. In addition, there are three machine learning operations based on the _sckit-learn_ library. If certain conditions are detected during processing, alerts are sent to the farmer by the _smtplib_. Each of these functions runs as services in tier 2, triggered by the main control. This module (sendTo-Blockchain) activates the other functionalities of this tier. Sending data about product movement with Python is done with _web3.py_ to interact with tier 3 Ethereum blockchains.  
Tier 3 has two Ethereum nodes, one for each blockchain consortium (public and private). Each node is a link between public (regulatory bodies) and private (supply chain) networks. Every movement in tier 2 will have its representation in the form of a transaction recorded in blockchains; however, these blocks are also stored locally. A developed smart contract keeps agrochemical data and records its movement. Smart contracts are written in Solidity and adopt the ERC721 standard to represent an agrochemical package as a non-fungible token (NFT). The minimum amount of data recorded in the blockchain is the invoice number and the product code (or barcode). A web server (Apache) is also installed in this tier to receive requests from the visualization tier. Tier 4 is formed by decentralized applications (dApps) developed in HTML, JavaScript and _web3.js_ (for access to Ethereum blockchains). Transactions performed on blockchains count as points according to the scoring system and presented together with transaction extracts, which can be tracked.  
Figure 13: Front, perspective and rear view of cabinet container with sensors and agrochemical package.  
Figure 12 shows data collected by sensors, and generated alerts can also be checked via panels available in this tier.