# New Protocol and Architecture for a Wastewater Treatment System Intended for Irrigation
## 2 Materials and Methods
### Architecture  
In this subsection, the proposed architecture is presented. The example of the area where the nodes are to be deployed is presented in Figure 1. As it can be seen in the image, there are several urban areas. These areas are zones with a population that may discharge wastewater into the canals that transport the water to the fields and is therefore subject to spill control. Furthermore, these areas have access to the electricity grid and the telecommunications infrastructure. The other area is the canal area. This area is located in an irrigation canal that leads to the fields. As it can be seen, in the canal areas, there is a comb-shaped structure that is formed by auxiliary canals that are connected with one another and have several gates that connect to the main canal. These auxiliary canals are prepared to implement the biosorption process that treats the water and removes contamination. The sensor nodes deployed within the different zones communicate through wireless connections. Moreover, the communication between each of the zones is established wirelessly as well. In one of the urban areas, which in Figure 2 is called Urban Area 0, the gateway will establish a wired connection to transmit the data to the data center for storage and data analysis. The data that are received with information from the different nodes will be treated with artificial intelligence (AI), to respond with appropriate measures in our system. Lastly, the adopted measures will be forwarded to the actuator nodes to let the contaminated water go through the biosorption process. Figure 2 allows for visualizing in greater detail the location of the nodes in one of the canal zones. As can be seen, there are nodes to which different types of sensors and actuators are connected. Several auxiliary canals are found as well. These are comb-shaped canals where the biomass is located. The biomass is responsible for the decontamination of the water. As seen in the image, the biomass canals are replicated and connected, so the water can go through one or several decontamination phases, depending on the results of the samples obtained by the sensors, which are located at the end of each biomass canal. The actuator nodes are connected to lock-gates that allow for regulating the passage of the water flow. The proposed architecture, formed by three layers, being Nodes Sensors & Actuators, Storage & Activation, and Artificial Intelligence, is shown in Figure 3. In the Nodes, Sensors & Actuators layer, all the nodes of the network are located. The different sensors  
Figure 1: Deployment of node areas. Figure 2: Example of canal zone in detail. that take measures of the water quality are connected to the nodes. Then, the data are periodically forwarded to the data center situated in the upper layer, where the data are stored. Furthermore, the actuators are connected to the nodes that are located at the gates of the canals so that the appropriate actions that have been decided in the higher layers are performed. On the other hand, the Storage & Activation layer hosts the devices where the information received from all the sensors is stored. Furthermore, this layer also hosts the system that allows for sending orders to the actuators so as to carry out the actions established by the decision-making process that is performed in the upper layer. Lastly, the systems that allow for processing the data that were stored in the lower layer are located in the Artificial Intelligence layer. This layer oversees the decision-making process whose result will be sent to the action functionality in the lower layer. The protocol stack is presented in Figure 4. As it can be seen, the Network Interface layer uses an ethernet protocol in the wired network, and a LoRaWAN protocol to perform wireless transmissions. The wired network is based on the stack defined by the transmission control protocol/internet protocol (TCP/IP) reference model. IPv4 and IPv6 protocols are used in the Network layer.