An Open-source Wireless Platform for Real-time Water Quality Monitoring with Precise Global Positioning

Sustainable development associated with the agricultural field of Arequipa, a region in economic growth, is vulnerable to contamination of water resources, putting production systems and food security at risk. Therefore, it is necessary to implement an automated system to control, management, and monitor this vital resource. The proposed work proposed a system to measure water quality monitoring in reservoirs and lakes with high accurate related to global positioning. It includes an embedded computer, multiparameter sonde, and an additional dual GNSS/INS in hardware architecture. The software architecture is fully open-source with compatibility, modularity, and interoperability features between Python and MySQL, allowing data management for real-time data in visual interface on a platform that stores unlimited data logging, monitors and analyzes. The proposed system is validated in an experimental test that measures the water quality of a huge agricultural reservoir, where certified instrumentation is mandatory, as compared to other methods used locally for this action. Keywords—Open-source; water quality monitoring; real-time; python; visual interface; MySQL; dual Global Navigation Satellite System (GNSS); Inertial Navigation System (INS); multiparameter sonde


I. INTRODUCTION
Arequipa (latitude -16.3988, longitude -71.535, and altitude 2335 m.a.s.l.) is one of the main economic regions in Peru with approximately 1,497,438 inhabitants. It is also one of the fastest growing regions in the country, stands out for mining and agricultural activities, which generate some conflicts in the management of water resources and those related to water quality [1]. This entails many risks and losses in all aspects of sustainable development in the urban-rural area that surrounds the region; either due to the misuse of chemical products related to these industrial activities and others [2].
The objective of this work is to develop an open-source integrated system for measuring water quality with accurate positioning. A dual GNSS device is used in conjunction with the depth meter embedded in the sonde. Electronic systems condition the signals from the sensors and the positioning system to send them to a high-performance computer. Measurement data is stored in memory in structured query language (SQL) database, to be later transmitted remotely through the 802.11a Wi-Fi network. In addition, a multiplatform interface is developed for data visualization in real-time and in offline mode.
The paper is organized as follows: Section 1 presents a brief resume of related works in integration system for remote water quality measurement; Section 2 presents the system description in hardware and software; Section 3 presents the validation of integrated system when measured a huge agriculture water reservoir; and Section 4 gives the conclusion.

II. RELATED WORK
The study of water quality is carried out by conventional methods such as taking samples in appropriate containers for subsequent analysis in the laboratory, methods that require high time, cost and human resources [3]. Another method includes specialized sensors that measure parameters such as pH, conductivity, salinity, turbidity, etc. in-situ [4], [5]. These sensors, embedded in a multiparameter sonde, serve to measure large volumes of water (lagoons, reservoirs, coastal waters) using commonly manned vessels to collect data in real-time and to save in a data-logger or in a computer. Measurement position is commonly provided by additional global positioning system (GPS) [6]. Some manufactures have developed their smartphone application in order to provide the positioning based in the smartphone global positioning system. Another research combines inertial navigation system with precise global positioning system [7]. High computational hardware is increasingly used to improve the accuracy of these systems and to use big data analysis [8]. Researchers have been developed systems with low-cost sensor and ZigBee low range wireless communication to measure water quality in aquaculture [9]. Another solution to measure wide areas of water uses multiple set of sensors replicated in different location to form a wireless sensor network [10].
Water quality monitoring systems use information technologies, such as human-machine interfaces, databases, structured programming, facilitating the visualization and alert of the measured parameters. In [11], the authors present the application of these techniques in reservoirs that feed large hectares of agricultural land. Among these information technologies, the use of free software, such as Python, MySQL and Grafana stands out, which have shown promise in similar applications [12], [13]. Regarding the database and wireless remote sensing, in [14], the authors present a remote monitoring system applied to the management of a bridge with measurements of parameters such as voltage, current, positioning, images, etc. The open-source hardware and software tackle many problems related to security, data management, flexibility, analysis, and low power. They have shown successfully implementing process and configuration related monitoring wireless sensors in similar application [15]. There are several researchers including low-cost sensors for water quality measurement systems [16], [17]. However, the environmental agencies and industry prefer the use of certified instrumentation and precise positioning to validate their analyses [18], [19].

III. MATERIALS AND METHODS
The laboratory for complex control process and unmanned vehicles at the 'Universidad Nacional de San Agustín de Arequipa' is leading research projects related to the development of enhanced systems for ocean and nature supervision [20], [21]. This paper describes a modular system to be employed in measuring water quality with high accuracy, both in unmanned and manned vehicles.
The proposed system shows the interaction between user and water as a liquid element for its remote monitoring; aided by dual GNSS, inertial sensors, database management system and other resources as shown in Fig. 1. The goal of the system is to quantify water quality through a multiparameter sonde with data metrics involving static measurement with high precision and dynamic measurement with additional data of position and velocity. Display and format metric data should be available for all measurements, both offline and real-time. High performance and great coverage are required in order to measure reservoirs, lakes and coastal waters. All these requirements are correlated to achieve the proposed goal.
One of the requirements is safe and fast connectivity, for which we will have a point-to-point wireless link with a coverage range greater than 15 km away. The wireless connection obtains continuous and synchronous data to study and analyze the water quality. Unwanted chemical parameters can be diagnosed in real-time in a certain area. Commonly, certified instrumentation uses industrial communication protocols and additional equipment for monitoring and control. Fig. 2 presents the block diagram of the proposed system where the embedded computer, the GNSS/INS device and the multiparameter sonde are hardware communicating each other trough wired protocols, the wireless protocols enable a communication from a ground station that generally is a laptop or a smarthphone. Another software are related to each component in this block diagram and will be explained in subsequent sections. Fig. 3 presents the system description of the monitoring system that consists of the Aquatroll 600 model multiparameter sonde, a Jetson TX2 high performance computer, a VN-300 as the dual GNSS/INS (global positioning system with inertial measurement unit), a TP-Link router CPE510, and a platform interface for data visualization running on a smartphone laptop or similar to a ground station. The sonde communicates with the embedded computer through the Modbus industrial protocol. The embedded computer receives data from the GNSS/INS synchronizing it with the data received from the sonde. The sonde and the dual GNSS/INS data are stored in the embedded computer memory. Using a laptop or a smartphone, and through a wireless link, the user can remotely access to the embedded computer in order to set and read the data. A graphical user interface is created for data visualization with indicators and alerts, both offline and real-time.

A. Software Architecture
The main software is based on Python open-source language programs with free libraries and modules, such as 'PyMySQL' and 'PyModbus' to connect databases and remote sensors in the well known industrial Modbus communication protocol. The Python codes communicate, configure, convert data types, compute mathematical equations, administrate and save data in a computer memory. Fig. 4 describes the drivers of this software architecture, the remote access is carried out using secure shell protocol (SSH) to enable local devices running on Windows, Linux, iOS, Android, etc. The communication is set with permissions according to the user profile, from reading to editing the existing Python codes. The 'PyMySQL' module is a Python library for MySQL clients based on Python enhancement proposal (PEP) 249, that uses a high level application programming interface (API) named 'mysql.connector' for interaction with SQL databases. The data displays in a graphical user interface (GUI) and is developed on Grafana, a software tool that allows to connect with many databases, including MySQL. This software includes Prometheus and Graphite modules to request information and to display it in a modern dashboard, respectively. Grafana uses the hypertext transfer protocol (HTTP) to read the MySQL database and the dashboard runs on a web browser on multi-platform devices, from smartphone to advanced computer. It is mandatory to enable the port 3000 for access as a client, other necessary configurations are related to transmission control protocol (TCP), domain name system (DNS) and internet control message protocol (ICMP).
The software platform allows the user to easy and efficient interaction through key performance indicators in the dashboard for data visualization, using Prometheus and Graphite metrics. Through Python code and MySQL, the sensor data and GNSS/INS data are saved in the remote computer. Then, the GUI reads and displays the data, updating constantly every second. This means that the user consults the parameter values to be displayed by communicating with the MySQL database. These consulted parameters are registered from the sensors attached to the sonde and to the dual GNSS/INS devices, and are properly organized in SQL format to be transmitted in real-time. The user consults the values in the GUI using text indicators, graphical indicators, alert indicators, time series indicators, and others provided by Grafana.
All protocol and technological standards used for the interoperability of the measurement system are represented in Fig. 5. The system has compatibility with communication protocols, such as Modbus, serial UART, IEEE 802.11a/n, TCP/IP, SSH, etc. For the communication with the multiparameter sonde, a module named 'PyModbus' is used, enabling the two wire synchronous communication to set, read, write and save the collected data. Using the 'PyMySQL' module, another Python code manages the data in an SQL format and saves it in the memory of the main embedded remote computer. The multiparameter sonde and the dual GNSS/INS devices have different sampling rates and the data are saved in different tables of the database. However, the GUI updates the data independently every second and keeps the wild sampling rate for all parameters to be displayed. The open-source software files are available in [22]. The embedded computer is a Jetson TX2, a 64-bit ARM A57 quad-core, 1.33 TFLOPS fast embedded Artificial Intelligence, and higher energy efficiency 7.5 W -15 W. It interconnects peripheral devices and processes all information regarding data writing, reading, storing, management, transmitting, etc. The power source is fed with two HRB, 5200 The sonde is a multiparameter in situ water quality instrument, series Aqua Troll 600, equipped a RS485/Modbus communication protocol, provides laboratory level sampling through optical sensors, can be submerged up to 100 meters deep through a rugged cable, has 3 seconds of sampling rate, reads 20 parameters and expandable to more (Table I). The sonde is connected to the embedded computer through the RS485 to USB adapter, the electrical connection follows the standard color code: RS485 (+) or blue to A pin, RS485 (-) or green to B pin, and GND/RETURN or black to GND pin, respectively. The embedded computer runs on Ubuntu 16.04 and where the USB adapter port is identified by ttyUSB0. The dual GNSS/INS device is a VN-300 series, VectorNav manufacturer, combines inertial navigation system (INS), attitude heading reference system (AHRS), a global navigation system, measures angular velocities (roll, pitch and yaw) with a dynamic heading accuracy of 0.2 • and static accuracy of 0.15 • (see Table II for whole parameters). The embedded computer runs on Ubuntu 16 and where the USB port for the dual GNSS/INS device is identified by ttyUSB1. The remote communication wireless device is a Tp-link Pharos CPE510, provides a point-to-point wireless link with a coverage range of more than 15 km, with a speed of up to 300 Mbps (40MHz, dynamic), with the IEEE 802.11a/n wireless standard. It is fed with two HRB 5200 mAh, 50C, 11.1 V, Li-Po batteries, connected in series to obtain 22.2 V. Fig. 7 presents a detailed description of a waterproof case that contains the embedded computer and electronics, has a resistant design to protect systems against dust, water, impacts, and corrosion for chemical agents, commonly found in the harshest environment. The case dimensions are 425 mm (length), 284 mm (width) and 155 mm (height). A structural grid supports the electronics and impermeable Bulgin class connectors for the multiparameter sonde and Wi-Fi and GNSS antennas located at the external. The open-source hardware files are available in [22].

IV. RESULTS
To validate it through a real experiment, an unmanned surface vehicle (USV) (Fig. 8), whose most positive aspect is that it is scalable in terms of measurement instrumentation, with an autonomy of 5 hours and payload of 100 kg. Transporting the proposed system on a mission to measure the water quality of a huge reservoir of approximately 58000 m 3 capacity, 150 m x 150 m length, and 6 m depth, used for agriculture irrigation, and located in a desert area of Majes (longitude -72.1908, latitude -16.3586, and altitude 1.402 m.a.s.l.). The full mission took 2 hours and the data serve to ensure the water quality of the typical crops, such as chili, paprika, vegetables, potato, onion, corn, alfalfa, garlic, tomato, etc. The concern is the water is transported from the Andes through ducts and may contain unwanted concentrations that may compromise the crop and its subsequent harvest. Fig. 9 shows the measurement area of the cited agricultural water reservoir with dimensions and a segment of a circular trajectory recorded by the system. with the main parameters relative to water quality. It is observed, despite the vehicle execute a circular maneuver,the umbilical of the multiparameter sonde is subjected to external hydrodynamic forces that can vary slightly its depth location.    Fig.  11 shows a general description in the visual interface with the 20 parameters regarding water quality, including global positioning. Fig. 12 shows by separated the 15 parameters related to accurate location of the measurement using the dual GNSS/INS device. Due to the specific mission task, the vehicle is moving, and the INS enables additional data, such angular and linear velocities, that can also be visualized in the interface and in real-time. Fig. 13 shows an offline analysis using Matlab plotting the main water quality parameter. In this case, there are only four variables selected from the MySQL database, real electric conductivity, specific electric conductivity, pH level, salinity. Fig. 14 shows an offline analysis using Matlab plotting the main global positioning parameters. The software architecture enables the possibility to use any other third part software for a detailed off-line analysis. Table III shows the measured parameters in details, both when dynamic and static. The dynamic computes mean values of the whole data, and the static is the specific measurement point without vessel motion. These results have shown there are slightly variation in measurements, the big data acquisition is necessary, can serve for better estimation and to observe specific region of the water where conditions may be critical to irrigate agricultural crops. Regarding alerts, the visual interface enables to set minimum and maximum indicators for all the parameters in order to detect inadmissible water conditions for the agriculture purposes. The user access safely protected and will be able to observe minimum, maximum, average values, etc. As an example, the alert is activated when the pH value reaches a maximum of 8.85, considering that this value may alter the life cycle of the crop and further economic losses. The proposed visual interface also may notify the alert online using JSON message protocol. Despite the updating time is one seconds, the whole sampling data are received relative to the sampling frequencies, 1 sample per three seconds by the sonde and 50 samples per second by the dual GNSS/INS device.   In huge water reservoirs, it is important to observe different point of water quality, and the proposed alternative tackled this inconvenient. Another further application is for marine water quality monitoring in Peru, because these values may change dramatically relative to the depth, and it is a key factor to ensure the habitat of marine species. It is known that GNSS devices have a higher accuracy and refresh rate than GPS, but these are more susceptible to obstacles such as trees, buildings, tunnels or electromagnetic fields. Considering tasks away from these obstacles, the GNSS is an attractive solution. In [23], the GNSS devices with dual antennas presents an immunity in their measurements for a reference system of constant move-    [16], [17]. The proposed system is also prepared with serial ports to receive other certificated sensors and instrumentation, that fill with the high standard requirements for industry and governmental agencies. In particular, the Aquatroll 600 sonde is very common in Peru for agriculture and mining activities and the insertion of new sondes should be pass with rigorous certification procedures before to get their practical acceptance.

V. CONCLUSION
Monitoring water conditions is essential in agricultural activities and in countries where mineral exploration is so close to these activities. The integration of hardware and software is necessary to attend more requirements in terms of precision, accuracy, and human-machine interface for data visualization. This work validates the integration of a certified multiparameter sonde with a dual GNSS/INS device in an embedded computer system in order to increase the accuracy in global position of measurement data. Moreover, the work presents open-sources technologies, a detailed description of the visual interface using MySQL and completely Python code. The system is validated when it is attached as a payload to an unmanned vehicle during the mission to measure the state of the water in a huge reservoir destined for agricultural activities in the Majes-Arequipa region, a desert area irrigated with water that flows from the Andes. Due to limited access and budget, this project collects 20 water quality parameters, based on the availability of sensors and the study area. This platform has a great potential for scalability leading to future work that aims to add more instrumentation, programming, communication and incorporation of IoT. These can contribute to research work with more features and applications of monitoring control of the aquatic environment.

ACKNOWLEDGMENT
The authors thank the 'Universidad Nacional de San Agustín de Arequipa' for the financial support given to the construction of an unmanned aquatic vehicle, under contract number IBAIB-08-2018-UNSA project. The acknowledges go also to the administrative staff of the 'Junta de Usuarios Pampa de Majes' for supporting the experimental tests in the VR-4 agriculture reservoir.