Keywords

1 Introduction

With the rapid development of society, science and technology, people have higher and higher requirements for their quality of life. In particular, people pay great attention to home safety. Therefore, designing a home safety IoT monitoring system, which uses ZigBee and WiFi technology to collect and transmit data between nodes and between nodes and platforms. The sensor nodes form a wireless sensor network which distribute in every corner of the home. The system can not only realize the real-time monitoring of the home environment, but also ensure the safety of the elderly living alone preliminarily and reduce their need for care at home which provides great convenience for their children [1, 2].

In this system, CC2530 is used as the core of wireless transceiver and processing module [3]. CC2530 is an integrated chip, which uses the 8051 core and encapsulates the Z-stack protocol stack [4,5,6]. It can be used to transmit data in wireless sensor networks. The system uses CC2530 module to establish a small ZigBee network [7,8,9], which is composed of three node types: coordinator node, router node and sensor node.

With the changing needs of people, wireless access technology is more and more in line with the development trend of society. Therefore, people's demand for wireless sensor networks is increasing exponentially. Wireless sensor networks (WSN) adopts a distributed sensor network, which fully combines various advanced technologies such as distributed information processing technology, modern network and wireless communication technology [10, 11]. It can cooperate with each other to detect and collect all monitored area data in real time, and process the collected data. Then the data is transmitted wirelessly and transmitted to users in the form of wireless Ad Hoc network and multi hop network [12,13,14,15].

2 System Architecture Design

In the home security IoT monitoring system, it uses the low-cost and low-power ZigBee low-speed and short-distance wireless network protocol to detect the security parameters of the detected location. The system is mainly composed of coordinator, router, terminal, gateway, server, client and other components. The coordinator is in charge of creating Zigbee network at the mobile terminal, initializing the network, assigning an address to the mobile terminal node that initially needs to join the network and controlling the joining of the mobile terminal node. It can upload the collected data and realize the automation function of remote control of the terminal at the mobile terminal. The terminal equipment includes temperature and humidity sensor, MQ2 smoke sensor and human infrared sensor, which can realize indoor data acquisition, storage and transmission. The router is responsible for forwarding messages from other nodes.

In the system architecture design, the terminal collects the required data, and the coordinator receives the data through ZigBee sensor node networking. The coordinator uploads the data to the gateway through the serial port, and then the gateway sends its data to the computer. The WiFi module can also be driven through the protocol stack. The WiFi module can communicate with mobile phones, computers and routers, and load the collected data into HTTP format and send it to the cloud service OneNet cloud platform. The sensing layer of the system sends the data which collected by the sensor to the application layer through the network layer. The application layer analyzes and processes the data, and monitors it in real time. When the monitoring data is abnormal, it will send out alarm prompt information in time, so as to realize the management and monitoring of home safety. The systematic software flow chart is described in Fig. 1.

Fig. 1.
figure 1

Systematic software flow chart.

The architecture of the whole IoT system consists of three parts: IoT device end, device cloud platform and web background server [16]. The Internet of things device cloud platform is based on OneNet device cloud. The main steps of OneNet cloud platform accessing the development process are as follows [17]:

  1. 1)

    Registered product information;

  2. 2)

    Create equipment list;

  3. 3)

    Establish TCP connection and upload data;

  4. 4)

    View the data flow.

The device access flow chart of OneNet cloud platform is shown in Fig. 2.

Fig. 2.
figure 2

Onenet cloud platform device access process.

3 Hardware Platform

The design of home IoT monitoring system is mainly composed of sensor, ZigBee gateway design and OneNet cloud platform [18]. The design of the systematic hardware architecture is shown in Fig. 3.

Fig. 3.
figure 3

Systematic hardware architecture.

In the design of nodes, we mainly refer to several commonly used sensors in home security to meet the requirements of the system. The human infrared sensor adopts HC-SR501 [19] model, and its sensing range is less than 7m. We usually add a Fresnel lens to the sensor module to improve the sensitivity of human detection. DHT11 contains a temperature and humidity sensor with calibrated digital signal output [20, 21]. The module realizes the collection of temperature and humidity data by controlling the timing. It is necessary to wait 1 s after the sensor is powered on to ensure the accuracy of the measured data. MQ2 sensor is mainly used to detect gas leakage [22]. It has the advantages of high sensitivity, good anti-interference and long service life. In the setting of the system, if the concentration of natural gas leakage is higher, the voltage output from AO pin will be higher. Thus, the value after ADC conversion will be larger. The ESP8266 WiFi module has low power consumption, supports transparent transmission and does not have serious packet loss. It can not only realize data transmission, but also connect to a designated router as a WiFi client [23]. The buzzer of the active module is selected. The active module is driven by triode, which is triggered at low level, that is, when the I/O port inputs low level, the buzzer makes a sound.

4 Algorithm Design and Implementation

The system uses IAR Embedded Workbench platform to realize ZigBee data communication through the design of ZigBee connection algorithm. In this system, the terminal enters the SampleApp_ProcessEvent() event firstly, and then the terminal calls SampleApp_SendTheMessage() function collects data. In this function, it sends the data by calling AF_DataRequest() function. If the data sent by the terminal is received through the ZigBee coordinator, it will enter SampleApp_ProcessEvent() event, which triggers SampleApp_MessageMSGCB() function in turn, receives the data sent by the terminal, and then its data is displayed on the OLED screen.

In SampleApp.c, configuring the product apikey, device ID, router account and password of OneNet cloud platform to realize the data interaction between WiFi module and OneNet cloud platform. The configuration code is as follows:

figure a

MCU can use ESP8266 WiFi module to send AT command to realize the configuration of WiFi transmission module. The configuration command is shown in Table 1.

Table 1. WiFi transmission module configuration.

Since the data packet of DHT11 sensor is composed of 5 bytes [24] and its data output is uncoded binary data, the temperature and humidity data need to be processed separately. The calculation formulas of temperature and humidity values are shown in (1) and (2), where byte4 is the integer of humidity, byte3 is the decimal of humidity, byte2 is the integer of temperature, and byte1 is the decimal of temperature.

$$ {\text{humi}} = {\text{byte}}4.{\text{byte}}3 $$
(1)
$$ {\text{temp}} = {\text{byte}}2.{\text{byte}}1 $$
(2)

The resistance calculation of MQ2 smoke sensor is shown in formula (3), where Rs is the resistance of the sensor, Vc is the loop voltage, Vrl is the output voltage of the sensor, and Rl is the load resistance. The calculation of resistance Rs and the concentration C of the measured gas in the air is shown in formula (4), where m and n are constants. The constant n is related to the sensitivity of gas detection. It will change with the sensor material, gas type, measurement temperature and activator [25]. For combustible gases, most values of the constant m are between 1/2 and 1/3 [26]. According to the above formula, the output voltage will increase with the increase of gas concentration.

$$ {\text{Rs}} = (\frac{{{\text{Vc}}}}{{{\text{Vrl}}}}{ - }1) \cdot {\text{Rl}} $$
(3)
$$ {\text{logRs}} = {\text{mlogC}} + {\text{n}} $$
(4)

The human infrared sensor uses the algorithm of timer T1 query mode, and its safety alarm logic judgment steps are as follows. The function realization process of the alarm program is shown in Fig. 4.

  1. 1)

    The InitT1() function initializes the timer.

  2. 2)

    To configure the three registers T1CTL, T1STAT and IRCON of timer T1, that is, set T1CTL = 0x0d (the working clock is 128 frequency division, and the automatic reload is 0x0000-0xFFFF), T1STAT = 0x21(the status is channel 0, the interrupt is valid), and IRCON = 1 (you can judge whether the storage space is full by querying).

  3. 3)

    To judge whether a person is detected and set DATA_PIN = 1 is detected.

  4. 4)

    If no one is detected, judge whether the storage space is full.

  5. 5)

    If the storage space is full, IRCON > 0, clear it, set IRCON = 0, and judge whether the unattended time count is within 12 h, so as to know whether there is any abnormality.

  6. 6)

    If count > = 12 h, it is considered that the elderly living alone have an abnormal state, the buzzer gives an alarm and LED1 is off.

Fig. 4.
figure 4

Realization process of alarm logic judgment function.

5 Experimental Analysis

5.1 Sensor Data

After the software and hardware of the system are designed, data acquisition is carried out in the laboratory. The temperature, humidity and MQ data measured by terminal 1 are shown in Fig. 5. If humidity or MQ value is detected excessively, the buzzer will sound an alarm. The information detected by terminal 2 is shown in Fig. 6. If no person detected is displayed in the detection results for a long time, LED1 light will be on and the buzzer will alarm.

Fig. 5.
figure 5

Temperature, humidity and MQ values.

Fig. 6.
figure 6

Human body detection.

5.2 OneNet Cloud Platform Data

Selecting the baud rate of 115200 on the serial port debugging tool after the configuration of OneNet cloud platform is completed. The configuration results are shown in Fig. 7. The WiFi module uses STA+AP mode. The WiFi serial port module establishes a TCP connection, configures a server with IP 183.230.40.33 and port number 80. In the transparent transmission mode, the data is transmitted, and the module is connected to the network through the router, so as to realize the remote control of the equipment by the computer.

Fig. 7.
figure 7

OneNet configuration results.

After the system is docked through WiFi module and OneNet cloud platform, the temperature and humidity sensor uploads the collected data to the cloud platform successfully, as shown in Fig. 8. I take 10 groups of data as an example through the long-term collection of temperature and humidity data in the laboratory, as shown in Fig. 9.

Fig. 8.
figure 8

Web cloud platform data.

Fig. 9.
figure 9

Change of indoor temperature and humidity value.

6 Conclusion

This paper takes ZigBee technology as the core through the combination of ZigBee wireless Ad Hoc network and WiFi communication technology. The home IoT monitoring system is studied and designed, which integrates the Internet, intelligent alarm, communication network and other scientific and technological means effectively. The system adopts temperature and humidity sensor, human infrared sensor and MQ2 smoke sensor to realize the data acquisition of the home environment. For this data, if there is any abnormality, the buzzer will give an alarm. The system adopts ZigBee technology with low cost, low power consumption and strong networking ability, which not only increases the practicability of the system, but also can monitor home safety in real time for a long time, so as to avoid safety accidents and reduce losses.