Development of a Remote Monitoring System for Henhouse Environment Based on IoT Technology

: To monitor multiple environmental factors of henhouses in modern chicken farms, a henhouse online monitoring system based on wireless sensor network was developed using wireless sensor technology and computer network technology. Sensor data compensation and correction were designed to be achieved using software and data fitting methods, data reliable transmission achieved using a data loss recovery strategy, and data missing during monitoring addressed using a self-decision and online filling method. Operation test of the system showed that: The system was economic and reliable; it enabled wireless monitoring and Web display of the environmental factors of a henhouse; and the root mean square errors (RMSEs) between the estimated values from the self-decision and on-line filling method and experimental values of the four environmental factors were 0.1698, 3.0859, 77 and 0.094, respectively, indicative of high estimation accuracy. The system can provide support for modern management of henhouses and can be transplanted to related monitoring scenarios in the agricultural field.


Introduction
Modern closed henhouses mostly adopt a multilayer cage rearing system with a high breeding density.Besides relying on technological advances in breeding and rearing, modern henhouses impose high requirements on the henhouse environment.Of all the parameters, temperature, humidity, CO2 concentration and NH3 concentration are especially important for chicken health [1].Modern monitoring technologies can provide a scientific management basis for henhouse managers and help to raise management efficiency and lower production costs [2].
The Internet of Things (IoT) is a new information technology and the network of things that are connected to the Internet through corresponding sensing devices to enable data acquisition, fusion and processing and allow intelligent identification and management at the operating terminal.IoT is widely applied in fields like modern greenhouse environmental monitoring [3,4], agricultural product tracing [5], smart city [6], livestock and poultry farm environmental monitoring.For livestock and poultry farm environmental monitoring, [7] reported that AVR controllers were used to monitor the temperature, humidity, CO2 concentration and NH3 concentration inside a henhouse, the configuration software LabVIEW was used to design visual application software, and fuzzy control was used to regulate the temperature, humidity, CO2 concentration and NH3 concentration inside the henhouse.It is documented that for the structure of traditional henhouses, a remote environmental monitoring system was developed based on ARM and Zigbee technologies in [8].As a result, labor intensity was lowered and work efficiency was raised.It was reported in [9] that temperature inside henhouses was monitored and GPRS technology was used to realize overlimit short-message warning.In [10], CC2430 was used to design a wireless sensor network to collect data of temperature, humidity and CO2 concentration inside a poultry house.Consequently, wireless data acquisition was realized and system cost and maintenance difficulty were lowered compared with wired data acquisition.
In summary, henhouse environmental monitoring systems based on IoT technology are popular among users because it is networking with no need of wiring and it is of low updating and maintenance costs [11,12].However, previous studies mainly focused on system design with little attention paid to the reliable transmission of wireless data.In fact, equipment like hencoops of steel-frame structure in henhouses cause great interference to the wireless data transmission of multiple sensors such as data duplicated and data missed.What is more, henhouse environmental monitoring systems based on IoT are yet to be widely applied [13,14].In this study, a wireless transport protocol based on a loss recovery strategy was proposed to address the issue of data packet dropout during wireless transmission so that the practicability and reliability of such henhouse monitoring systems can be enhanced.In addition, duplicated data auto-filtering and missing data online filling were achieved.In view of the requirement of remote mobile monitoring, a Web remote monitoring system was designed.Authorized users could access the monitoring information through a PC or a mobile smart terminal.Remote monitoring and management of the henhouse environment were thus realized through a simple and friendly interactive interface, and with higher management efficiency.

The Overall Architecture Design of the System
The system adopts a modular design and consists of a field monitoring subsystem, a database subsystem and a remote monitoring subsystem (Figure 1).

Figure 1.
Overall design of the remote monitoring system for henhouse.

The Field Monitoring Subsystem
The field monitoring subsystem is based on a Client/Server (C/S) architecture.The acquisition nodes regularly collect henhouse environmental information, pack it into environmental parameter data frames and send them to the gateway nodes through the wireless module UTC-4432B1 (Hangzhou Fytoo Electronic Technology CO., LTD, Hangzhou, China).The gateway nodes then process and display the data frames and forward them to the management software of the subsystem PC after the validity of the data frames is verified by CRC.The management software communicates with the gateway nodes through a wireless communication protocol based on Modbus protocol to process and display henhouse environmental temperature, humidity, CO2 concentration and NH3 concentration and store them in the MySQL database for convenient data management.

The Database Subsystem
The database subsystem is between the field monitoring subsystem and the remote monitoring subsystem and is a communication bridge between the two.Environmental parameter information, equipment state, equipment control record, short-message warning record, user account and so on collected by the system are stored in the database for user query and analysis.

The Remote Monitoring Subsystem
The remote monitoring subsystem is developed using Java Web technology and is a Web remote monitoring system based on MVC pattern.The monitoring terminal does not require a dedicated client application program and includes such functions as real-time display of environmental information, historical data query, equipment remote control and user management.Henhouse environmental data information can be checked through a browser.

Sensor Data Compensation and Correction
Accuracy of henhouse environmental parameter collection has important effects on the modeling and regulation of henhouse environment.Under the condition that system costs will not increase, software technology is used for data compensation and correction to raise data acquisition accuracy of the sensors.The CO2 sensors directly output the digital quantity after filtering processing, and no follow-up process is needed.

NH3 Concentration Compensation and Correction
The output voltages of the NH3 sensors are 0-3 V and converted to NH3 concentrations through AD conversion.The acquisition node controller uses an STM32F103VET6 MCU (Shenzhen Spring Electronic Technology CO., LTD, Shenzhen, China) whose ADC reference voltage requires an external connection.Affected by mains voltage fluctuation, AD acquisition is not accurate.Therefore, two paths of AD acquisition are designed: One directly acquires ADC reference voltage, and the other acquires the output voltages of the NH3 sensors.NH3 concentration is computed proportionally and accuracy of NH3 concentration acquisition is raised.At the same time, filtering processing is performed using a median average filter to eliminate the effects of randomly arriving impulse interference on the accuracy of measuring results.

Temperature and Humidity Compensation and Correction
Digital sensor DHT22 (Aosong (Guangzhou) Electronic CO., LTD, Guangzhou China) is used for temperature and humidity acquisition and values are output in a unibus data format.As the sensors exhibit non-linearity and hysteresis and errors exist between the acquired values and the true values, a standard tester of high-precision is used for compensation and correction.Taking temperature as an example and referring to the preference temperature range of henhouses, incubators with a constant temperature precision of 0.5 °C is used to design the test.The constant temperature range is 8-37 °C with a step length of 0.5 °C.To simultaneously compensate the errors caused by non-linearity and hysteresis, the sensors are tested for both forward and reverse paths.According to henhouse temperature measuring requirement in actual production, a linear fitting function with mean square error of 0.058 between sensor acquisition value and standard value is used as the forward compensation function using the Matlab (Mathwork, Natick, MA, US) fitting tool.Similarly, the reverse path is compensated using a linear fitting function.Two consecutive temperature values are read by the system.The first reading is a temperature value acquired in last cycle while the second reading is a real-time acquisition value.If the real-time acquisition value is larger than last acquisition value, the real-time acquisition value is included in the forward compensation function, otherwise included in the reverse compensation function.Final temperature value can then be computed, and temperature is compensated and corrected.As a result, temperature acquisition accuracy is raised.Figure 2 shows the verification test results of the compensation algorithm.The absolute error of temperature measuring decreased, with the maximum error being 0.4 °C, which met the temperature measuring requirement of henhouses.

Design of Acquisition Data Reliable Transmission Based on a Loss Recovery Strategy
To raise the reliability of acquisition data transmission, a data transport protocol based on loss recovery is designed for loss detection and loss retransmission so as to lower packet loss rate.The acquisition nodes are responsible for loss detection and regularly detect sending flag of the equipment by timer interrupt.When data frame is missing during transmission, it is resent by the acquisition nodes.To avoid affecting data acquisition in the next cycle, maximum number of retransmission is set up.As there are multiple acquisition nodes, data collision must be taken into account.The distributed MAC protocol is adopted in design.During system initialization, the gateway nodes regularly send out a data acquisition command.After receiving an address-matching acquisition command, the acquisition nodes start timer interrupt to regularly collect environmental parameters and send them to the gateway nodes.At the same time, wireless module is set up and carrier sensing is enabled.And AUX status is tested before data packets are sent.Low level indicates that there are carrier signals in the air.To avoid interfering in the signals in the air, a random time delay of 100 ms-500 ms is loaded.After the delay, radio-frequency channel in the air is monitored again and data packets will not be sent until the channel is idle.If AUX is of high level, it means the channel is idle and data packets are sent immediately.The carrier sensing function enables data collision avoidance to some extent, effectively decreases data transmission collisions of nodes, and raises data transmission reliability.

Duplicated Data Filtering and Missing Data On-line Filling
Repetition and missing occur to the acquisition data received by the PC management software of the field monitoring subsystem.For data repetition, a duplicated data filtering method based on time identification is proposed.The time field of the acquired data is compared with that of the latest record of related nodes in the database.If time interval is less than half of the sampling cycle, the acquired data are considered duplicated and are discarded.Therefore, duplicated data are effectively filtered and system reliability is raised.For data missing, a self-decision and on-line filling method is proposed.Estimation strategies are chosen based on the strength of the spatial correction and temporal correlation of the missing data, and weights of the various estimation algorithms are determined based on the principle of minimum sum of squared errors (SSE).Technologies based on multithread programming are used for on-line identification of missing data and the self-decision and on-line filling method is used for missing data estimation and storage in database.Therefore, continuity and integrity of data acquisition by the system are guaranteed and the negative effects of data missing on the follow-up data utilization are reduced.

Multiple Regression Analysis Estimation Based on Spatial Correlation
The strength of the spatial correlation between nodes is decided by the value of the Pearson's correlation coefficient.The larger the absolute value of the coefficient, the stronger the correlation [15].It is generally believed that a coefficient of 0.8-1.0indicates a high correlation.In this study, nodes with a coefficient of larger than 0.8 are chosen to be included in estimation.Regression coefficients β0, …, and βn are solved using the least square method and a regression function ŷi = β0 + β1Y1 + β2Y2 + …… + βnYn is constructed, where Y1, …, and Yn are acquisition values of related nodes in a same sampling cycle and ŷi is the estimated value based on spatial correlation.

Fitting-Interpolation Combinational Algorithm Estimation Based on Temporal Correlation
Essentially, the estimation algorithm based on temporal correlation is an interpolation algorithm.The latest missing data are estimated based on the current acquisition values and historical acquisition values.To fully utilize historical data and current acquired data, missing data are estimated using an interpolation-fitting combinational algorithm.There are many interpolation methods, mainly including the linear interpolation method, the spline interpolation method, the cubic polynomial interpolation method, and the Lagrange's interpolation method.These interpolation methods were used to estimate 100 groups of data records based on the true acquisition data of the system, and methods with the minimum SSE were chosen.The test results showed that when temperature, CO2 concentration and NH3 concentration were estimated using the linear interpolation algorithm and humidity was estimated using the cubic polynomial interpolation algorithm, estimation errors were the smallest.Similarly, when temperature was fitted with a quadratic polynomial and humidity, CO2 concentration and NH3 concentration were fitted with linear functions, estimation errors were the smallest.Finally, weights of estimated values from interpolation algorithms and estimated values from fitting algorithms were determined based on the principle of minimum SSE, and their weighted averages were the estimated values based on spatial correlation.

Algorithm Fusion and Implementation
According to the self-decision and on-line filling method, if there are other nodes that have strong spatial correlation with a parameter of the missing record, the estimated value (ŷi) includes the regression estimated value ŷiA and the interpolation-fitting estimated value ŷiB in the relation of ŷi = αAŷiA + αBŷiB, where αA and αB are weights of corresponding algorithms and αA + αB = 1.SSE of estimation is [16]: y y e e e where eAi and eBi are errors of regression estimation algorithm and interpolation-fitting estimation algorithm at time i, respectively, and N is the number of missing records.When ESS is minimum, αA and αB are the optimal weight values.
e e e then the optimal solution is: , where X = [11].Root mean square error (RMSE) between estimated value and true value is used as the basis for judging the effectiveness of the system estimation algorithms.The smaller the RMSE, the more accurate the estimation method.
where ŷi is system estimation value and yi is system acquisition value.
Separate sub threads are created for the on-line filling of missing data so that the performance of other tasks will not be affected.Time field difference between the record acquired in the current cycle and the latest record of the corresponding node in database is used to judge whether there are data missing.The API function provided by MySQL is used to connect databases.The new time value obtained by subtracting system sampling cycle from system current time is used as the time field of estimation data.After successfully stored, estimation data are saved again in current acquisition data to make sure that the data storage order in database is consistent with the actual acquisition order.

Experimental Conditions
The experimental henhouse was a modern closed henhouse: 88 m long, 8 m wide, 3.7 m high at the eaves and 5 m high at the ridge.The chickens were cage-reared layer upon layer for a total of four layers as is shown in Figure 3.The four racks of cages were arranged back to back into two rows and each cage had six red hair laying hens.

Pilot Run Results
The system was run for 24 consecutive hours.Figure 4 shows the environmental parameter curves for the 24 consecutive hours of a day taking Node 1 as an example.Figure 5 is the operation interface of the field monitoring subsystem which includes functions like system setup, environmental parameter real-time display, overlimit short-message warning, equipment control and database operation.Figure 6 is the Web remote real-time monitoring page of the remote monitoring subsystem.The left half displays intuitively the AJAX real-time updated monitoring data in tables on current henhouse environment.The right half displays the changing trends of the environmental parameters within a time period in real-time curves.Web pages were designed to be self-adaptive so that they can well display even on smart devices with low resolution ratios.Therefore, mobile monitoring of smart devices was realized and the convenience of system operation was raised.

Experimental Methods
Real datasets acquired by the system was tested.A section of consecutive data was chosen.It was assumed that a certain datum was missing, and it was estimated using the self-decision and filling method.Then 100 groups of data were chosen for the evaluation test.The estimated value was compared with the true value to verify the effectiveness of the estimation algorithm.Estimation was performed for temperature, humidity, CO2 concentration and NH3 concentration.Node A was taken as an example, and it was assumed that data missing occurred to Node A. As generally the probability of simultaneous data missing for multiple nodes is small, it was accepted that no data missing occurred to Nodes B and C.

Test results
Figures 7-10 show the estimation results and comparisons between the true data acquired by the system and the estimated values by the several estimation algorithms.As can be seen in Figures 7-10 and Table 1, the self-decision and filling method had lower maximum absolute errors and smaller RMSEs computed using Equation (3) and thus had better estimation effects than any other single estimation algorithm.The test results showed that the self-decision and filling method had better estimation accuracy and met the estimation requirements of temperature, humidity, CO2 concentration and NH3 concentration in henhouses.

Conclusions
(1) In this study, a henhouse environment monitoring system based on IoT was developed according to the environment monitoring and management requirements of henhouses.Reliable monitoring of henhouse temperature, humidity, CO2 concentration and NH3 concentration was realized.
Compared with traditional henhouse environment monitoring systems, the system had such advantages as low packet loss rate, high reliability and easiness in extension.In addition, henhouse environment information was released via the Web and corresponding authorized users can remotely check related information via a browser, which met the requirements of the practical production.(2) Under the condition that the system costs were not raised, data fitting was used for acquisition data compensation and correction based on the features of the sensors.Consequently, the acquisition accuracy of the system was raised.(3) For the packet loss issue of wireless transmission, a data frame transport protocol for closed henhouse environmental parameters was designed based on loss recovery.Reliability of environmental parameter transport was increased and packet loss rate was decreased.In turn, reliable acquisition of environmental parameters was realized and the practicability and reliability of the system were enhanced.(4) For the issue of inevitable loss of close henhouse environment monitoring data, a self-decision and on-line filling method was proposed to comprehensively utilize the temporal-spatial correlations of node data to estimate the missing data.Compared with a single estimation algorithm, this method has higher estimation accuracy.Multithread programming was used to realize the on-line identification and real-time filling of missing data.Consequently, the integrity of system monitoring data was raised.

Figure 2 .
Figure 2. Absolute error curves before and after compensation for the forward path.
/℃ Absolute error of temperature measurement/ ℃ Absolute error curves before compensation for the forward path Absolute error curves after compensation for the forward path

Figure 3 .
Figure 3. Experimentation in a closed poultry house.

Figure 4 .
Figure 4. Environmental parameter variations within a day of Node 1.

Figure 5 .
Figure 5. Operation interface of the field monitoring subsystem.

Figure 6 .
Figure 6.Real time monitoring page.

Figure 7 .
Figure 7.Comparison of the experimental results and the estimated temperature of Node A.

Figure 8 .
Figure 8.Comparison of the experimental results and the estimated humidity of Node A.

Figure 9 .
Figure 9.Comparison of the experimental results and the estimated concentration of CO2 of Node A.

Figure 10 .
Figure 10.Comparison of the experimental results and the estimated concentration of CO2 of Node A.

3
Number of data points NH3 concentration Value/ppmThe value of the collection Self-decision estimate value Linear in terpolation estimate value Linea r fitting estima te valu e

Table 1 .
Comparison of estimation results.