# A Testbed to Evaluate the FIWARE-Based IoT Platform in the Domain of Precision Agriculture
## 4 Testbed
### IoT Use Case Scenario  
We are assuming a distributed scenario in the field of precision agriculture/viticulture (i.e., crops in several different regions or countries). Hypothetically, this is a complex IoT scenario as it involves managing a large number of _resources_ associated with sensors and actuators. Specifically, the sensors detect data relating to the environment (e.g., air temperature, relative humidity, solar radiation and precipitation) and the state of the vineyards (e.g., water and nutrients). The actuators are installed in crop irrigation systems. The system has to be scalable: if the number of sensors and actuators is increased, only computational resources would need to be increased without implying greater complexity or system redesign. To address this challenge of scalability, the implementation of the _Farm Management System_ (FMS) illustrated in Figure 3 is planned. Figure 3: FMS envisioned based on FIWARE IoT architecture (lower part drawings are from [57]). The FMS that has been designed takes advantage of the new features offered by the _Future Internet_ by relying on the IoT FIWARE architecture (see Section 3.3). Vineyards are divided into management zones, each with a Zigbee wireless sensor network (WSN). The IoT Gateways of these networks host characteristics of Protocol Adapter and Data Handling GEs. These gateways are located in the vicinity of the devices. The IoT Gateways connect to a specific FILAB account [58] (FIWARE testbed), which hosts instances of IoT Broker, IoT Discovery and Context Broker GEs. Our application, FMS, is also hosted in this instance. The functions performed by these components are explained below. **Registration of IoT Devices and Resources**  
1. When starting the system, the Protocol Adapter automatically detects the IoT _resources_ associated with the devices, sensors or actuators in its management zone. 2. For each _resource_ detected, the Protocol Adapter sends a _registerContext_ request to Data Handling. 3. When the Data Handling register receives the _registerContext_ request, it creates an _entity_ in its local database _modelling the resource_, and sends a _registerContext_ request to IoT Discovery. IoT Discovery bundles information on _resources_ from different management zones. **High-Level Modelling of Things**  
4. We now turn our attention to the opposite end of Figure 3, the application of FMS and the Context Broker component. The FMS application implements a RESTful HTTP client that can invoke Context Broker services. The _updateContext_ service of the Context Broker is invoked both to create new _entities_ that model _things_ and to update the status of existing entities. Two types of entities are thus created: the resources that are detected automatically (steps 1 and 2) and the things which are defined explicitly from the application. In FIWARE, resources and things represent different levels of abstraction, as also shown in Figure 2. Things tend to pool resources according to their location and type of attributes. The Context Broker can access information from the resources through a component not yet presented: the IoT Broker. 5. Mapping between resources and things is achieved in IoT Discovery which records _associations_ between entities that model things and those that model system resources. **Subscription to the Information Generated by the Entities**  
6. Once entities have been defined, whether these be resources or things, any application can subscribe to the information that these entities generate by invoking the _subscribeContext_ operation from the Context Broker. In our case the FMS application creates entities and subscribes to them, and Cosmos, which is a storage system for FIWARE Big Data, have also been subscribed to them. The Cosmos connection is not direct but rather through another FIWARE component, the injector Cygnus-NGSI. Note that there is a chain of subscriptions and brokers (Data Handling, IoT Broker and Context Broker).