# New Protocol and Architecture for a Wastewater Treatment System Intended for Irrigation
## 2 Materials and Methods
### Proposed Algorithm  
In this subsection, the performance algorithm of the elements of the proposed system is presented. The proposed algorithm has been divided into two parts. The first part shows the algorithm used by the sensor nodes to obtain the data and transmit them to a central node. This node is called Central Node and it is located in Urban Area 0, from which the data and alarms are sent to the AI and storage systems. The second part presents the manner in which the data are stored in the Storage Server and treated in the AI computers so as to later send the response action to the actuator nodes. The algorithm presented in Figure 5 shows the operation process of a group of nodes. As can be seen in Figure 2, a sensor node is not deployed on its own but in a group of three nodes that measure at the same point. This group is formed by one sensor node named Central Node, and two more sensor nodes. All sensor nodes are capable of detecting different parameters related to water pollution. All the sensors connected to the nodes take measurements every minute. If there are variations with respect to the reference values, the data are sent to the Central Node of the group, and at the same time the data are stored in the SD card. In addition to performing the usual functions of any other sensor node, distributed Central Nodes are responsible for sending data and alarms with information from any node in their group. These alarms and information are forwarded to the Central Node located in Urban Area 0, via wireless communication. This grouping of nodes allows for guaranteeing fault tolerance. If only one node detects pollution, the node sends an update to the Central Node of their group, and this Central Node checks if itself or the other sensor of the group has also detected pollution. If pollution is not detected by more than one node, it is considered a false positive. All the groups of nodes located in the different areas, urban or canal, can send updates to their Central Nodes via wireless communication. The Central Nodes send the information, via wireless communication as well, to the Central Node of Urban Area 0. The Central Node of Urban Area 0 is responsible for sending all information and alarms  
Figure 5: Algorithm for node groups. collected in all areas to the data center through a wired/wireless transmission medium. The data center is primarily responsible for storing the data, which can be consulted at any time, and generating analytical and machine learning models. In addition, it is also responsible for generating the actions that the actuator nodes must take. Generally, the action resulting from the detection of an alarm is associated with the start-up of one actuator node at least in one area. When the Central Node of Urban Area 0 receives an alarm, if it is known and has been previously treated, this node decides an action and makes an order to the actuator nodes so that the corresponding action is carried out. Moreover, the Central Node of Urban Area 0 sends the alarm to the storage and AI data analysis system. The second algorithm that we propose so as to store the data and alarms that are generated in the sensor nodes is provided in Figure 6. Once saved, they are processed by AI and then the decisions that are made are forwarded to the actuator nodes. Initially, when the data are received in the Storage Server, the system must differentiate if it is an alarm or if it is the data that have been obtained during an observation period. In case of an alarm, the received data will be tagged before being stored. If it is not an alarm, the data are stored directly. Then, they go to the computer where they are treated by AI. In this way, patterns of behavior can be detected. Depending on the problems that can be detected and the place where actions should be applied, several decision rules have been created. Those rules are applied based on the detected patterns.