The Design of Home Fire Monitoring System based on NB-IoT

—In the field of home fire monitoring, the currently relatively mature monitoring solutions include GPRS/GSM communication and Zigbee communication. The main disadvantage of GPRS wireless communication is high power consumption, and the disadvantage of Zigbee technology is that it needs to be combined with other communication technologies to realize remote monitoring. In addition, the above technical solutions all require self-built local or remote monitoring servers to save monitoring data. In view of the above problems, this system designs a home fire monitoring system based on NB-IoT technology and cloud platform. The system uses a single-chip STM32F103C8T6 as the core controller and contains a sensor data acquisition module and a narrowband IoT communication module. The data fusion of multi-sensor data is performed by BP neural network algorithm.On the basis of remote transmission, the system solves the problems of high power consumption, high cost and insufficient signal coverage of terminal hardware. The system can collect indoor environmental parameters and fire information in real time, and upload them to the cloud platform for storage. If abnormal data is detected, an early warning message will be issued. The feasibility of the system is verified, and the verification results show that the system works normally and the output is accurate, which meets the design requirements and can be widely used.


I. INTRODUCTION
Nowadays, high-tech electronic products are widely used in various families. However, because some people can't use these high-tech products reasonably, and even misoperation leads to adverse consequences, many abnormal situations or dangers occur. In addition, most families use natural gas, liquefied petroleum gas, etc. Some people forget to close the valve after use, causing gas leakage and other situations. Gas is a flammable and explosive gas, which is likely to cause fire or explosion accidents. Therefore, the indoor system needs to have the functions of gas detection and fire detection to ensure the safety of family environment. The establishment of family fire monitoring system has practical application value and social benefits [1].
In order to solve the above safety problems, a home fire monitoring system based on NB-IoT (Narrow Band Internet of Things) is designed. By using a variety of heterogeneous sensors (such as temperature and humidity sensors, smoke sensors, etc.) as the data acquisition module to collect indoor environmental information, the data is analyzed and processed by the main controller to realize the functions of fire detection and gas leakage detection, so as to achieve the purpose of remote care of the home environment, ensure the safety of family life and property, and provide a safe and intelligent living environment for the family [2].
The core controller of the home fire monitoring system is a microprocessor STM32F103, which contains a sensor data acquisition module and a Narrowband IoT Communication Module composed of a home living room environment monitoring and fire monitoring system [3]. The system is based on the middle layer of the home fire monitoring system of Huawei's OceanConnect platform, and achieves the work of device data reporting and platform issuing commands [4]. The home fire monitoring platform realizes the remote monitoring of the home living environment. The validity of the fire detection algorithm is verified through experiments, and the test results are as expected; through the test of the terminal node, cloud platform and each functional module in the home fire monitoring platform, the feasibility of the function of the home fire monitoring system and the stability of data transmission are verified, which provides a reference for the practical application and promotion of the system. II. RELATED WORK FENG Hui et. al. [5] based on ZigBee technology, smoke, CO, temperature detection fusion were integrated, and community fire alarm system based on ZigBee is designed and implemented. QI Bin et. al. [6] used LoRa and GPRS separately for long-distance transmission of fire sensing information and fire alarm information. The combination of the two technologies meets the needs of wireless fire alarm system monitoring and alarming. ZHANG Zhi-hua et. al. [7] used probabilistic neural networks for information fusion of fire features, which can effectively perform fire identification and improve the accuracy of fire detection. XIE Rongquan et. al. [8] used the BP neural network algorithm to calculate and detect the developing rule and signal feature of the fire image. OKOKPUJIE K O et. al. [9] combined GPRS and single-chip microcomputer to build an automatic fire alarm system to realize remote fire monitoring.
Although Zigbee technology has flexible terminal nodes, easy deployment, and low power consumption, its application distance is limited. The disadvantages of GPRS/GSM wireless communication method are high power consumption, high operation and maintenance costs, low data transmission rate, and the risk of withdrawing from the network with the rapid development of 5G technology in China. LoRa wireless communication technology needs to be combined with GPRS/GSM wireless communication method to achieve remote monitoring. In addition, the above technical solutions all require self-built local or remote monitoring servers to save monitoring data.

III. OVERALL SYSTEM ARCHITECTURE DESIGN
The system consists of sensing terminal, cloud platform and application layer. The sensing terminal mainly contains sensors, STM32 main control module, NB-IoT communication module and external control devices; the platform layer mainly contains IoT cloud platform; the application layer provides home fire monitoring application services to users, and the system architecture is shown in Fig. 1. The sensing terminal collects indoor temperature and humidity, smoke concentration, harmful gases and other information, uploads alarm signals when abnormal conditions such as gas leakage and fire occur, sends the data to the cloud platform, and starts external control devices at the same time.
The IoT cloud platform is essentially a cloud server with functions of device management, data management, etc. It converts the format of upstream and downstream service data, connects NB-IoT terminal devices in the south direction, and connects the application layer in the north direction, decodes the south direction data for easy access by the perception layer subscription, and encodes the north direction commands for easy reception by the perception layer.
The northbound application is a human-computer interaction interface, which accesses data messages through a personal PC subscribed by the API interface and protocols opened by the IoT cloud platform, displays the home environment data status in real time, and includes alarm notification functions, and can issue commands to remotely control terminal devices when abnormal.

IV. TERMINAL HARDWARE DESIGN
The sensing terminal mainly consists of a variety of heterogeneous sensors, the main controller, NB-IoT module and other peripheral circuits, in which the sensors are mainly responsible for collecting indoor environmental data, the main control unit fuses, processes and controls the start and stop of the collected data, and establishes a connection with the cloud platform through the NB-IoT module networking, packages and uploads the data to the cloud platform, and receives commands from the cloud platform. The hardware block diagram of the system terminal is shown in Fig. 2.

A. Environmental Parameter Acquisition Circuit
The system uses STM32F103C8T6 as the terminal main control chip, which has timer, UART, ADC, I/O and other modules inside, which fully meets the functional requirements of system hardware design. The temperature and humidity acquisition module DHT11 is used to monitor changes in temperature and humidity, the smoke sensor MQ-2 is used to detect gas leakage, and the carbon monoxide sensor 4CO-500 is used to detect CO concentration [10].
1) DHT11 chip adopts single bus data format. With high measurement accuracy and low power consumption, it only needs a single data pin port to complete I/O bidirectional transmission. Connect the I/O port PA7 of the STM32 microcontroller to the DATA pin of DHT11, and connect a pull-up resistor to the DATA pin to realize temperature and humidity acquisition.
2) The system uses MQ-2 smoke gas sensor to monitor the environment for gas leaks and fires, which is commonly used to detect smoke, liquefied gas, alcohol, methane and other gases, with the advantages of high sensitivity, wide detection range, high stability, long service life, etc. and is widely used in smart homes and other fields. The signal output by the two B pins of MQ-2 is a DC signal and changes with the smoke concentration. Connect the B pin to the PA0 of the STM32 microcontroller [11].
3) Carbon monoxide will be produced in the early stage of a fire. After carbon monoxide enters the human body, it will combine with hemoglobin in the blood, causing hypoxia in the body tissue, causing the human body to faint and suffocate to death. Therefore, it is very important to transmit the concentration of carbon monoxide to the fire control center in real time to guide fire rescue.

B. NB IOT Communication Module
The system selects the BC35-G wireless communication module to send data and receive commands, which is a multiband NB-IoT wireless communication module with very low power consumption, high sensitivity and low cost. And it supports multiple network protocol stacks with significant advantages in positioning, power consumption, data transmission rate and other module performance and system security [12]. The SIM card adopts the special NB-IOT network card provided by China Telecom to store temporary data [13], user information and encryption key. The application circuit is shown in Fig. 3.

C. Power Module Design
The external 3.7V lithium battery is chosen to power the whole hardware terminal, because the power supply voltage of each module is not consistent, the power supply voltage of the main control module is 3.3V, the power supply voltage of the data acquisition module is 5V, and the power supply voltage of the NB-IoT module is 3.7V. Therefore, the voltage needs to be converted into 3.3V and 5V to power the main control module and the data acquisition module respectively.
The lithium battery power supply module adopts the TP5410 chip for charging and boosting. The chip integrates the functions of charging and discharging, 5V constant voltage boosting, etc., and converts the lithium battery 3.7V voltage into 5V voltage through the boost converter. The circuit schematic diagram is shown in 3.3 shown. VUSB represents the voltage provided by the external device connected to the USB interface. The BAT pin is connected to a 3.7V lithium battery. The VOUT pin represents the circuit output voltage, which is converted to 5V by the booster.
RT8059 is selected as the 3.3V voltage regulator chip. This chip can effectively reduce the 5V voltage to 3.3V and conduct voltage stabilizing output. Its output current can reach 1 A. The power supply voltage regulator circuit is shown in Fig. 4.

V. TERMINAL SOFTWARE DESIGN
The role of the sensing terminal software is to realize the collection of environmental information, data processing and complete data reporting. The terminal device software execution process is shown in Fig. 5. After the terminal device is powered on, the hardware enters the initialization state. After the initialization is completed, the BC35-G module connects the device to the network, and checks the network attachment status by calling the AT command. When the network attachment is successful, it connects to the cloud platform for data transmission services. After the NB network is successfully attached, the sensing terminal (southbound device) is connected to the IoT cloud platform. After the connection is successful, the CDP server is configured. At this time, the device is in the wake-up state and remains connected to the cloud platform, and the device can communicate with the specified application server. The sensing terminal first collects sensor data, fuses the data, determines whether there is a gas leak or a fire, if so, sends an alarm message, and then sends the data to the cloud platform [14]. The main controller encodes the acquired data according to the defined binary format, and constructs the fused data into CoAP packets and sends them to the cloud platform. The cloud platform parses the CoAP message, decodes it by calling the decode interface, and converts it into a unified json data format to complete the data reporting. When the cloud platform issues a command, it calls the encode interface to encode and convert it into a binary code stream to construct a CoAP message and send it to the sensing terminal. The main controller parses the command and returns a response to control the operation of related external devices.

A. STM32 Project Configuration
The terminal software development uses the integrated development environment Keil uVision5. Since the STM32 requires a lot of initialization configuration during development, such as pin definition, clock configuration, etc. If the direct operation register development method is used, the process will be very cumbersome. In order to reduce the development time and energy, the STM32CubeMX software is used to configure the initialization code of the STM32 project in a graphical way. The generated STM32 initial project can be directly opened in Keil uVision5 and run.
Create a new project in STM32CubeMX, select the STM32F103C8 series MCU chip, configure the pin function according to the schematic diagram, and then configure the initialization parameters. The main pin configuration functions are as follows: After the pin and initialization configuration is completed, the initialization project code is compiled and generated, which can be called directly when writing the program for each module.

B. Fire Discrimination Algorithm
The terminal nodes collect parameters such as temperature and humidity, smoke concentration, and CO concentration in real time, and then the collected data are homogenized and normalized, and then fuses the multi-sensor data through the BP neural network algorithm, and outputs it after decision analysis [15]. In the home environment, humidity has little effect on fire, so the effect of humidity is not considered in this paper for fire discrimination [16].
(1) Data preprocessing Due to the existence of many interference noises in the external environment, the measured data are often inaccurate, which will cause great interference to the result judgment, and even misjudgment and omission may occur. In order to improve the accuracy of the data, the data needs to be preprocessed. Assuming that there are n different sensors in the system, their output vectors corresponding to the moment t can be summarized as X(t) = (x 1 (t), x 2 (t), ..., x n (t)),denoted: where K is the number of sample data, is the sample arithmetic mean, and is the sample standard deviation. And from equations (1) to (2), it can be inferred that the homogenization formula of heterogeneous sensor data is: Thus, the input vector can be transformed into:Y (t) = (y 1 (t), y 2 (t), ..., y n (t)). If some of the data fluctuate greatly during the measurement process, it may happen that the data with smaller values in the output data is assimilated by the data with larger values. To avoid this event, this paper uses the normalization method to compress the data after homogenizing the data. The normalization formula is shown in (5).
where y i (t) is the input vector after homogenization, x ′ i (t) is the normalized covariate value, y max is the maximum input value, and y min is the minimum input value.
(2) Fire Data Identification In this paper, the BP neural network algorithm is used to fuse the preprocessed data. BP neural network consists of input layer, implicit layer and output layer, and the most rapid descent method is used to learn the rules, and the actual result output is made infinitely close to the desired output by continuously adjusting the threshold and weights, so as to finally achieve the purpose of learning training.
The number of neurons in the input layer of the BP neural network is influenced by the dimension of the input data, and the number of neurons in the output layer is determined by the specific application, while the selection of neuron nodes in the hidden layer is particularly important, and the appropriate selection number will directly affect the performance of the BP neural network, which usually uses equation (6) to select the neuron nodes in the hidden layer.
where m is the number of input layers, n is the number of output layers, a ∈ [1,10].
In order to avoid the problem of solving linear indistinguishability brought by linear mapping, the S-type activation function f (x) = 1/ (1 + e ∧ (−x)) is used in the BP neural network in this paper.
In this paper, the three parameters of temperature, smoke concentration, and CO concentration are used as the input layer of the BP neural network. And the open fire probability, shaded combustion probability, and no fire probability are used as the feature outputs according to the type of fire occurrence. The training output value is [0, 1] between. The number of input and output neuron nodes is 3. According to formula (6), the number of hidden layer neuron nodes is set to 10, and the structure of BP neural network is shown in Fig. 6. The BP neural network structure is determined, and the network parameters are set: Network inputs: The weight of the input layer and the implicit layer is w ij , and the threshold is θ j ; the weight of the hidden layer and the output layer is v jt , and the threshold value is γ t .
The network parameters are set and the feature-level fusion is performed. The core is iterative learning and training. The specific learning and training process is as follows: 1) Initialize the weights and thresholds, assign any real numbers within the interval (−1, 1) of the weights and thresholds, and select the error function e, the calculation precision value ε and the limited number of learning times M .
2) Randomly select a group of samples k as input and target samples: the kth group of input 3) Calculate the implicit layer inputs as: The output is: 4) Calculate the output layer input as: The output is: 5) Calculate the unit error between the actual output and the expected output: 6) Calculate the error of each unit in the middle layer as: (12) 7) Output layer weights and threshold correction: 14) where, N is the learning rate, α ∈ (0, 1) .

8) Implicit layer weights and thresholds:
9) Continuously update the replacement weights and thresholds, and perform iterative training until the error meets the preset accuracy or reaches the limit of the number of learning times, and then the training can be ended.
In order to verify the accuracy of the system fire detection algorithm, the system measurement data, SH3 polyurethane plastic fire and SH6 wood fire are selected to form the original samples, and a total of 70 sample data are formed. Part of the original data and expected output are shown in Table I. Homogenize and normalize the original data according to equations (1) to (5), and the data will be limited to the [0, 1] interval after normalization. The processed sample data are shown in Table II. Using matlab simulation software to simulate the neural network, 60 groups of sample data are selected from the existing test data for network training, of which the number of learning times is 50, the learning rate is 0.1, and the number of neurons in the hidden layer is 10. The neural network error obtained by BP neural network algorithm is shown in Fig. 7. Where, the abscissa is the number of training times, and the ordinate is the neural network error [17]. When the error is less than 0.0001, the training of the BP neural network is completed. The preprocessed sample data in Table II are tested experimentally, and the sample data are input into the trained BP neural network to obtain the actual output values of several different fire probabilities. The test results are shown in Table III. Through the above 9 sets of test data, it is known that the absolute error of open flame probability is 0-0.024, and the average absolute error is 0.00567; the absolute error of smoldering probability is 0.002-0.035, and the average absolute error is 0.01067; the absolute error of no fire probability is 0.010-0.091, and the average absolute error is 0.02056, it can be seen that the trained neural network conforms to the actual output. The fire detection algorithm can improve the measurement accuracy of the fire detection device in practical applications, and can better reduce the probability of false alarms and missed alarms.

VI. IOT PLATFORM DESIGN
The IoT platform used in this system is Huawei's Ocean-Connect platform, and the design process is as follows [18]. 1) Create a home fire system product application, record the application ID and key; 2) Write a profile file to define the capabilities and characteristics of the NB device; 3) Design a codec plug-in, parse the reported data and encode the issued commands; 4) Register NB-IoT device, connect the device to the network. After the device is connected to the network, the platform can receive device data to realize the connection and management of the NB-IoT module and the OceanConnect platform; 5) Debug, create online debugging and testing equipment, and use application simulator and NB equipment simulator to simulate the process of data reporting and command issuance.
The device Profile file developed in this paper mainly defines four attributes, smoke (smoke), CO concentration (CO), temperature (temp), humidity (humi), and also adds the down command field, sets CmdValue as the exhaust fan on command. Cmdvalue = 1 means to turn on one exhaust fan, cmdvalue = 0 means to turn off the exhaust fan, and the attribute type is int; Set alarm as the alarm command, take 1 as the alarm and 0 as the off alarm [19].
NB-IoT devices generally have higher requirements for power saving and use binary format. However, the IoT platform communicates with the application side using JSON format. Therefore, coding plug-ins need to be developed for the IoT platform to call in order to complete the conversion between binary format and JSON format. When the terminal reports temperature, humidity, CO, and smoke data messages, the message name and data type must match the definitions of the corresponding fields in the profile, that is, they are consistent [20].
After the design of the codec plug-in is completed, you can add a real device or a new virtual device for debugging. After the debugging is passed, you can develop Web applications. This system uses the OceanBooster platform to develop northbound applications. OceanBooster supports forms, text, buttons, background pictures, etc. When adding new menus, external links can be added, with the ability to analyze device statistics, one-click device commands can be issued, and supports docking to third-party systems to quickly build WEB-side applications. According to the NB-IoT device developed by the profile file and codec above, add device monitoring components, button components, switch components, device status trend components, etc., set the style and layout of each component, and connect the components with the products developed in the IoT platform, connect the attributes, services, and commands of the components correspondingly, and realize the uploading and sending of commands and data. The interface of the monitoring system is shown in Fig. 8. The current room temperature is 18°C, humidity is 71%, smoke concentration is 1%, and CO concentration is 0; the devices registered in the IoT platform can be selected to display the current status of each device, and the audible and visual alarms and exhaust fans can be manually controlled [21].

VII. CONCLUSION
By analyzing the functional requirements of the terminal system, the design scheme is determined, and the hardware and software of the terminal system are designed. The system hardware terminal composed of STM32F103C8T6 as the main controller, each sensor data acquisition module, BC35-G wireless communication module and other peripheral circuits is designed. Through the design of the system terminal software, the sensor data acquisition module can collect the indoor environmental parameters (temperature and humidity, smoke concentration, etc.) of home living in real time, and after being processed by the STM32 main controller, the terminal data is sent to the IoT cloud platform by the BC35-G networking. And the threshold method is used to realize the indoor gas detection and alarm function. The three raw data of temperature, CO concentration and smoke concentration are processed by homogenization and normalization methods, and the BP neural network is applied to data fusion of the preprocessed data. Through continuous iterative learning and training, the probability of fire occurrence is obtained, and accurate fire detection is realized. The main work of the paper is as follows: 1) The system architecture design is completed and the NB-IoT home fire monitoring terminal hardware and software function programs are designed. The terminal node can collect indoor environment data (temperature and humidity, smoke concentration, etc.) and detect fire in living environment in real time while setting the threshold value through sensor data to achieve gas leak detection; Use data fusion technology to realize fire detection function; use NB-IoT wireless transmission technology to regularly upload data to the IoT platform, which has the characteristics of longdistance transmission and strong practicability.
2) Based on Huawei's OceanConnect platform, the NB-IoT intelligent gateway is built. By defining Profile files and developing and deploying codec plug-ins, the data conversion function is realized, providing a communication bridge between the system terminal and the application side. At the same time, the CoAP protocol is used as the communication protocol between the hardware terminal and the IoT platform, which further reduces the power consumption of the hardware terminal.
From the experimental results, the system meets the overall requirements of the design. The home fire monitoring system designed by using the emerging NB-IoT technology solves the problems of high cost, high power consumption and short transmission distance of traditional Internet of Things technology, and has high practical value; the fire detection algorithm and BP neural network are used to train the sample model, which improves the accuracy of fire detection and reduces the misjudgment rate; the Huawei OceanConnect platform is used to manage data and equipment, and to process and store data at the same time, reducing application costs and improving overall system performance.
In the follow-up research, the training samples will be further enriched, the humidity data will be incorporated into the network structure, and the neural network algorithm will be optimized so that it can be applied to more complex fire environments such as public buildings; a mobile APP application will be designed, and the monitoring system of this paper will be connected to the fire protection big data application platform of the government to realize grading early warning of police situation and rapid linkage response. With the rapid development of computer technology and network technology, these ideas are expected to be realized as soon as possible.