# An IoT-Based Framework for Smart Water Supply Systems Management
## 1 Introduction  
The Brazilian territory holds around 12% of the world's total freshwater [1]. Such a precious asset deserves careful management to preserve its quality and to avoid wastes in water distribution systems. However, approximately 40% of the water flowing through the Brazilian water supply systems in Brazil is lost. The waste represents almost 7000 Olympic pools of drinking water per day, generating a financial loss above USD 3 billion every year. The reasons for these losses are diverse: leaks, measurement errors, or even water theft. Smart water management in supply systems is essential to optimize the use of water resources and the quality of service. In this context, the Internet of Things (IoT) can be a valuable tool, as it enables the integration of multiple technologies, storing and analyzing data from different sources in real-time, and extracting contextual information. It can be difficult to anticipate all operational scenarios in IoT-based systems and to establish how managers should act in each situation. Modeling these operational processes through conventional workflows (e.g., Business Process Model and Notation (BPMN) [2]), based on fixed flows, is a considerable challenge. In this situation, the flexibility provided by declarative processes can be an adequate solution to deal with water systems. The declarative paradigm allows the execution of every activity provided it is not explicitly prohibited in the process specification [3]. Thus, it ensures that only activities that do not violate the policies of management will be executed. This paper demonstrates the advantages of adopting declarative processes in the context of water management systems through an illustrative example. The paper models a real water system using both process paradigms: declarative and imperative. Then it compares each model to evaluate its potential and limitations. After drawing the model, the process implementation phase took place. However, feeding the process in real-time with information that originates from the sensor network is a complex task, since the amount of data generated by the environment increases exponentially. Hence, there is a strong need for identifying information patterns hidden in such a data storm. To address this challenge, this paper exploits the Complex Event Processing (CEP), which is capable of dealing with the analysis of large amounts of data in real-time, and identifying patterns and relationships between distinct events. This paper proposes an IoT framework for intelligent water management, called REFlex Water. It uses declarative processes to model the water system. A process represents policies and the infrastructure required to control the water distribution, allowing operators to handle routine situations and unforeseen occurrences. REFlex Water implements the process using CEP technology. The paper tests the implementation performance to evaluate the framework's capacity to respond to scenarios with a high number of IoT devices and heavy data traffic. The main contribution is to provide a framework for smart water management, which provides efficiency in measuring and identifying leaks based on an IoT infrastructure. An additional contribution is the use of declarative processes to represent water management policies. Such a process modeling paradigm allows for the implementation of ordinary controlling policies but also offers the necessary flexibility to handle unforeseen situations. Table 1 shows the comparison of REFlex Water with other Frameworks. The characteristics C1 to C9 observed are as follows: use of declarative processes (C1), use of CEP (C2), monitoring system (C3), intelligent measurement (C4), energy management (C5), real-time data analytics (C6), monitoring water quality (C7), leak detection (C8), sending alerts (C9). The bullets refer to characteristics supported, while the minus to characteristics unsupported. Among the frameworks, it was observed recurring characteristics presented by SWAMP, [PERSON] et al.