Frontiers in Computing and Intelligent Systems ISSN: 2832-6024 | Vol. 2, No. 2, 2022 53 Pipeline gas leakage early warning system based on wireless sensor network Jiaowu Cai 1, Peng Liu2, Liangyu Li 1 1 College of Information Engineering Zhongshan Polytechnic, Zhongshan 528400, China 2 Ganzhou Shen Ran Natural Gas Co., Ltd., Ganzhou, 341400, China Abstract: Expounds a community pipeline gas leakage warning system based on wireless sensor network, fuzzy control algorithm and random forest algorithm. System using the wireless sensor network acquisition household pipeline gas data, through the intelligent gateway will collect data reported to the cloud platform, the system through the fuzzy control algorithm to reduce the importance of low interference, make the input random forest model data optimization, visualization module using B/S architecture, responsible for the early warning data display in the Web page. According to the historical data of household gas pipeline in a community in Ganzhou city, the simulation was carried out under laboratory conditions. The results show that the model can effectively improve the function of online monitoring and dynamic early warning of gas leakage. Compared with other algorithms, the fuzzy-random forest algorithm has a better performance in finding small leakage in the early stage. Keywords: Wireless sensor network; Gas leakage; Early warning system; Fuzzy control algorithm; Random forest algorithm. 1. Introduction Pipeline gas facilitates the daily life of community residents, and at the same time, there are also many safety risks. Gas leakage will lead to poisoning, fire and even explosion of residents. It is of great significance to study the online monitoring and dynamic early warning method of gas leakage to ensure the safety of gas operation. Accident tree analysis (Fault Tree Analysis, FTA), event tree analysis (Event Tree Analysis, ETA), hierarchical analysis (Analytic Hierarchy Process, AHP), and fuzzy comprehensive evaluation method are mostly used to evaluate the gas risk. For example: Wang Chunxue, etc[1]The FTA/ETA bow tie model was used to identify the risk factors of urban gas pipeline leakage and establish a mixed-disaster probability risk assessment model. YANG Yongsheng et al [2] The gas pipe network leakage accident is analyzed by FTA method, and the probability of gas pipe network leakage is calculated by using the Bayesian network, and the dynamic calculation model of gas pipe network leakage risk is established combined with the geographic information system. And LI Xinhong et al [3] The AHP method and the expectation maximization algorithm are used to calculate the weights of different indicators, and the importance of hazard factors is evaluated by the fuzzy solution distance model, and the risk management method of gas pipeline is proposed. These methods need the practical experience of experts to find the potential danger of gas facilities, but it is difficult to monitor and dynamically warn of gas leakage online. With the development of Internet of Things technology, researchers have carried out a series of gas safety monitoring and early warning research, such as Huang Ping and others [4] Using combustible gas and temperature sensors, the data in the town pits is collected in real time, and the alarm threshold is designed, and the leakage alarm system of combustible gas is established. LIU Yongtao et al [5] In view of the single function of the existing gas alarm system, STM 32 is used to collect the gas data, and the gas leakage alarm function is realized by setting the alarm threshold. And HOU Longfei et al [6] We propose a method to optimize the pipeline leakage monitoring points, which considers the leakage diffusion radius and the effective monitoring length, and still maintains the real-time monitoring of the underground gas pipeline leakage while reducing the monitoring points. However, most of these systems use simple threshold warning method, which is difficult to make rapid response in the early stage of gas leakage. In recent years, machine learning has been developed rapidly developed, and algorithms such as artificial neural networks, random forest and support vector machines (Support Vector Machine, SVM) have been applied in the field of gas fault diagnosis and early warning, and have achieved good results [7-8]. Wang Novel et al [9] Gas pipeline valve fault diagnosis accuracy is low, easy to overfit, etcMultilayer neural network (Multilayer Perceptron, MLP) is used to predict the degree of valve failure. Qian Heng et al [10] The gas load forecasting problem is studied by using the incremental random forest regression algorithm. And ABDULLA et al [11] Using the inlet pressure, outlet pressure and outlet flow of the pipeline as input, the oil and gas pipeline leakage identification model is established by using multiple neural networks. But the accuracy of these algorithms is mostly limited by the size of the training data. According to the above problems, the author will wireless sensor network, fuzzy control algorithm and random forest algorithm, design a household pipeline gas leakage dynamic warning model, through on-line monitoring and leakage prediction, complete the dynamic warning of household pipeline gas leakage, in order to master online gas facilities operating conditions, timely detection and disposal of gas accident. 2. Overall design scheme 2.1. The overall architecture The dynamic warning model of household pipeline gas leakage is composed of data acquisition and storage module, prediction module and visualization module. The data acquisition and storage module consist of sensors, intelligent gateway and MySQL database to complete the real-time 54 collection and storage function of household pipeline gas data; the prediction module is fuzzy-Random forest model is responsible for dynamically predicting the gas leakage level of household pipeline. The visualization module consists of front-end interface and back-end server, and adopts B/S architecture to display the online monitoring data and dynamic prediction results in the web page. The model architecture is shown in Figure 1. Fig.1 Dynamic early warning model architecture of pipeline gas leakage in community households 2.2. Monitoring indicators Gas facilities have complex structure, strict safety requirements, and lack of monitoring information. Through literature review and actual investigation, six types of collected data are determined, namely, volume fraction of combustible gas, mass concentration of odorant, temperature, pipeline pressure, pipeline flow and gas consumption. When gas leakage occurs, the volume fraction of combustible gas and the mass concentration of odorant in the environment increase, and the temperature at the leakage point decreases [12], Pipeline pressure reduction, pipeline flow, gas, quantity increase. Therefore, the above six types of data are selected as the monitoring indicators of the dynamic early warning model of household pipeline gas leakage, based on the "Code for Design of Urban Gas" (GB50028-2006) and the index number and value range of the sensors used, see Table 1. Table 1. Monitoring indicators number parameter measuring range T1 Combustible gas volume fraction /% 0~0.5 T2 Oodorant mass concentration / (mg·m-3) 0~50 T3 temperature /℃ -55~100 T4 pipeline pressure /Pa 0~2000 T5 Pipeline Flow Rate / (m3·h-1) 0~5 T6 Gas consumption / m3 0~3 2.3. Wireless sensor network based on 6LoWPAN 6LoWPAN is a low-speed wireless individual domain network standard based on IPv6. Compared with ZigBee and LoRa protocols, 6LoWPAN is based on IP technology, which can directly connect with other network devices, and is suitable for community gas monitoring scenarios. Therefore, the wireless sensor network is built based on 6LoWPAN to collect the data corresponding to the gas monitoring index of the household pipeline in real time, and the gas data is converged to the boundary routing node through MQTT protocol. The wireless sensor network consists of child nodes and boundary routing. The child node consists of micro control unit, combustible gas sensor, temperature sensor, RS485 communication interface, RS232 communication interface, wireless data transmission, power conversion, clock, reset circuit, etc. The RS485/RS232 communication interface is connected to the intelligent gas meter to collect pipeline pressure, flow rate and gas consumption. The boundary routing is the same as the child nodes except for the missing sensors. 2.4. Smart Gateway In order to gather the gas data and cloud the household pipeline, the intelligent gateway is designed by using Raspberry PI. The MQTT agent server is built in the intelligent network, which is connected with the boundary route in the wireless sensor network through Ethernet, and the function of aggregation and household pipeline gas data is realized through MQTT protocol. On this basis, the gas data is programmed by Node RED and is uploaded to the cloud platform by using the MQTT protocol, and then stored to the MySQL database to realize the function of the cloud on the data. 2.5. Visualization module In order to ensure the timely and accurate detection of potential gas leakage hazards, a visual module is designed and developed to realize the function of dynamically displaying the online monitoring data and leakage level of the corresponding location in the map. Web Visual interface using HTML, CSS and JavaScript design, through the programming interface import map, call Baidu map through the design of different color annotation of different leakage level display and distinguish, through the design information window shows the corresponding area of online monitoring data and leakage level, through the Ajax method data interaction with the back-end server, realize the dynamic refresh of data. 3. Construction of an early-warning model for household pipeline gas leakage 3.1. Vague-Principle of the random forest algorithm Vague-The random forest algorithm takes the data with high feature importance in the random forest model as the input of the fuzzy control algorithm, obtains the gas leakage judgment results based on expert experience, and then replaces the gas leakage judgment results with the data with low feature importance in the random forest model, so as to reduce the interference information in the input data and improve the correlation between the input data and the gas leakage level. The optimized data was used as input to the random forest model and trained to obtain the ambiguity- Random forest model, and then get the level of household pipeline gas leakage. Vague-The structure of the random forest algorithm is shown in Figure 2, and the gas leakage grade is defined in Table 2. 55 Fig.2 Fuzzy-Random forest algorithm structure Table 2. The gas leakage grade number grade state 0 low Little gas leakage or sensor fluctuations, very low risk 1 lower Less gas leakage, less risk 2 centre Has a certain amount of gas leakage, medium risk 3 higher More gas leakage, high risk 4 tall Gas leakage is extremely high 3.2. Detailed modeling steps Step1: Use a 6LoWPAN-based wireless sensor network to collect combustible gas volume fraction, deodorant, mass concentration, temperature, pipeline pressure, pipeline flow and gas consumption under different leakage levels, and preprocess data, including data format conversion, bad point data removal and data annotation. Step2: Normize the data using the maximum minimum method with the following formula: minmax min 0 xx xx x k − − = (1) In formula: 0x is the normalized result; kx is the current data; minx is the minimum value of sample data; m axx is the maximum value of sample data. Step3: Take the processed data as the input of the random forest model, and divide the training set and the test set with a ratio of 7:3. Train the random forest model to obtain the prediction accuracy, confusion matrix and the feature importance of each data of the random forest model. Step4: Based on the feature importance in step3, Data with high feature importance were selected as input for blur processing, The model selects the volume fraction of combustible gas, odorant mass concentration and pipe pressure, Classified the 3 categories of data into 2 groups, Group 1 is the volume fraction of the combustible gas and the odorant mass concentration, Group 2 is the combustible gas volume fraction and pipe pressure, Fuzzy inference based on the corresponding membership function and fuzzy rules, The corresponding expert judgment results are obtained by anti- blur, note as 7T and 8T , and the two features with low importance are instead of 7T and 8T . Step5: Use the replaced data as input from the training method to blur the random forest model-Random forest model, obtaining a blur-The diction accuracy, confusion matrix and feature importance of each data. Step6: Use the real-time data collected by the wireless sensor network as a blur-Input from the random forest model, dynamically obtained household pipeline gas leakage grade and stored in the MySQL database. Because the specific shape of the membership function has less influence on the controller performance[16], For simple calculation, after normal the input data, use trigonometric function to construct combustible gas volume fraction 1T ,mass concentration of odorant 2T ,pipe pressure 4T , and the membership 7T and 8T , as shown in Figure 3, where, The membership function 7T and 8T is the same. The fuzzy subset of input and output is set to{NB,NS,ZO,PS,PB}, corresponding to negative, negative, 0, positive and large, respectively. Fig.3 Membership function of the fuzzy control algorithm 4. Verification and analysis 4.1. Validation preparation In order to verify the practicability of the dynamic warning model of household pipeline gas leakage, according to the historical gas data of a community in Ganzhou, the gas leakage situation was simulated in the laboratory, and the network of wireless sensor was collected from 500 gas data from 5 leakage levels based on 6L O W P AN, and the data set was divided into training set and test set with a ratio of 7:3. 4.2. Validation results The data set is labeled and put into the random forest model for training. Use the trained random forest model to predict the test set to get the accuracy of the random forest model in the test set, and determine the feature importance of each input data to the prediction results of the random forest model. In the case of selecting 500 decision trees, the prediction accuracy of the random forest model was 92%, and the characteristic importance of each input data to the prediction results of the random forest model is shown in Figure 4. Combine the fuzzy control algorithm and the random forest algorithm-Random forest model, in the case of 500 decision trees, blurred-The random forest model has a prediction accuracy of 98%, and the features are ambiguous-The significance of the prediction results of the random forest model is shown in Figure 5. From Figure 4 and Figure 5, 8T (obtained form 1T and 4T ) has the highest importance in the fuzzy random forest model, while the degree of 7T is greater than 1T or 2T ,and the 56 prediction accuracy of the random forest model is significantly improved compared with the random forest model, which proves the effectiveness of introducing expert experience. Fig.4 Characteristic significance of the random forest model Fig.5 The fuzzy-random forest model feature importance In order to further verify the influence of expert experience on the random forest model, the corresponding accuracy was obtained by changing the number of decision trees in the model, and the two models were trained and verified for many times in the number of decision trees, with the average as the final prediction accuracy. The contrast effects of the 2 models are shown in Figure 6. Fig.6 Comparasting effects of 6 2 models It can be seen from Figure 6 that: with the increase of the number of decision trees, the prediction accuracy of the fuzzy-random forest and random forest models is basically in a rising state and is fuzzy-The prediction accuracy of random forest models is consistently higher than that and ambiguous- And much smoother curves for the random forest model. To prove ambiguity-The effectiveness of the random forest algorithm, trained on the same training set, obtains the MLP neural network model and the SVM model, and compares the blur-The effects of the random forest model, the random forest model, the MLP neural network model, and the SVM model in the test set, and the prediction results of the four models are shown in Figure7. Fig.7 Comparison of the prediction results for the 7 4 models in Fig Among them fuzzy-The average prediction accuracy of the random forest model was higher than the random forest model, MLP neural network model and SVM model. The prediction results of the 4 models in the 150 test set samples are shown in Figure8. Fig.8 The prediction results of the 8 4 models in Fig Figure8: fuzzy in 150 test sets-The number of prediction error samples was 3 groups, 9 groups, the MLP neural network model was 17 groups, and the SVM model was 14 groups. Therefore, fuzzy-The predictions of the random forest model are closest to the actual samples. 5. Conclusion The system utilizes the blurring-Random forest model dynamically predicts the household pipeline gas leakage level, the timeliness of the model is based on expert evaluation 57 method and method based on static data has obvious improvement, the system combines fuzzy control algorithm and random forest algorithm, introducing expert experience into machine learning algorithm, improve the accuracy of the random forest algorithm, and reduce the random forest algorithm dependence on the data set scale. Acknowledgements The Innovation platform for integration of production and education project "Intelligent Internet of Things Technology Innovation Platform for Integration of Industry and Education" of Guangdong Province in 2022(Project No.: 2022CJPT024); The scientific research project "Intelligent Clothes Dryer Based on Wireless Sensor Network" of Zhongshan Polytechnic in 2022 (Project No.: KYB2204). References [1] Wang Chunxue, Lu Shiran. Study on the risk assessment of disaster caused by urban gas pipeline leakage [J]. Chinese Journal of Safety Science, 2016,26(12):146-151. [2] Yang Yongsheng, Zhong Shaobo, Yu Zhichen, et al. A dynamic calculation model of leakage risk of urban gas pipeline network [J]. Chinese Journal of Safety Science, 2018,28(1):167-172. [3] LI Xinhong, HAN Ziyue ZHANG Renren,et al. An integrated methodology to manage risk factors of aging urban oil and gas pipelines[J], Joural of Loss Prevention in the Process Industries,2020,66:DO1:10.1016/j.jIp.2020.104154 [4] Huang Ping, Wu Ziqian, Yuan Mengqi, et al. Analysis of combustible gas leakage characteristics of urban inspection Wells based on real-time monitoring data [J]. Journal of Safety and the Environment, 2019,19(2):569-575. [5] Liu Yongtao, Liu Jia, Li Yuhua, et al. Design and implementation of voice gas alarm device based on SIM900A[J]. Modern Electronic Technology, 2017,40(3):96- 99. [6] HOU Longfei, QIAN Xinming, DU Bingxuan,et al.Optimizationgas leak monitoring points distributed underground[J].Journal of Loss Prevention in the Processlndustries.2017.47:95-103. [7] Lin Haifei, Gao Fan, Yan Min, et al. PSO-BP neural network prediction model and application [J]. Chinese Journal of Safety Sciences, 2020,30(9):80-87. [8] Zheng Xiaoliang, Lai Wenhao, Xue Sheng. Application of MI and SVM algorithm in coal and gas outburst projection[J]. Chinese Journal of Safety Science, 2021,31(1):75-80. [9] Wang Xinying, Zhang Ruicheng, Zhang Huiran, et al. Keras application in the fault diagnosis of gas pipeline valves[J]. Fire Protection Science and Technology, 2020,39(4):541-546. [10] Qian Heng, Yu Huiqun, Fan Guisheng. Gas load prediction method based on incremental random forest[J].Journal of East China University of Science and Technology: Natural Science Edition, 2019,45(1):133-139. [11] ABDULLA MHERZALLAH R.Probabilistic multiple model neural network based leak detection system:experimental study[J].Journal of Loss Prevention in the Process Industries,2015, 36:30-38. [12] Wang Zhiyong, Gou Jun, Guo Yong, et al. Research on the temperature change caused by gas pipeline leakage[J].Journal of University of Electronic Science and Technology,2015,44(2):306-310. [13] Zhou Xiangyang, Jia Yuan. Fuzzy/PID compound control for aerial remote sensing inertial stabilization platform[J]. Journal of Instrumentation, 2016,37(11):2545-2554. [14] PRECUP R E,HELLENDOORN H.A survey on industrial applications of fuzzy control[J].Computers Industry,2011,62(3):213-266. [15] XIE Chengyu,CHAO Lei,QIN Yaquang,et al.Using a stochastic forest prediction model to predict the hazardous gas concentration in a one-way roadway[J].AIP Advances 2020.10(11):DO1:10.1063/5.0025594. [16] Xu Juan, Chen Shizhen, He Yangjian, et al. Research on the adaptive control strategy of the balanced head based on fuzzy PID[J]. Journal of Electronic Measurement and Instrumentation, 2016,30(6):895-920.