Back
 JCC  Vol.6 No.2 , February 2018
Design and Implementation of Agricultural Information Acquisition System Based on ZigBee and Qt
Abstract: This paper introduces the design and implementation of agricultural products information collection system based on Qt and ZigBee platform. It consists of three subsystems mainly based in acquisition of images, temperature and humidity values which are passed to the regional gateway. The regional gateway is equipped with embedded Linux operating system and deployed Qt runtime library. The function of transmitting the static image of agricultural products and the temperature and humidity to the regional gateway through the ZigBee Wireless Sensor Network is realized, the pH value, electrical conductivity and light intensity of the growth environment of agricultural products were measured by using Qt library combined with sensor cluster, it can store, display and query the image, electrical conductivity and other parameters in the regional gateway.

1. Introduction

With the development of agricultural intelligence, consumers demand for quality of agricultural products is also getting higher and higher, the quality of agricultural products can be judged by the indicators of its growth environment, at present, the detection of agricultural products is mainly limited to the measurement of temperature and humidity, in addition to temperature and humidity, the pH, light intensity and soil conductivity were also measured in the system. More importantly, the image monitoring in the process of agricultural product growth was carried out, this is a big innovation. Through the images of growth of agricultural products, combined with the later digital image processing technology, it can prevent pests and diseases more accurately, and understand the growth of agricultural products [1] .

But traditional image transmission systems are expensive to deploy, and it needs to be energized all the time, it allows the associated devices to operate at high speed and operate in a high power mode, the whole system has great load and high power consumption. Therefore, it is very important to design a low power, security system which is ad hoc network, easy to deploy, and it can transmit images. Taking into account the fixed growing environment of agricultural products, image sampling is only required in a certain period. Therefore, the Wireless Sensor Network can be used to monitor the image of agricultural products and the temperature and humidity parameters. As we know, ZigBee is a wireless communication technology with the characteristics of low power consumption, low rate and ad hoc network, and has been developing rapidly in recent years. It can reduce the size of the Wireless Sensor Networks and reducing power consumption [2] - [9] . According to the above reasons, it is particularly important to design a set of agricultural products information collection system. Therefore, we developed the system with characteristics of stable performance, perfect function and friendly interface based on ZigBee Wireless Sensor Network and Qt graphics library which is crossing platform [10] [11] [12] .

2. Design of Hardware System

The collection system of agricultural products information based on Qt platform and ZigBee technology mainly includes three parts, the system structure is shown in Figure 1. Three main parts are regional gateway, image acquisition subsystem, and the temperature and humidity acquisition subsystem. A regional

Figure 1. System structure diagram.

gateway collects data from 16 temperature and humidity nodes, data from an image acquisition node are also collected. The pH value, electrical conductivity and light intensity were collected by 485 sensor clusters connected with the gateway. The sending module of each subsystem acts as the terminal node (end device) in the ZigBee Wireless Sensor Network, they have high stability. And they are the development platform made up of CC2530 chip as the main controller, this chip is compatible with the IEEE 802.15.4 standard [13] .

2.1. Image Acquisition Subsystem

The image acquisition subsystem includes an image capture module based on the development platform of H3 ARM processor, and sending module based on ZigBee end device, the structure is shown in Figure 2. The image capture module takes pictures according to certain period by controlling the USB camera of model FA CAM202, then compress the image. Considering that the growth image of agricultural products will not be mutated, the frequency of image sampling should not be too frequent, the final period of taking photo is selected for half an hour, and the function of updating the sampling period is provided. You can control the update of the photo cycle through the gateway. The binary data of the picture is sent to the ZigBee end device through the serial port. The end device divides the binary data of the image into several data packets and sends them to the ZigBee coordinator of the regional gateway through the ZigBee Wireless Sensor Network protocol.

2.2. Temperature and Humidity Acquisition Subsystem

This subsystem is mainly responsible for collecting the temperature and humidity data of the growth environment of agricultural products. The system is composed of CC2530 chip as the main controller, and the chip connected with the temperature and humidity sensor named SHT10. The temperature and humidity data are collected and sent through a single bus protocol. The structure diagram is shown in Figure 3. The collected data are analog signals, which need to be converted into digital quantities at the regional gateway.

2.3. Regional Gateway for Wireless Sensor Networks

Regional gateway is the core of agricultural information acquisition system, mainly consists of three parts, they are ZigBee coordinator, embedded Linux & Qt development board based on ARM processor, sensor cluster based on the 485

Figure 2. Image acquisition subsystem.

Figure 3. Temperature and humidity acquisition subsystem.

bus, the structure as shown in Figure 4. The ZigBee coordinator is responsible for the establishment and maintenance of the entire Wireless Sensor Network, and collects wireless data from the ZigBee end devices of subsystems. The coordinator of the system is also a ZigBee development platform using CC2530 chip as the main controller. The sensor cluster based on 485 bus is responsible for collecting environmental parameters such as pH value, electrical conductivity and light intensity. The embedded Linux & Qt platform is responsible for storing and displaying the above data, including images and temperature and humidity and other parameters.

3. Implementation of Software Platform

The agricultural information collection system based on Qt and ZigBee platform adopts the star network structure of ZigBee Wireless Sensor Network to transmit and receive wireless data. Because our information collection area is only 40 square meters, only one gateway and sixteen nodes, we do not need routers, so the use of star network can save hardware cost, and make network management simpler and networking more stable. So we use a star network. The micro controller that runs the ZigBee protocol stack uses the CC2530 chip of TI company, and the compilation of the ZigBee application is completed with the IAR work Suite, including the temperature and humidity collection at the end device, sending of image data, and the receiving of wireless data in Coordinator.

The image acquisition program is completed based on the V4L2 framework under Linux, using the arm-linux-gcc compiler tool chain to compile. While the regional gateway is written in C++ language, based on the Qt platform to complete the coordinator data parsing and processing, to receive data from the 485 bus sensor cluster. Finally, the storage and display of agricultural products information are realized. The compilation relations of each part are summarized as shown in Table 1.

3.1. Image Acquisition and Sending

After the ARM development platform of the image acquisition subsystem obtains the data from the camera according to a certain period, using the JPEG compression algorithm to compress it into JPG format file, it will store the full JPEG format pictures on the local hard disk. Then sending to the ZigBee end device

Figure 4. Structure diagram of regional gateway.

Table 1. The compilation relations of each part.

through the serial port, the end device will divide a full picture into several packets, and the image data is finally sent to coordinator by using ZigBee protocol. The whole software flow chart of the image acquisition subsystem based on ZigBee platform is shown in Figure 5.

The timeout value time 2 is determined according to the IO blocking model of Linux system. Considering the shortest distance of ZigBee transmission is 25 meters and the longest is 100 meters, the timeout value time 2 is 3 seconds. If after three seconds the nodes have not yet received the answer, it means that sending the image data packet is failed. The timeout value time 1 is the period of taking a photo.

Because there’s only one coordinator in an area, but a coordinator has to receive data from 16 temperature and humidity nodes and an image node from the same area, these data are sent asynchronously to the coordinator. When a picture has not been fully received, the coordinator may receive data from the temperature and humidity nodes, therefore, temperature and humidity data and image data need to be distinguished.

In addition, because there are 16 different nodes, it is necessary to distinguish the data of each temperature and humidity node. When sending data to coordinator, these subsystems need to define a set of communication protocol based on Qt and ZigBee platform for agricultural product information acquisition system, an 8 bytes protocol header is packaged in front of each payload of the ZigBee packet to distinguish the data type and the node number. So the specific format of each ZigBee packet is shown in Table 2. The specific meaning of each domain

Figure 5. Software flowchart of image acquisition subsystem.

Table 2. ZigBee packet format.

of the ZigBee packet is described in detail, as shown in Table 3.

As a result of the ZigBee protocol, the maximum payload length of each packet in ZigBee is 75 bytes. And because we need to take up 8 bytes of the protocol header in the payload, the maximum length of valid data in the payload is 67 bytes. In order to achieve byte alignment of memory in ZigBee development platform, in the end, the maximum effective data length of a packet is 64 bytes.

In order to avoid packet loss and packet overload caused by blocking of the gateway, it is necessary to indicate the current packet number in all packets.

Table 3. The specific meaning of each domain of ZigBee packet.

After receiving the wireless data of the end device, the coordinator of the regional gateway determines whether the data packet is a legitimate packet according to the Sequence field, it determines whether or not to send feedback signals to the end device according to this. The end device has not received the feedback signal within the specified time, indicating the packet loss event, it sends the last packet repeatedly until it receives the coordinator’s feedback signal to start sending the next packet.

3.2. Temperature and Humidity Acquisition

The software implementation of the temperature acquisition subsystem and the image acquisition subsystem are approximately the same, and relatively simpler. Because the temperature and humidity data can be sent only with one packet, this is different from the image data which needs to be segmented into multiple packets and sent successively.

The ZigBee packet format sent by the temperature and humidity acquisition subsystem is exactly the same as the ZigBee packet format of the image acquisition subsystem, but only 4 bytes are fixed in the last Available data domain, the first two bytes represent the humidity, and the last two bytes indicate the temperature. The amount of data is far less than the image data, but each temperature and humidity node’s sequence number is not the same, this manifest in each node has its own ID field, it is used to distinguish temperature and humidity from different nodes.

The CC2530 chip collects data of temperature and humidity sensor according to certain period. It is packaged in accordance with the agreed protocol format and sent to the coordinator. Then wait for the coordinator feedback signal, if not received the feedback signal, indicating that the packet loss event, recollect a temperature and humidity data, pack and send, until the received feedback signal. If the feedback signal is successfully received, the acquisition activity will be carried out in the next cycle. The specific software flow chart is shown in Figure 6. The time 1 is the 15 period of temperature and humidity acquisition, it is 15 minutes. The time 2 is the same as in Figure 5, it is 3 seconds.

3.3. Design and Implementation of Gateway’s Software

The gateway of agricultural products information collection system based on Qt

Figure 6. Software flowchart of temperature and humidity acquisition subsystem.

and ZigBee platform collects data from image and temperature and humidity collection subsystem, it also collects environmental parameters such as pH value, light intensity and electrical conductivity of agricultural products. And it also stores and displays all the above data. Considering that UI display and data processing share a thread will block, in order to improve the real-time performance of the system and touch screen response speed, so the regional gateway uses multi-threaded software architecture.

The UI thread shows pictures and parameters such as temperature and humidity, and it acts as the main thread, which is responsible for the interface rendering. There are also two sub threads, one is coordinator sub thread for obtaining image and temperature and humidity data, it communicates with ZigBee Coordinator through UART 232 protocol. The software flow chart is summarized as shown in Figure 7.

The whole gateway is designed and implemented based on Qt 5.7 version of open source cross platform graphics library, Qt 5.7 provides the QSerialPort module, which makes it possible to read the UART serial port or USB to the serial port directly through the Qt library, so that the ZigBee coordinator can be used to communicate with the gateway through serial port. At the same time, it open the source of QCharts module, so, we can draw beautiful icon view, it

Figure 7. Flowchart of regional gateway software.

provides a good platform guarantee for the data display of pH value and other 485 bus sensors.

The coordinator sub thread uses the QSerialPort module to complete the communication between the gateway and coordinator. According to a certain period of polling, scanning the device file of ZigBee coordinator serial port, when there is data readable, in accordance with a certain order to read the serial data. First read the fixed length protocol header, the specific format has been described in Table 2 above.

Then parse the protocol header to get the data type, if it is temperature and humidity data, notify the main thread directly to update the UI interface. If it is image data, all valid data packets will be combined into a complete JPG picture, and then notify the main thread to update the UI interface.

The 485 bus of the regional gateway integrates three sensors, includes pH sensor, light intensity sensor and conductivity sensor. They have different device addresses on the 485 bus, the gateway only needs to specify the corresponding device address according to the 485 protocol, and the corresponding command can obtain the required data from the specified sensor. The address of the three sensors on the 485 bus is shown in Table 4.

The regional gateway reads the 485 bus sensor cluster according to a certain period, reads the pH value, the light intensity, and finally the conductivity [14] [15] . The commands to read the pH value are 8 bytes, and the specific format is shown in Table 5, the command format for reading light intensity is shown in Table 6, and the command format for reading electrical conductivity is shown in Table 7.

After successful acquisition of the above parameters, the child thread through the signal and slot mechanism, notify the main thread updates the UI interface, showing a new pH, light intensity and conductivity. The 485 bus sub thread also uses the QSerialPort module to complete the communication between gateway

Table 4. Check list of this devices on the 485 bus.

Table 5. pH reading command.

Table 6. Reading command for light intensity.

Table 7. Reading command of conductivity.

and the 485 bus sensor.

After collecting the data of temperature and humidity, we also need to display this data in the regional gateway, so as to realize this functions, includes browsing pictures, observing the change of 485 bus sensor parameters such as pH value and observing the real time temperature and humidity. Therefore, it is necessary to use a separate master thread to implement the rendering function of the UI interface.

In order to facilitate the use of agricultural products management personnel, UI main thread also implements a system login interface, to ensure the safe use of the system, only a specific manager can login to use the information acquisition system, the specific interface as shown in Figure 8.

Picture browsing is mainly to browse the pictures with JPG format in the application’s work directory, these images are collected from the image nodes through the ZigBee Wireless Sensor Network. This section uses the model view framework of the Qt platform, it uses QString List Model and QSort Filter Proxy Model as models and uses QList View as a view, so as to achieve the function, includes reading and filtering the file list of pictures. The specific effect is shown in Figure 9.

The temperature and humidity data of the 16 nodes do not make historical records, so the real-time temperature and humidity data of the 16 nodes are only displayed. Through the custom widget, the realization of the thermometer and humidity instrument panel drawing, and rewrite the mouse Press Event function, to achieve the click of the corresponding node, zoom in the animation function of the corresponding widget. If some nodes are dropped and they are

Figure 8. System login interface.

Figure 9. Image browsing interface.

not in the ZigBee PAN, the corresponding nodes begin flashing by changing the background color of the widget, reminding the administrator that there are some nodes are off-line. The specific effect is shown in Figure 10.

For the display of 485 bus sensor data, the QCharts module provided by Qt 5.7 is utilized, the model view function is used at the same time. And through the mapping relationship between model and coordinate view, a model is used to complete the data association of multiple views. Since the sampling period is 5 seconds, the time is displayed in the format of “sub:seconds” in multiple views. The specific effect is shown from Figures 11-13.

In order to protect electrical conductivity sensors, we only wrapped the sensors in plastic bags, similar to insulation, so the values measured by electrical conductivity were only 0 and 2.

Figure 10. Real time temperature and humidity data display interface.

Figure 11. pH display interface.

Figure 12. Light intensity display interface.

Figure 13. Conductivity display interface.

4. Conclusions

The agricultural product information collection system based on Qt and ZigBee platform completed by this paper through the V4L2 Linux framework to complete the acquisition of agricultural products image, and through the libjpeg library to achieve image compression, generating jpg format quality images stored in the local image acquisition subsystem’s hard drive, and custom data transfer protocol through the ZigBee wireless sensor network image data sent to the coordinator. In the regional gateway using Qt platform QSerialPort module to achieve and coordinator and 485 bus sensor communication capabilities to complete the collection of agricultural products information. And the Qt platform provides a model view framework and QCharts module to design and implement a friendly human-computer interaction to achieve the functions of picture browsing, temperature and humidity, pH value, light intensity and conductivity history query. Finally, an innovative system for the stable and reliable transmission of agricultural product information based on ZigBee wireless sensor network is realized.

The present system is limited to the implementation of the Agricultural Information Acquisition. In future we can improve the system by implementing your design on mobile surveillance platforms and making it more intelligence to automatic control relevant factors. For example, uploading the data uploaded by the gateway to the Internet server, then pushing it to the mobile client, and sending data and commands to the gateway through the mobile client, controlling the sampling period and other parameters.

Acknowledgements

This work was partially supported by the National Nature Science Foundation of China (No. 61771262) and by Tianjin Key Laboratory of Optoelectronic Sensor and Sensing Network Technology.

Cite this paper: Sun, G. , Liu, Z. , Du, Y. and Guo, X. (2018) Design and Implementation of Agricultural Information Acquisition System Based on ZigBee and Qt. Journal of Computer and Communications, 6, 13-26. doi: 10.4236/jcc.2018.62002.
References

[1]   Ojha, T., Misra, S. and Raghuwanshi, N.S. (2015) Wireless Sensor Networks for Agriculture: The State-of-the-Art in Practice and Future Challenges. Computers & Electronics in Agriculture, 118, 66-84.
https://doi.org/10.1016/j.compag.2015.08.011

[2]   Zhao, Z., Lee, W.C., Shin, Y. and Song, K. (2013) An Optimal Power Scheduling Method for Demand Response in Home Energy Management System. IEEE Transactions on Smart Grid, 4, 1391-1400.
http://doi.org/10.1109/TSG.2013.2251018

[3]   Li, J., Zhu, X., Tang, N., et al. (2010) Study on ZigBee Network Architecture and Routing Algorithm. International Conference on Signal Processing Systems, Dalian, 5-7 July 2010, 389-393.
https://doi.org/10.1109/icsps.2010.5555486.

[4]   White, C.B. (2012) Critical EMC Test Issues Needing Early Resolution. IEEE International Symposium on Electromagnetic Compatibility, Pittsburgh, 6-10 August 2012, 127-131.
http://doi.org/10.1109/ISEMC.2012.6351797

[5]   Zheng, L. (2006) ZigBee Wireless Sensor Network in Industrial Applications. SICE-ICASE International Joint Conference, Busan, 18-21 October 2006, 1067-1069.
https://doi.org/10.1109/SICE.2006.315751

[6]   Farahani, S. (2008) ZigBee Wireless Networks and Transceivers. Newnes, Oxford.

[7]   Yen, L.-H. and Tsai, W.-T. (2010) The Room Shortage Problem of Tree-Based ZigBee/IEEE 802.15.4 Wireless Networks. Computer Communications, 33, 454-460.
https://doi.org/10.1016/j.comcom.2009.10.013

[8]   Portilla, J., de Castro, A., de la Torre, E. and Riesgo, T. (2006) A Modular Architecture for Nodes in Wireless Sensor Networks. Journal of Universal Computer Science, 12, 328-339.

[9]   Yu, X., Wu, P., Han, W., et al. (2013) A Survey on Wireless Sensor Network Infrastructure for Agriculture. Computer Standards & Interfaces, 35, 59-64.
https://doi.org/10.1016/j.csi.2012.05.0019

[10]   Liu, H.D., Rui, J.W., Yao, Y.D. and Wu, J. (2006) Design and Implementation of Internationalized Graphical User Interface Based on Qt. Journal of Chinese Information Processing, 20, 95-99.

[11]   Liu, Z.R., Chang, C.C. and Xu, S. (2004) Embedded Linux Application and Development Solutions. Mechanical Industry Press, Beijing, 2004.

[12]   Qt for Embedded Linux.
http://doc.qt.io/qt-5/embedded-linux.html

[13]   Baronti, P., Pillai, P., Chook, V.W.C., Chessa, S., Gotta, A. and Hu, Y.F. (2007) Wireless Sensor Networks: A Survey on the State of the Art and the 802.15.4 and ZigBee Standards. Computer Communications, 30, 1655-1695.
https://doi.org/10.1016/j.comcom.2006.12.020

[14]   Mauerer, W. (2008) Professional Linux Kernel Architecture. Wiley Publishing, Inc., Indianapolis, IN.

[15]   Corbet, J. and Bubini, A. (2005) Linux Device Drivers. 3rd Edition, Oreilly & Associates Inc., Sebastopol, CA.

 
 
Top