Keywords

1 Introduction

With the rapid development of wireless sensor network, smart phone communication and Internet technology, the remote wireless mobile home monitoring system will become one of the mainstream smart home network [1]. The smart home system needs a lot of information acquisition and transmission. Introducing the wireless sensor network technology into the construction of smart home can build a “home appliance network” with adaptive control function for smart home [2]. This network can not only make the smart appliances conduct mutual coordination, but also be interacted with the external network. Therefore, users can achieve the remote control of the smart appliances through this network.

At present, the domestic and foreign major operators are integrating resources and carrying out innovative business to occupy the smart home market [3,4,5]. Although the smart home industry is developing relatively quickly, the present level of development is uneven. It is faced with many problems like the lack of unified industry standards, expensive price, complex operation and the leakage of information which restrict the development of the smart home industry [6, 7]. In this research, the field research was conducted to find out the deficiencies of the current smart home system. And the environmental parameters required for the monitoring system were determined through the analysis of actual functional requirements. Combined with ZigBee wireless network communication technology and the research of the intelligent collection for monitoring data by sensors, a set of perfect intelligent remote monitoring system for smart home was designed through the mobile terminal platform. And the debugging environment was deployed to analyze and verify the research results.

2 Overall Design

The overall design is based on the research about the wireless sensor network technology, wireless data communication technology, HTML5, WebSocket and other related theoretical basis [8]. Combined with corporate field research and actual functional requirements analysis, the overall design of the smart home monitoring system based on the wireless sensor network was determined generally, as shown in Fig. 1.

Fig. 1.
figure 1

Overall design

The system collects the required information of the family environment by the related sensors and controls the switch of the household electrical appliances by the controller modules. In this system, the sensor modules and the controller modules are connected to the ZigBee terminal equipment. The data transmission is based on the ZigBee wireless network and the ZigBee center coordinator. The ZigBee center coordinator is connected to the server through the serial ports. It can save the data collected from the sensors into the server database or sent the data to the client directly. According to the implementation process of the system, the overall scheme includes the front-end sensors and the controllers module design, the ZigBee wireless sensor network design, the data transmission module design, the server program design, the data interaction module design, and the client application software design.

3 Wireless Sensor Network Design

3.1 ZigBee Wireless Network Design

The ZigBee wireless transmission module of this system used TI wireless RF chip called CC2530F256 as the core chip. CC2530F256 is compatible with the ZigBee protocol stack, providing a powerful and complete ZigBee solution. Because the transmission distance is relatively short and the family housing area is limited, the system just needs relatively small sensor nodes and a simple data transmission structure, which does not need the router nodes to extend the network coverage area [9]. Meanwhile the position and the number of the household appliances are easy to change, which will change the network state. Therefore, under the premise of the communication requirements, considering the cost of the equipment and the simple structure, this system used the star topology to build the smart home wireless network. The star topology wireless network consists of a ZigBee full-function central coordinator and several terminal functional devices. And the data transmission is based on the principle of ZigBee wireless data transmission.

In this paper, the DS18B20 temperature sensor module was selected as an example to introduce the concrete design process of the data acquisition and transmission software. First, the system obtained the collected data from the terminal device. Then the data was transmitted to the central coordinator. Finally, the coordinator sent the data to the sever module through the serial ports. In order to observe the results of data acquisition expediently, the coordinator used LCD to display the collected data values. Meanwhile the data in the terminal nodes and the coordinator node was sent to the computer through the serial ports and shown by serial debugging assistant. In order to enhance the system layout and installation convenience, meanwhile reducing energy consumption, the data acquisition nodes all used the battery power [5, 10]. The node modules will go into sleep mode in leisure time and be wake up when the system needs data acquisition or transmission. The entire workflow is shown in Fig. 2.

Fig. 2.
figure 2

Temperature sensor node workflow

3.2 Development and Encryption of the Data Communication Protocol

The data communication protocol was designed to solve all kinds of problems of the parameters transmission, ensure the integrity, reliability and security of the data, and achieve the data transmission function between the modules. Based on the basic Modbus communication protocol, the system used the same structure to define the different command codes. According to the concrete data and the specific functions, the system customized a complete communication protocol, which can make the system more standard and perfect. In order to make the communication protocol defined by the system possess scalability, the functional code fields were set in the message component unit, and the functional code table was established to manage the functional codes defined by the system. The developers only need to add the functional codes in the code table when they want to add new function in the protocol, which will not affect the previous communication protocol and functions.

In order to avoid the interference of the external equipment and ensure the confidentiality and the security of the data in the process of network communication, the security and encrypted transmission of the data in the smart home network are the importance of the research. There are three basic encryption keys of the ZigBee network data, including the main key, the link key and the network key. According to the actual application, the key is generated by the network layer and the application layer. The security keys can be shared between the layers, which can reduce the storage requirement. The system used CC2530 chip as the ZigBee module of the wireless transceiver. And the data encryption and decryption of CC2530 can be achieved through the coprocessor supported by AES (Advanced Encryption Standard).

4 Design of the Monitoring System

4.1 Design of the Functional Modules

According to the demand analysis of the system, the smart home monitoring system can be divided into five main functional modules, including real-time monitoring module, security alarm module, scene mode, basic information management and user management. These five functional modules can not only achieve the real-time monitoring data display, alarm for abnormality, linkage control and historical data display, but also achieve the statistical processing, analysis and diagnosis of the massive monitoring data to search potential effective information intelligently. In the meantime, this system can provide the mode selection, information management and scalability. The overall functional structure of the system is shown in Fig. 3.

Fig. 3.
figure 3

Overall system functional structure

4.2 Acquisition and Processing of the Server Data

The server used multithreading serial communication technology to obtain the induction layer data. In the data communication process, a variety of serial operations were placed in different threads, and every thread was only responsible for the corresponding serial operation. The main thread was responsible for the coordination and management of the auxiliary threads, which can use the CPU in fast switching between various threads. Therefore, the system can achieve the concurrent execution and multi-task mechanism to reduce the occupancy rate of the CPU. This mechanism can improve the utilization of the serial ports and efficiency of data transmission, which can greatly improve the data request and processing ability of the server.

In order to solve the common problems of the database like operating frequently and low query efficiency, the system used the cache mechanism to save the collected data. The cache mechanism saved the data in the cache memory. Returning data from the cache memory is quicker than querying database, so it can greatly improve the performance of the server application. In the process of operation, the database will start data cache dependency. When the server requests the latest data collected by the sensor, it will write the data to the cache and update the cache. And setting the key index “CacheKey” when the system writes cache can improve query execution efficiency of the data in the cache. The concrete process of data storage adopting data cache mechanism is shown in Fig. 4.

Fig. 4.
figure 4

Flow chart of cache data storage

4.3 Information Interaction of the Client and Server

For the basic operations which don’t need high operation frequency and real-time requirements, such as user login, obtaining the equipment information, querying the historical data and other operations, the client used Ajax asynchronous loading technology to invoke the Web Service from the server and obtain the basic information. In order to make the system client and server can transmit data cross platform and cross language, this system used lightweight data exchange format “Json” to achieve the data exchange between them.

As for viewing and operating the data in real-time monitoring system, it needs client and server keep persistent connection and constantly obtain the real-time updated data from the sensor layer, which has high requirements for real-time communication, so this system designed the WebSocket full duplex bidirectional communication technology to achieve real-time monitoring. First, this system enabled a thread in the server to open the WebSocket network service and used the delegation method to open or close the WebSocket connection. Then it obtained the IP address of the machine and established the monitoring ports. Finally, the system regarded the two values as the parameter values of the WebSocket server address to transmit data. For the realization of the system client, the system used the HTML user interface. After the WebSocket connection between the client and the server, the two sides will be able to achieve continuous two-way communication with a high utilization ratio.

5 Application Test and Verification of the System

5.1 Communication Distance and Packet Loss Rate Test

In order to compare the performance of the ZigBee communication system in different environments, the test was divided into indoor test and outdoor test, which conducted a number of tests in different indoor rooms and outdoor open occasions to ensure the accuracy of the results. In each distance test process, the ZigBee terminal node data transmission frequency was set as 3 s/times, and a total of 500 data was sent to the coordinator. The average value of the test results was shown in Table 1.

Table 1. Communication distance and data packet loss rate of the ZigBee module

As we can see from the test results, by using the system based on the ZigBee wireless sensor network, when the communication didn’t meet interference in the outdoor environment, the packets loss rate was very low within a 50 m range. When the node distance was more than 70 m, the packet loss rate will increase a little. While in indoor environment, when the transmission distance was less than 25 m, the packet loss rate was about 0%. The results show that the data transmission of the designed ZigBee network has high reliability, and it can meet the requirements of data transmission in the general family environment.

5.2 WebSocket Real-Time Communication Verification

In order to examine the communication efficiency and real-time of the WebSocket technology which was used in the smart home monitoring system, the Ajax polling based on HTTP protocol and the real-time communication framework based on the WebSocket were set up. In this test, the data request and response information of two kinds of scheme in the process of communication were analyzed and compared through the Chrome browser network tools. Then the test case was designed by using the Jmeter pressure test tools, which simulated the communication between the client and the server to compare the network throughput and delay of two methods.

5.2.1 Network Throughput

In this two test schemes, the same data in test was used to ensure that the server sent to the client in the same actual data size. The Jmeter test tool was used to get data size through the Ajax polling and WebSocket, and then we can observe the changes of network throughput in four cases. The results were shown in Fig. 5. As we can see from this picture, with the increase of the load and the flow, the network traffic caused by the Ajax polling was very huge. The WebSocket scheme caused much smaller network throughput than the traditional Ajax polling scheme, which has great performance advantages.

Fig. 5.
figure 5

Network throughput comparison of Ajax polling and WebSocket

5.2.2 Network Delay

After the completion of the test, we entered into the “view result tree” of the Jmeter test tool to count the connection time and loading time consumed in the communication process and calculate the network delay time of this two communication schemes. In order to ensure the accuracy of the test results, several experiments were carried out in each test case. The data delay time was collected to take the average value of the results. Network delay test results were shown in Table 2.

Table 2. Average delay time of the test results

According to the comparison of the above two kinds of real-time communication schemes and analysis of the results, the real-time application based on WebSocket communication scheme performs better than the current widely-used Ajax long polling technology in the aspects of message delay time and network throughput. WebSocket technology can decrease the network throughput greatly, and take advantage of the stable long connection mode to reduce the communication delay time, which has a high efficiency in the real-time monitoring system of the smart home.

6 Conclusion

This paper introduced the wireless sensors into the system, which greatly simplified the structure of the system and improve flexibility. It used the serial debugging assistant to test the communication distance and the data packet loss rate of the wireless network set up by ZigBee equipment, and completed the ZigBee communication module test and WebSocket communication test in the smart home system. It verified the stability and safety of the ZigBee wireless network. Then, the real-time communication framework of Ajax polling and WebSocket were constructed respectively, and the network throughput and the network delay of the two schemes were tested through Chrome browser and Jmeter pressure test tool, which proved the advantages of WebSocket technology in system real-time monitoring. Finally, the on-line overall test for the entire smart home system was conducted through the different mobile terminals. The system worked well and met the design requirements, which achieved the basic expected functions of the smart home system.