## 5 Practical Application of a Self-Adapting IoT Network  
The ideas and concepts presented in this article have been implemented in a system designed to manage micro-, small- and medium-sized greenhouses. The system comprises the following elements:  
* Sensors for air temperature, air humidity, soil pH, soil humidity, light intensity and composition (five bands of wavelengths);
* Actuators;
* Management units: IoT devices capable of collecting data from the sensors, buffering them in a local database and sending them to the cloud;
* Connectors;
* Network interfaces;
* Cloud-based management system. The purpose of implementing the system described in this article is to offer support for plant growth in indoor greenhouses. This is achieved through the execution of automated recipes and continuous monitoring of predefined capabilities. If any of these capabilities are compromised, then the system will take necessary actions to restore them. Figure 6 illustrates a sample implementation of the solution described in this article. In the indoor farm, a grid of sensors is placed over the greenhouse. A detailed description of the experimental set-up is described in Appendix A. The sensors were connected to management units using \"connectors\", specifically 4 wire cables that provide 12 V of power and RS-485 connectivity for a Modbus network. The management units were built on Raspberry Pi 3B devices equipped with custom RS-485 adapters. Each management unit could handle up to 256 sensors (the limit of Modbus network addressing), although for resilience purposes, the maximum number was 25 sensors per management unit. Each management unit operates independently and can perform various tasks without a connection to the cloud services. For example, in the event of a network outage, it collects  
Figure 6: Indoor greenhouse powered by an IoT grid. data from the sensors, stores it locally and sends the data to the cloud service once the network connection is restored. The connection with the cloud service is established over the public Internet. To ensure resiliency, several connections might be created for a single greenhouse. The cloud-based management system has been implemented as a set of components hosted in the Microsoft Azure cloud, including the following:  
* Azure Event Hub;
* Cosmos DB;
* Custom.NET applications deployed as Azure Application Services;
* Management and reporting interfaces deployed as Azure Web Services. **Graph Representation of the Indoor Farm Management System**  
The solution described in this document was designed as a \"digital twin\", where the physical system is represented by a corresponding graph. The IoT network graph of the presented solution consists of more than 100 nodes, representing sensors, actuators and management units. While the majority of the graph follows a tree structure, there are additional connections that extend beyond the basic tree structure, spanning across multiple nodes. Another category of connections represents redundancy, which is vital for handling failures. Each node representing a sensor is associated with a set of properties that define the threshold values for individual readings and aggregates. For example, a temperature sensor's single reading is expected to fall within the range of 20-27 degrees Celsius, while the average value over the past 6 h is expected to be within 23-24 degrees Celsius. The system updates the sensor data from every 30 s to 5 min. Each update is compared against the properties of the corresponding sensor node and may trigger an action if the data fall below or exceed the defined thresholds. This comparison process is a relatively simple operation that does not necessarily require the use of graphs. However, thanks to the graph representation, the system can automatically consider additional factors, such as the physical distance between sensors in the same area. With this additional information, a single discrepancy can be interpreted as a sensor failure rather than an event that should generate a \"temperature out of range\" alarm.