# An IoT-Based Solution for Intelligent Farming +
## 4 Experimental Evaluation
### Evaluation Scenario Conditions  
We are interested in evaluating the behavior of the gateway under normal system operation conditions. Such conditions were defined in previous works considering the requirements and the design of the WSN [22], and the temporal conditions defined and explained in [24]. As these decisions are directly related with animal husbandry and livestock conditions, they were supported by partners of the project, namely the Agrarian School Of Viseu and Ramos Pinto, Lda. In summary, those conditions are:  
* The uC duration is set to 6 s (due to localization needs) and the MC duration to 60 s (the needed data report periodicity);
* The arrangement of one MC is defined as follows: one uC type 1 (PR), one uC type 2 (C2B) and the remaining ones are reserved for uC type 3 (B2B);
* The area to be covered is set to 10 ha, since, according to the practical experience of our partners, it is the average vineyard size of potential users of the solution;
* The number of beacons needed to cover such area is 20;
* The max number of collars in one property is fixed to 1000;
* The serial port baudrate is set to 115,200;
* The gateway is connected to the Internet through an Ethernet connection. To implement the gateway an Orange PI Zero (Shenzhen Xunlong Software CO (Guangdong, China)) [79] was chosen, due to its low cost and low energy consumption. This device features an H2 Quad-core Cortex-A7 H.265/HEVC 1080p, a 512 MB DDR3 SDRAM, runs a Linux-based Armbian operating system and it costs around 10E. Furthermore, the gateway application was developed using the \"C\" programming language and relies on a multi-threading architecture. Furthermore, as at the present stage of the project it is unpractical to perform the necessary tests using the maximum number of collars defined for a single property (1000), we implemented a generator of traffic that runs over a Linux platform and sends periodically (every MC), the expected data that would be generated by a defined number of collars and 20 beacons. That allows to easily evaluate the behaviour of the gateway under different traffic conditions. In order to ensure that the gateway is able to receive, process and publish all the data without congestion, and consequently without losing data, we measured the duration of all tasks, from the instant that the data sent by a beacon is received by the gateway via the serial port, until the moment that it is published into the broker. Those tasks are: (i) the time needed to receive all the data through the serial port interface; (ii) the processing time of the data received, including the time needed to store it in a shared memory and the time spent by the localization algorithm; and (iii) the duration of the task responsible for generating the messages (in JSON format) to be sent over the AMQP protocol and for publishing them into the broker. It shall be noted that when publishing messages through the AMQP library installed on the gateway, the measured time includes the time needed for generating a message, the propagation time of those messages through the Internet until reaching the broker, and the propagation of an acknowledge message sent by the broker after receiving the message. Albeit the worst case scenario is expected to occur with the maximum number of collars (1000), in order to understand the impact of increasing the number of collars, we relied on the implemented traffic generator to evaluate how those times evolve considering different number of collars (100, 200, 500 and 1000). For each one of these, we performed experiments that lasted for 300 MCs, thus around 5 h.  
Table 3 summarizes the medians of the durations measured. For improving readability, we split data into Beacons and Collars. Besides the duration of the tasks previously mentioned, we also present the cumulative time spent by all tasks. As it can be observed, the time spent by the serial port to receive the data is the most restricting task with the conditions defined, and naturally, it increases linearly with the increasing number of collars.