Remote and Real-time Monitoring System for Indoor Environment Based on ZigBee and LabVIEW

1State Key Laboratory of Mechanical Manufacturing Systems Engineering, Xi'an Jiaotong University, Beilin district, Xi'an, 710049, China 2School of Architecture, Xi'an University of Architecture and Technology, Yanta district, Xi'an, 710055, China 3Institute of Heritage Sites & Historical Architecture Conservation, Xi'an Jiaotong University, Beilin district, Xi'an, 710049, China 4Collaborative Innovation Center of High-End Manufacturing Equipment, Xi'an Jiaotong University, Qujiang new district, Xi'an, 710054, China 5Xi'an Jiaotong University Suzhou Institute, Industrial park, Suzhou, 215123, China 6State Key Laboratory of Mechanical System and Vibration, Shanghai Jiaotong University, Minhang district, Shanghai, 200240, China


Introduction
With the progress of society and the need for environmental protection, the role and importance of environmental monitoring have become increasingly prominent. In particular, the rapid development of sensors for real-time environmental monitoring in recent years has also put forward higher requirements for real-time environmental monitoring technology, such as lower cost, remote monitoring technology, and smaller hardware size. For example, Korostynska et al. have reported a novel electromagnetic sensor for real-time environmental monitoring, which realizes the electromagnetic wave sensing of NO 3 and chemical oxygen demand (COD) concentrations. (1) Kayed et al. have proposed a new temperature transducer using a full-circular n-type piezoresistor over the (111) silicon plane as an accurate solution for real-time temperature compensation. (2) Therefore, to maximize the role of these new sensors, research on remote and real-time environmental monitoring systems with excellent performance is of great importance.
Currently, the wireless communication technologies that are common in the Internet of Things are WiFi, Bluetooth, UWB, IrDA, NFC, ZigBee, and so forth. (3) Each communication protocol has its own characteristics, which are applicable to different occasions. Among them, ZigBee mainly has the advantages of low power dissipation, low complexity, low drop rate, high reliability, high security, strong networking capability, low cost, and so forth, and it has been widely used in many fields such as medicine, (4,5) agriculture, (6,7) smart home, (8,9) and intelligent control. (10,11) Moreover, in the field of environmental monitoring, ZigBee technology is also widely used. Other researchers have carried out much research on the field applications of ZigBee. For example, Bamodu et al. (12) and Tzeng et al. (13) have separately proposed an indoor environment monitoring system based on ZigBee technology. They have implemented sensor network systems with low cost and low power consumption, but the hardware size of the former is too large and the latter monitoring software functions only for data storage. Furthermore, neither of them possesses a design of the package structure. Teng et al. have proposed an indoor environment measurement system that includes a ZigBee star network as the core and sensor technology as the base. (14) However, the central node of the star topology is overburdened. Once it fails, the entire network is affected, and the security of the network system becomes compromised. He et al. have also developed an indoor environment monitoring system based on ZigBee to realize the indoor environment automatic monitoring. An actual test showed that the system is stable and reliable, but it cannot resist interference from other ZigBee networks. (15) Huang et al. have proposed an Air-Sense system that utilizes the platform of a ZigBee network to collect and detect indoor environment quality in real time. (16) However, the function of the monitoring software is too simple, and there is no package structure design. Lin et al. have designed and realized a multisensor and multinode environmental monitoring system for the interior and exterior of ancient buildings on the basis of ZigBee, TCP/IP, and intranet penetration technologies. The monitoring system is stable and reliable by monitoring the indoor and outdoor environmental information of actual ancient buildings. (17) With the continuous development and wide applications of ZigBee technology, higher requirements are placed on the integration and scalability of the monitoring node module and package design. Moreover, the anti-interference design is also an urgent problem that should be solved, especially one that can prevent interference from other ZigBee networks in the surrounding area.
On the other hand, remote communication technology has an incomparable advantage in practical applications because it can realize the remote transmission of data. In the field of environmental monitoring, if remote communication can be implemented, the monitored environmental parameters can be remotely transmitted in real time. Particularly for environmental monitoring in remote areas, it can effectively reduce monitoring costs and optimize resource allocation. However, most of the current solutions for implementing remote monitoring technologies, such as renting servers and base stations, (18)(19)(20)(21)(22) have some problems such as high operating cost, high complexity, poor extensibility, and management difficulty.
Considering cost, anti-interference, integration, and reliability, and from the perspectives of package design, node module design, network construction, and remote monitoring platform design, we designed and implemented a remote online monitoring system for indoor environment monitoring in this study, which has the characteristics of low cost, strong antiinterference, small size, high integration, and so forth. The remote monitoring of environmental parameters including temperature, relative humidity, fine particle (PM2.5) concentration, carbon dioxide concentration, vibration intensity, and concentrations of harmful gases (hydrogen, liquefied gas, etc.), can be achieved at any location via software.

Wireless sensor network
In this study, ZigBee is adopted as the communication protocol of this system. The structure of the ZigBee protocol is shown in Fig.1. A hierarchical structure is used in the ZigBee protocol, and service access points are used to implement protocol stack management and data communication between layers. There are usually two service access points between two layers, one providing data transfer services and the other implementing management to provide all other services. The ZigBee protocol is based on the IEEE 802.15.4 standard and has additional routing and networking capabilities. In addition, compared with the IEEE 802.15.4 network standard, ZigBee has the advantages of lower bandwidth, higher latency, and an asynchronous protocol. (23) The network structure constructed in this system is a tree topology, which is a collection of multiple star topologies. As shown in Fig. 2, the tree topology consists of a coordinator,  multiple routers, and multiple terminal nodes. The tree topology is a multi-hop network. The collected data are transmitted by terminal nodes to the routers on their corresponding subnets, and then aggregated to the coordinator via the multi-hop network, and finally uploaded to the monitoring platform. Compared with the mesh topology, the structure of the tree topology is simpler and more suitable for applications with small data volume and low transmission rate.
There are three types of node module in the system, namely, terminal node module, router, and coordinator. They are exactly the same in terms of hardware, but have different functions because of their different codes. The structure of the monitoring system is shown in Fig. 3. The terminal node is responsible for collecting environmental data and transmitting it to routers, and the transmission distance can be greatly expanded by the routers. Finally, the data received by the routers can be transmitted to the monitoring platform by the coordinator through USB to a serial port. The overall layout of the system is shown in Fig. 4. In this figure, "other node modules" refer to the coordinator, routers, or terminal node modules in other surrounding ZigBee networks. Their functions in the respective network systems are the same as those of the node modules in this system. Therefore, the anti-interference design for other ZigBee networks should be carried out to prevent the impact of other ZigBee networks on this network system.
The multicast communication technology is used to construct the ZigBee network. During data transmission, the node modules can be grouped and marked, and only those with the  same group number can communicate with each other. This type of network is not affected by other ZigBee networks in the surrounding area and can work stably on its own, which greatly improves the system's stability and reliability. As for the process of networking, after each network node is powered on, a network connection is initiated and established by the coordinator, and other nodes will automatically join this network. Moreover, the router can only join the network through the coordinator. However, the terminal node can join the network either through the router or the coordinator.

Node module design
For a wireless sensor network, the node module is the core component, which controls the collection of environmental data by each sensor module, and can also realize serial communication with the monitoring platform. On the basis of CC2530, the node module that is highly integrated with the functions of the controller module and the wireless communication module is designed in this study. In addition, the current-limiting resistance and serial interface circuit are designed on the back of the node module to make the structure more compact and easier to install. The sensor interface used in this node module is the serial UART. Moreover, the signal form output by the sensor module is a digital or analog signal. The circuit schematic of the node module is shown in Fig. 5.
The node module designed is shown in Fig. 6, and its size is 4.5 × 4.5 cm 2 . The main interfaces of this node module and their respective functions are as follows: (1) Battery interface: connects with the battery to provide power supply; (2) USB interface: provides power supply, especially for the coordinator; this interface is a USB serial communication interface; (3) Sensor interface: provides connection interfaces for air temperature, relative humidity, PM2.5 concentration, carbon dioxide concentration, vibration intensity, and harmful gas concentration sensors; (4) Expansion interface: includes three 3.3 V power interfaces, three GND interfaces, and three 5 V power interfaces, and enables the expansion of other sensors later; (5) Antenna interface: connects with the antenna to increase signal strength and transmission distance; (6) Debug interface: realizes online simulation, debugging, and downloading of programs; (7) Indicator light: directly displays the networking status of the node module.

Package design
The carbon dioxide concentration sensor used in this system is MH-Z19B, manufactured by China Weisheng Electronic Technology Co. Ltd., which has an operating temperature of 0-50 ℃ and an operating humidity of 0-95% with a measurement range of 0-2000 ppm and an accuracy of ±50 ppm. The PM2.5 sensor used in this system is GP2Y1014AU0F and from China Shuaineng Technology Co. Ltd. This sensor is small, light, low in power consumption, and easy to install, and the minimum particle size that it can detect is 0.8 μm, which can meet the needs of indoor environmental monitoring. The temperature and relative humidity sensor is DHT11 from China Beike Trading Co. Ltd. It has many advantages such as its compactness, simple interface, fast response, and low cost. Moreover, its temperature and relative humidity ranges are 0-50 ℃ and 20-95% with precisions of ±2 ℃ and ±5%, respectively. The vibration intensity sensor is SW-1801P from China Beike Trading Co. Ltd., which outputs a switch signal. An open circuit may occur in the static state of the sensor. However, when a vibration caused by an external force occurs, the circuit of the sensor will be turned on instantaneously. If the external force disappears, the circuit will return to the open state. Furthermore, the harmful gas sensor is MQ-2 also from China Beike Trading Co. Ltd. Stannic oxide is used as the gassensitive material in this sensor. The main harmful gases, such as hydrogen, methane, propane, and natural gas, are monitored. The switch signal is also output by this sensor.
On the basis of 3D printing technology, an indoor package device that can meet the functional requirements of the node module and each sensor module is designed and fabricated, and the material used is a photosensitive resin. As shown in Fig. 7, this structure is small and light. The overall structure size is 12 × 10 × 5 cm 3 , and the weight is about 60.9 g, which is beneficial for its movement and installation. Moreover, this package box can be placed in a corner because of its square design, which can effectively reduce the space occupied indoors.
Owing to the variety of sensors used in this system, this package structure is modularized to isolate each sensor module, thereby eliminating the problem of wire-to-wire entanglement between different sensors. If the monitoring node module breaks down, it is also easy for users to troubleshoot problems. The thickness of the package is only 1 mm, which can not only effectively reduce the overall weight, but also improve the efficiency of 3D printing. Furthermore, many fixed blocks are also designed on the cover of the package to solve the problem of bending deformation due to the thin wall.
For the power supply of the node module, this system adopts two forms: battery power supply and constant voltage source. Under normal circumstances, a constant voltage source is used for power supply by USB. However, in special cases such as power outages, a battery is used to supply power. Thus, on the basis of the requirements of battery power supply, as shown in Fig. 8, the fixed structure of the battery box is designed at the bottom of the package without taking up extra space. This fixed structure is a double U-shaped structure with high practicability and low cost.

Software Algorithm
On the basis of the graphical design language of LabVIEW, this system builds an online monitoring platform that realizes functions such as data collection and storage, real-time display, over-the-limit warning, and remote communication. The monitoring platform is shown in Fig. 9, and the interface between the remote monitoring platform and the local monitoring platform is the same. Besides, the environmental data can be viewed through a remote monitoring platform without additional device support, which is not restricted by location.

Data collection
In the program chart of data collection, as shown in Fig. 10, the serial port is initialized by configuring the baud rate, data bits, parity bits, stop bits, control bits, and other parameters. Then, in accordance with the serial communication protocol, data are transmitted from the coordinator to realize data collection of environmental parameters, such as air temperature, relative humidity, carbon dioxide concentration, and so forth. The collected data are stored in queues named "DATA1" and "DATA2". The data of the "DATA1" queue are provided to the data display module, and the data of the "DATA2" queue are provided to the remote communication module.

Data display
As shown in Fig. 11, in the data display module, the data information stored in the "DATA1" queue is extracted and then converted into strings for node judgment. Next, these data enter the loop structure, and string interception and data are displayed through string processing sub-VI ( ).
As shown in Fig. 12, the filtering algorithm, data storage, and over-the-limit warning modules are included in string processing sub-VI. Owing to the long-term and continuous operation of this system, a large mutation may occur in the collected data because of external interference. Furthermore, false warning of the monitoring platform may occur. To solve this problem, the filtering algorithm is designed. The basic principle is as follows. For each parameter of any node, if C is exceeded by the absolute value of the difference between A and B, A is wrong and replaced by B. That is, the obvious error data will be automatically deleted before the data are displayed on the monitoring platform, which prevents the false warning phenomenon.
, , Here, A is the current value, B is the previous value, and C is the preset value.
Moreover, monitoring data can be saved in a local folder in the form of Technical Data Management Streaming (TDMS) format by a data storage program. As shown in Fig. 12, when the monitoring software is running, the data are automatically saved in a folder called "data storage". If the parameter value exceeds the upper limit or is lower than the lower limit, the input of this Boolean control will become "True" and the alarm switch will also be turned on.

Remote communication
LabVIEW has the powerful function of network communication, and the TCP/IP protocol is also used in this system to implement remote communication. Both sides of remote communication are divided into the "sender" and "receiver". The "sender" is located on the remote monitoring platform, and the "receiver" is on the local monitoring platform. The monitored environmental data are displayed on not only the remote monitoring platform, but also the local monitoring platform. Finally, the remote communication is realized by the functions of the software.
The TCP listening function is used by the "sender" and the listening port is "xxxx". If the communication request made by the "receiver" is accepted, the main loop can be entered to  transfer data from the "DATA2" queue to the "receiver". The program chart of the "sender" is shown in Fig. 13.
The program chart of the "receiver" is shown in Fig. 14. The IP address of "xxx.xxx. xx.xxx" (public network IP of the local router) and the port "xxxx" are written in the function to send a communication request. Once the remote communication is successfully connected, the monitored data will be stored in the "DATA" queue of the "receiver". Finally, it is further transmitted to the data display module of the remote monitoring platform.

Alarm display
As shown in Fig. 15(a), when the monitored environmental parameter value exceeds the upper limit value, the color of the warning indicator will change from green to red, and it also makes an alarm sound "ding, ding, ding". At the same time, the monitoring interface also automatically displays a help information interface, which shows alarm information to help the user handle the alarm correctly. Each environmental parameter has its own different help information interface. The program chart of the alarm display is shown in Fig. 15(b).

Results and Data Analysis
In this study, two indoor rooms are monitored for six months, and the environmental data monitored in each room are also processed and analyzed, mainly in the form of monthly averages. The two rooms are similar but in different locations. Room 1 is used for the daily work and study of graduate students. The space of the room (overall size is 6.7 × 5.8 × 3.3 m 3 ) is relatively large. However, there are only four graduate students. Room 2 is of the same size as Room 1, but a large device that is usually used by graduate students in their experiments is stored in it. Owing to the performance limitations of the device, it can be used by only up to two people at the same time, which means that there are no more than two people in Room 2 in most instances. Carbon dioxide is a nontoxic gas, but people's health can be harmed when its concentration is too high. The relationship between different concentrations of carbon dioxide and air quality is shown in Table 1.
As shown in Fig. 16, the monthly mean carbon dioxide concentrations in Room 1 are 480.0, 507.2, 516.2, 589.4, 555.7, and 549.0 ppm, and the average concentration for six months is 532.9 ppm. From Table 1, the air quality in Room 2 is determined to be excellent, and the air is fresh and comfortable to breathe. The monthly mean carbon dioxide concentrations in Room 2 are 393.6, 391.4, 395.2, 415.5, 417.8, and 434.6 ppm, and the average concentration for six months is 408.0 ppm. It can be seen from Table 1 that the air quality of Room 1 is excellent in terms of carbon dioxide concentration, which is equivalent to the general outdoor environment and is not harmful to people's health.
In general, the indoor concentration of carbon dioxide monitored in this study is normal and the fluctuation is small, which means that the flow of people is not large, and the air circulation is also good. Moreover, Room 1 has a slightly higher concentration of carbon dioxide than Room 2, which shows that the flow of people is slightly larger in Room 1 than in Room 2. These findings are in line with the actual situation of Rooms 1 and 2.
As shown in Fig. 17, the monthly mean PM2.5 concentrations in Room 1 are 51.1, 48.6, 44.0, 45.5, 51.5, and 57.3 ppm, and the average concentration for six months is 49.7 ppm. As shown in Table 2, the air quality of Room 1 is good. The monthly mean concentrations in Room 2 are   The same as the general outdoor environment.

< CO 2 ≤ 1000
The air is clean and comfortable to breath. People can live and work normally The air is turbid and makes people sleepy. If this condition lasts for a long time, people's work efficiency will decrease.

< CO 2 ≤ 5000
People will have some symptoms such as headaches, lethargy, sluggishness, rapid heartbeat, and mild nausea.

< CO 2
The condition may cause severe hypoxia, permanent brain damage, coma, and even death.
43.5, 43.0, 45.1, 47.1, 44.2, and 43.0 ppm, and the average concentration for six months is 44.3 ppm. Thus, the air quality in Room 2 is also good. In general, the PM2.5 concentrations in the two indoor rooms are relatively stable and low, which indicates that the indoor air quality is good and suitable for people to live and work. However, the PM2.5 concentration is slightly higher in Room 1 than in Room 2, which is related to the larger flow of people in Room 1.
As shown in Fig. 18, the monthly mean temperatures in Room 1 are 21.7, 21.7, 20.9, 21.2, 21.0, and 20.1 ℃, and the average temperature for six months is 21.1 ℃. The monthly mean temperatures in Room 2 are 18.0, 17.6, 18.2, 17.4, 17.5, and 19.2 ℃, and the average temperature for six months is 19.2 ℃. The average temperature of Room 2 is slightly lower than that of Room 1, which is consistent with the actual situation. Because Room 1 is used as a place for graduate students to work and study daily, its frequency of use is higher than that of Room 2. Therefore, the average temperature of Room 1 is higher than that of Room 2 because of the use of central air conditioning. However, in general, the temperature fluctuations of the two rooms are very small. In addition, the graph of the monthly mean relative humidities in Rooms 1 and 2 within half a year is shown in Fig. 19, the monthly mean relative humidities in Room 1 are 43.5, 28.6, 29.6, 29.4, 42.8, and 44.3%, and the average relative humidity for six months is 36.4%. Moreover, the monthly mean relative humidities in Room 2 are 51.9, 31.8, 33.1, 29.0, 33.8, and 46.4%, and the average relative humidity for six months is 37.7%. The overall trends of relative humidity in Rooms 1 and 2 are similar, it initially decreases, and then increases. This is consistent with local seasonal changes because the air is drier in winter.
The difference between the trends of temperature and relative humidity is so great because of the use of central air-conditioning in the room. The central air conditioner can only regulate the temperature, and the relative humidity in the room is mainly affected by the external environment.
For Room 1, if harmful gases are detected, the number 0 is output; otherwise, the number 1 is output. The setting of the vibration sensor is opposite to that of the harmful gas sensor. If a vibration phenomenon is detected, the number 1 is output; otherwise, the number 0 is output. The settings of the vibration sensor and harmful gas sensor in Room 2 are opposite to those in Room 1. As shown in Fig. 20, the signals output by the harmful gas sensors in Rooms 1 and 2 are all numbers 1 and 0, respectively, which indicate that no harmful gases are detected in the two indoor rooms. On the other hand, the signals output by the vibration sensors in Rooms 1 and 2 are all numbers 0 and 1, respectively, which indicate that no vibration phenomena is detected in the two indoor rooms. This is also consistent with the actual situation.    In short, by analyzing the environmental data monitored for half a year of the two indoor rooms, we can see that both the indoor carbon dioxide and PM2.5 concentrations are normal, and the temperature fluctuation is also not obvious, which indicates that the current indoor environment is suitable for people to live and work. However, the relative humidity is significantly lower in December, January, and February than in other months, indicating that the air in the room is relatively dry during these three months. On the basis of this data analysis, it is recommended to use a humidifier or central air conditioning with a humidity controller to adjust the indoor humidity. Moreover, by specific data analysis, we can also see that the carbon dioxide concentration, air temperature, and PM2.5 concentration are slightly higher in Room 1 than in Room 2, which is because the flow of people and frequency of use are slightly higher in Room 1 than in Room 2. Comparison of the data analysis with the actual situation shows that the results monitored by the system are correct, which further illustrates the stability and reliability of the monitoring system.

Discussion
Through the comparative analysis of the monitored data and the actual situation, it was shown that this system has high reliability and stability. Regarding the anti-interference, especially for other ZigBee networks, the high reliability and stability of the system are further verified through experiments. For the anti-interference for the ZigBee multicast network, the specific experimental process is divided into two parts. First, in a single multicast network, let one node cyclically send a random data packet to another node. The packet length is 100 bytes and the number of transmissions is 2000. The packet loss rate and packet error rate are calculated using the upper computer software. At the same time, the communication distance is continuously increased. However, since the environment monitoring is carried out in an indoor room (overall size is 6.7 × 5.8 × 3.3 m 3 ), the maximum communication distance that we tested is 25 m, which fully meets the application requirements. Then, after introducing other ZigBee networks, the packet loss rate and packet error rate are also measured by the same method.
The communication test results are shown in Table 3. When the communication distances are 5 and 15 m, the test results in the two scenarios are very good, and the packet loss rate and packet error rate are both zero. However, when the communication distance is 25 m, in a single multicast network, the packet loss rate is 0.05% and the packet error rate is zero. After introducing other ZigBee networks, the packet loss rate and packet error rate are 0.1 and 0.05%, respectively. It can be seen from the test results that the ZigBee technology is very stable and reliable in short-range communication. Moreover, the comparison of communication test results in two cases showed that the anti-interference and stability of multicast network communication are also excellent.
In general, the different locations of nodes can have an impact on the wireless communication network. However, because the ZigBee network has the characteristic of an ad-hoc network, it is unaffected by the initial node location, especially in short-range communication. In addition, during the operation of the network, individual network nodes are temporarily separated from the network, as shown by viewing historical data records. However, after some time, the node that is out of the network can automatically resume communication and rejoin the network. Therefore, although the link may be interrupted owing to the effect of the physical environment, the node can automatically rejoin the network, which indicates that the network has a certain robustness. In addition, it is also necessary to pay attention to the fact that the monitoring platform will run more slowly. The most intuitive manifestation is that the data display takes longer. A possible factor contributing to this phenomenon is that functions such as "open data file" and "serial port initialization" are placed in the loop diagram. If these operations are put in a loop, the software will continue to apply for new resources. Therefore, the running speed will decrease. In brief, creating a connection or hardware initialization requires the application of memory resources to the system, and closing the connection allows the system to release these resources. Thus, it can be solved by adding the "close data file" function in a loop diagram and putting the "serial port initialization" function outside the loop diagram.

Conclusion and Future Work
In summary, on the basis of ZigBee technology, a remote indoor environment monitoring system is designed and implemented. Besides, multicast technology is used to ensure that the network is not interfered by other ZigBee networks and can work normally in complex network environments. Moreover, a remote online monitoring platform with functions of real-time display, storage, and over-the-limit warning is designed on the basis of LabVIEW and TCP/ IP protocol. The monitoring node module is also designed and completed on the basis of the CC2530 chip. The double-sided structure design makes the node module have the advantages of having a compact layout and complete functions, and the size is only 4.5 × 4.5 cm 2 . The packaging device for installing the node module and each sensor module is also designed and manufactured and has the characteristics of being small and light, which are beneficial for saving space in a room. Its overall size is 12 × 10 × 5 cm 3 , and its weight is 60.9 g. Finally, the environmental data of the monitored room are analyzed. It is found that the air quality of the two rooms is good and the temperature fluctuation is also relatively small, which is suitable for people to work and live. However, there is a marked decrease in relative humidity in winter, indicating that the indoor air was relatively dry at that time. On the basis of this situation, a corresponding solution is also suggested. Owing to the limitations of the performance of the sensor itself, the concentrations of specific harmful gases and vibration parameters are not detected in this system. On the monitoring platform, the concentrations of harmful gases and vibration parameters can only be set to the over-the-limit warning function without a specific numerical display. Next, we will use high-precision sensors of harmful gases and vibration to obtain more accurate monitoring data. Moreover, we will consider combining wireless sensing technology and building information modeling (BIM) technology to build a visual monitoring platform to better achieve environmental monitoring in the future. Shaobo Ning graduated from Xi'an Academy of Fine Arts with a bachelorʼs degree in arts and graduated from Xi'an University of Architecture and Technology with a masterʼs degree in landscape architecture. He is currently studying for a doctorate degree in human settlements environmental science at Xi'an Jiaotong University. His research interest is in environmental science. (346818647@qq.com)