Research on High Precision pH Sensing Device Based on Cloud Platform Service

. This project tries to design a wireless intelligent pH sensor to monitor the pH value of nutrient solution in real time by using the analog front circuit LMP91200, microprocessor STM32F103c8t6 and WiFi module. The experiment shows : this equipment has a high accuracy, can be 0.01; it can access business cloud services platform to achieve the functions like accurate acquisition and calibration of pH value, Interactive with cloud platform through WiFi Networks; APP and PC for the remote measurement is stable, after 12 hours of testing there is no packet loss phenomenon; Because of high uploading speed, in 5 seconds it can complete the device networking and upload, besides, the cloud services have changed the traditional way of nutrient solution measurement.


Introduction
Facilities agriculture is a cross sectoral, multidisciplinary, integrated system engineering which takes biological engineering, agricultural engineering, environmental engineering, automatic control technology as a whole.In agriculture, through the computer debugging facility environment putting the environment in a suitable state could achieve the purpose of early maturity, high yield, high quality and high efficiency.In the cultivation mode of the facilities, the cultivation technology of nutrient solution is the focus of the recent two years.In some foreign countries which are advanced in the field of plant cultivation technology, more than 50% are using the method of water culture.They use the nutrient solution instead of the soil to cultivate the plant, provide different plants' configures for different nutrient solutions, the purpose is to improve the mature time and increase the production.
The pH value is the hydrogen ion concentration index in the liquid, which is an important indicator of plant nutrition.Now the foreign countries lead in the pH measuring equipment, for example, the Swiss Mettler Toledo and Italy Hanna instruments.The advantages are high accuracy, good stability, but the disadvantage is high price.So if we use these equipment in the greenhouse, it will bring a huge cost.In our country, we also have the similar equipment and the price is low, but in practical application, the disadvantage is poor stability, poor accuracy and high energy consumption.Moreover, the conditioning circuit is complex through the high performance operational amplifier to make isolating, amplifying and filtering circuit to complete the acquisition of pH signals.In 2013, on the basis of Arduino, Bin Jun completed the pH measurement with the function of automatic temperature compensation and high accuracy, but the circuit is rather complex.In 2011, Zhang Jiaxing designed a kind of automatic pH measurement system.The circuit design is simple, however, the host computer software was designed to complete the pH monitoring, which caused the networking level is low and maintaining is not easy.
Du Zhiguo puts forward the remote real time water quality monitoring system architecture based on combination of Zigbee wireless sensor network and Internet, which realizes the acquisition and transmission of water quality monitoring parameters, but the volume is large and the cost is expensive.So it's not suitable for large area applications.However, along with the application of wireless sensor

The Architecture of pH Measurement System
The pH monitoring system designed in this paper uses low power, low cost, high speed wireless communication mode for real-time data transmission.And it also provides a simple, intuitive management platform to complete the management of wireless sensor, environmental information storage and analysis of processing functions for the users.The system structure diagram is shown in figure 1  Secondly, compared with the traditional PC, the speed of analysis and processing data is greatly improved; Finally, it saves the cost of the enterprise to build their own servers and the power consumption of the server operation.
Mobile Terminal: it can enrich the way of environmental monitoring.Whenever and Wherever you are, you can see the environmental information in the greenhouse by cell phone and PC.In the PC side, managers can directly enter the cloud platform through the login page to view information in real time, reducing the tedious tasks like software development and software maintenance.

pH Measurement Principle of Nutrient Solution
The composition of nutrient solution is more complex in protected cultivation.It not only contains the main nutrients needed for crop growth, such as nitrogen, phosphorus, potassium, calcium and so on, but also contains the necessary trace elements of crop growth.So, it's difficult to monitor all the nutrients.We just need to monitor several indicators of the nutrient solution, such as pH and EC.And then through the hardware facilities to adjust the environmental conditions, it would meet the needs of the crop growth.According to this we can see that the accuracy and stability of the pH value is critical.
PH is a kind of scale of hydrogen ion activity in the solution.Its formula is:

pH=-Log[H+]
At present, the calculation method of pH includes chemical analysis method, test paper method and potential method.Potential method is often used.The potential method uses glass electrode as indicating electrode and Ag/Agcl electrode as reference electrode.And then insert the two electrodes into measurement solution.
They formed original battery and the two electrodes are respectively the positive and negative electrode of the original battery.According to the Nernst Equation, the relationship among the output electromotive force of the primary cell, the absolute temperature of the measured solution and the pH value of the measured solution is:

E=E0+KT(pHx-pHs)
E is the original battery output electromotive force; E0 and K are constants, E0 depends on the type and structure of the electrode sensor film, K is the coefficient of Nernst; T is the absolute temperature of the tested solution.pHx is the measured pH value of the solution.pHs is the pH value of the buffer solution in the composite glass electrode.
According to the Nernst Equation we can know that the output electromotive force of the primary cell is produced by the interaction of the pH and the temperature of the solution.Therefore, if we can measure the output electromotive force of primary cell and the solution temperature, through the Nernst Equation, we could calculate the pH value of the solution.

Hardware Circuit Design
The sensor node is the basic unit of the environmental monitoring system with the

pH Electrode
The pH electrode, also known as the pH sensor, is a part of the pH device which is in contact with the material being tested and is used to measure the potential of the electrode.The PH electrode is mainly divided into two parts, the measurement electrode and the reference electrode.When placed in the liquid, they formed battery system.And then we could calculate the pH through the difference between the two electrode voltages.Now, most of the electrodes are combined together with the measuring electrode and the reference electrode, which named pH composite electrode.
Taking into account the harsh environment of agriculture, this paper selected the Taiwan HAOSHI pH electrode which is used in the industrial field.This electrode is used in the German industrial manufacturing technology.The pressure is 0.6MP.
It can be applied to a variety of conditions of pH measurement.The characteristics are fast response and good thermal stability.It also can be directly related to the use of various pH instruments.Moreover, this pH electrode has a high measurement accuracy by using PT100 thermal resistance for the temperature compensation.

Sensor Analog Front End Circuit
The Sensor analog front end circuit used in this paper is LMP91200 which is produced as the first integrated pH circuit by TI.The role of LMP91200 is to connect the pH electrode with the micro controller, so as to complete the pH measurement.The LMP91200 is designed for 2-electrode sensors and works over a voltage range of 1.8V to 5.5V, so it can be connected with a variety of different operating voltage microprocessors.The LMP91200 has low input bias and it is feasible that an external Pt1000, Pt100, or similar temperature sensor is integrated in the LMP91200, thus this device has a high precision.Fig. 3. is the structure circuit of LMP91200.

Data Acquisition Module
The core of the Data acquisition module is STM32F103C8T6 chip.The chip is based on the 32 bit Cortex-M3 kernel microcontroller and supports 72MHZ operating frequency.Meanwhile, it also integrates Flash 64KB and SRAM 512KB.The chip is rich in IIC, USART, SPI, ADC and other resources.In this system, we use the 12 bit STM32F103C8T6 of ADC to complete the analog digital conversion of the pH output voltage and through the WiFi module serial communication to complete the function of the data transmission to the cloud.

WiFi Communication Module
This module is mainly characterized by the Shanghai Hanfeng MCU autonomous development platform, cost-effective, support AP+STA two wireless interface.AP that is Wireless Access Point, means wireless access point.The wireless router is AP and other devices can be connected to each other by AP.STA is short by Station, which is like wireless terminal.The module can access the router through the STA and connected to the server via TCP.The HF-LPB100 supports AP+STA two interface modes.When in use, as AP for mobile phones or PC access and through the STA interface WiFi also can connect the router to complete the data upload.So the efficiency is greatly improved.HF-LPB100 also has the characteristics of small size, low power consumption(3.3Vpower supply, the average power consumption is 0.03W), supports serial transparent transmission mode.The RXD and TXD of the WiFi module is connected with the STM32 serial port to accomplish the serial communication, meanwhile, the reset, connection and the preparation interface is connected with the STM32 GPIO, so the microcontroller sends control commands to ensure the work of WiFi module.
4 Software Design

System Software Design
The application of this system is written in C language, compiled under MDK5.When the device is connected to the cloud, it will be under the cyclic working state.
The WiFi module every 1'30'' will send the reading MCU state instructions, and every 10 minutes MCU will automatically upload data.Figure 4 is the overall software flow chart.

pH Acquisition Program Design
The MCU writes the LMP91200 control words through the SPI communication mode : 0x6880, 0xE880,0xA880.By writing 0xA880, 0xE880 to get the Pt100、the voltage value of the calibration resistance and PGA magnification, then calculate the solution temperature according to the PT100 and the calibrated resistance terminal voltage.
The formula is: In the formula (1),VOUT_CAL is the calibration of the output voltage on the resistor R1, I_true is the actual current flowing through the resistor R1,PGA is a preset programmable gain amplification, the value is 10.In the formula (2),R_RTD is PT100,VOUT_RTD is the output voltage of it.In the formula (3),R0 is the resistance of PT100 in the 0℃,the value is 100,α is thermal conductivity, the value is 0.00390802.
After the temperature measurement, writing 0x6880 to the LMEP91200 chip for the pH measurement, then get the A/D conversion voltage, finally, calculating the solution pH by the Nernst equation.The formula is: In the formula ( 4),E is the output voltage of pH electrode, the value is VOUT_pH minus 1/2Vref,VOUT_pH is the output voltage of LMP91200,Vref is the reference voltage;E0 is the reference electrode voltage, it is a fixed value related to the pH electrode; R is gas constant; T is absolute temperature; F is Faraday constant.
For the accurate measurement, this paper uses the standard solution(25 C, pH for 4 and 6.86) to the calibration.
Combined formula ( 4) and ( 5): Then bringing the S and E0 to the pH calculation equation.Fig. 5. is the measurement of pH software flow chart.

The Serial Communication Between MCU and WiFi
The way of the serial communication between MCU and WiFi is asking and answering.The normal cycling state of MCU mainly includes four parts, the occurrence of the button, WiFi sending query commands, control commands and a heartbeat command.The design software prescribes that when the MCU or WiFi module sends commands to each other, the other party must return the response.If the sender has received no response to the instruction for 200ms, it will be resend.
The key event is used to select the mode of the network.The query commands are used to monitor the MCU state value.The control command is used for the WiFi module to send the control MCU instructions.The heartbeat command is used to monitor the communication between WiFi module and MCU whether is normal or not.If the MCU didn't receive the heartbeat for 180ms, it will determine the communication failed, and then restart WiFi automatically.

Rapid Development of APP
The gizwits provides some SDK packages for Android and IOS development, which has packaged some functions such as the network configuration, discovery, connection, control, heartbeat and state reporting etc.And also, in the gizwits official website, there are some open templates ,so the developers can quickly complete the development of APP according to it.This system is mainly for the development of Android mobile phone, mainly divided into the following four steps.
(1) Build Android development environment, download eclipse software and import pet house open source.Create the own project on the official website of gizwits and download the SDK package(including jar.so and so.so),then replace the jar.so and so.so in the LIBS files. (

Network Transmission Test
Network transmission test makes the WiFi sensor run for 10 hours, then through the communication log of gizwitsofficial website to observe the accuracy and stability.Fig. 9. is the interactive information chart of APP and cloud .

Conclusion
In this paper, by analyzing the problems existing in the pH monitoring in china and abroad and the development trend of the future, we design a device used for the pH measurement.The function is feasible that the data will be transmitted to the gizwits platform and monitored in real time through accessing both mobile phone app and website login cloud.The experimental results show that this device has a high accuracy, and can quickly complete the data upload, meanwhile it solve the problems of low intelligence, network management is not scientific in the domestic pH monitoring equipment, the research results have a certain practicability.
networks in the field of agriculture, WiFi sensor has been widely used in the field of environmental monitoring with the advantages of high transmission speed, strong anti-interference ability, strong compatibility.It has become one of the important means of communication in facility agriculture.In recent years, with the development of internet of things and cloud services technology, Baidu, Ali, Tencent have launched their own cloud platforms.Instead of PC, the cloud platform improves the speed of data processing.When the device needs to be upgraded, developers just need to upgrade the cloud at the far end instead of manually upgrading each equipment.The cloud platform not only improves the efficiency of the work, but also reduces the labor cost.Therefore, after analyzing the existing problems of pH monitoring equipment, this paper based on cloud platform proposes the design of pH monitoring equipment, including the hardware design, the communication among equipment and the cloud and the rapid development of the Android .The purpose is to improve the accuracy and stability of pH monitoring equipment in our country and to strengthen the degree of network management.
in four parts, including pH measurement equipment (monitoring nodes), wireless routers, cloud platforms, mobile terminals.Monitoring Node: composed of the WiFi sensor for monitoring pH in greenhouse nutrient solution.It is mainly responsible for acquiring pH value, timely sending data to the cloud server and completing the management function of the sensor power supply.Using WiFi to transmit data is to eliminate the difficulties in the wiring of the greenhouse.Wireless Router: Mainly to complete the function of wireless network coverage and providing WiFi network connectivity with the cloud.Cloud Service Platform: Bottom is composed of a huge number of servers and virtualization management software, when the devices access the cloud platform, firstly.

Fig. 1 .
Fig. 1.Structure of the system functions such as collection of environmental factors, data processing and signal communication.The hardware composition of WiFi sensor mainly includes pH composite electrode(used for measuring potential), sensor measuring potential analog front-end circuit LMP91200, STM32 acquisition module and WiFi module( used for communicating between the equipment and cloud).Fig.2. is the hardware structure circuit.

5
The Access of Cloud Platform and Mobile Terminal Development 5.1 The Access of Cloud Platform The WiFi module and the cloud completed a physical connection through the wireless router.In terms of data communication, the mqtt communication protocol code and network firmware are embedded into the WiFi module so that it can transmit data to the cloud according to specified format.To standardize and simplify the development of the equipment business logic protocol, a common data point protocol is developed for the interaction among devices, cloud, and APP.The advantage is that the cloud can analyze the data based on it, mobile APP can resolve the device data when they are in sending and reporting, MCU can complete the development based on the generated communication protocol.So, to the developers, you just need to edit the data points in the new individual project and define the data type, then it will accomplish the communication between the device and cloud.

( 3 )( 4 )
) Get the Productkey in the creating project,meanwhile,bounding the android application and get the APPID.Productkey is the only number of smart cloud the developers complete the development of the MCU,through the Productkey gizwits can identify the device and automatically complete the registration.The function of APPID is to associate the intelligent applications with the device.In the source code to create a new class APPlication used to inherit the native APPlication class, then initialize the device APPID in it and initialize theProductkey in MessageCenter file.Opening all the SDK log print level in the AndroidManifest.xmland allowing APP to communicate with the cloud.Registering SDK listener, using to callback the interfaces which have defined in the SDK, such as registration, login, configuration equipment, binding device.Design the UI, add the identity name of data point in the GokitControlActivity function, add the BindingDeviceActivity to callback the binding device.So, the APP development finished.The test is mainly to verify the accuracy of the measurement and the completion of the function.The comparison between theoretical value and measured value of pH was carried out by experiments.Not only that, the test uses the APP and PC to login the cloud to verify whether the WiFi sensor can accurately and stably upload data to the cloud.The choice of pH solution is the standard buffer solution(pH=4.00),which is produced by Tianjin Hengxing Chemical Reagent company.Figure 6 is the physical map of the system.Figure 7 is the APP value and the cloud value.

Fig. 9 .
Fig.9.The interactive information chart of APP and cloud 14 software, including the main function, pH acquisition program design, as well as WiFi and MCU serial communication protocol three aspects.After the completion of the electrical initialization on the device, you should choose Airlink or Softap to access the could when the WiFi is first access the network.The Airlink model is a collective name of SmartConfig and SmartLink, which is compatible with a number of WiFi vendor communication protocols and the WiFi devices of smart cloud have been built in this feature, but it doesn't support the 5G signal.Softap model is the supplement of Airlink.In this mode, the device becomes a AP.The mobile phone can be directly connected with the WiFi device, and then enter the router account number, password.The device will automatically connect the router.

Table 1 .
Table 1 is the transmission format of WiFi module to obtain MCU data.Table 2 is the transmission format of MCU response WiFi module.The transmission format of WiFi module to obtain MCU data

Table 2
The transmission format of MCU response WiFi module