Research on WSN Time Synchronization Algorithm Based on Smart Campus

The realization of the collection, transmission and processing of information is the three basic elements of a smart campus, among which data collection and transmission are inseparable from the participation of wireless sensor networks. In particular, the geographical area of the campus of colleges and universities is relatively large, the population is relatively dense, and the mobility and contact rate of personnel are high. Higher requirements are put forward for intelligent teaching management and campus safety management and control. In particular, the current large-scale outbreak of the new tube virus has been basically under control in our country, but because of the characteristics of college campuses, it is more likely to become a disaster area. Therefore, a large number of sensor nodes (monitoring, temperature, smoke, alarm, etc.) are deployed in the campus, and the emergency information of the school can be fed back and processed in time through the sensor network, thereby ensuring the safety of the campus. To build a large-scale sensor network, many technical issues must be considered. Among them, the time synchronization algorithm that can reduce network power consumption is one of the key technical indicators. This paper proposes time synchronization algorithm ideas from two aspects of cluster head synchronization and intra-cluster synchronization. It is applied to the time synchronization process of WSN nodes to reduce the energy consumption of WSN sensor nodes in smart campuses, thereby increasing the robustness of WSN networks.


Sensor time synchronization problem in Wisdom campus.
The perception foundation of a smart campus is inseparable from the Internet of Things technology, The wireless sensor network is the core of data perception and transmission in the IoT system, Because a large amount of data used in the smart campus for acquisition of teaching management, security monitoring, disaster warning and other data perception and transmission must be completed by WSN, That is, a large number of sensor nodes must be able to work together, Work together. Because WSN is a distributed system, Time synchronization is a key issue that all distributed systems need to consider and solve, The information collected by sensor nodes contains time and space related content, Therefore, each node must be able to achieve mutual cooperation, data fusion, cooperative sleep and other basic assistance relations, These are all based on precise time synchronization. The current mainstream time synchronization mechanism generally uses the Global Positioning System, PS, The time synchronization accuracy of nanoseconds can be achieved through satellites, But the factors of volume and cost are not suitable for WSN environment. Network time protocol is also a widely used time synchronization method, But it also has a fixed topology, The energy utilization rate is not high, High construction cost is also not suitable for WSN.Considering that the main energy consumption in WSN is in the communication phase of data transmission and reception, the power consumption of the node itself is very low and only accounts for about 5% of the total power consumption. According to these characteristics, many scholars have proposed their own time synchronization algorithm; however, in terms of reducing power consumption, it still cannot fully meet the energy-saving requirements of WSN.

Time synchronization impact factor
The main influencing factor of time synchronization error in WSN comes from the time delay generated during the transmission of time synchronization packets. The analysis shows that the time delay in the synchronization process is divided into the following 6 types:

Basic strategy to reduce time synchronization delay
(1) Improve the time synchronization algorithm to reduce the time delay in the transmission, transmission and reception of time synchronization data packets, To reduce time deviation.
(2) Through mathematical methods (Such as linear regression, maximum likelihood estimation, Bayesian estimation and other methods) Analyze the time offset generated during time synchronization, So as to calculate a more accurate time.
(3) Combining the hierarchical idea with the time synchronization mechanism makes the synchronization message transmission path optimal, reduces the accumulation of errors caused by the data information transmission process, and finally improves the accuracy of the algorithm. Using hierarchical methods to synchronize node time reduce the distance and number of synchronized time data packets, thereby reducing time deviation, and error accumulation caused by data information transmission, improving time accuracy, and reducing energy consumption during time synchronization.

Comparison of mainstream algorithms
Based on WSN features, At present, the more common time synchronization algorithms include RBS algorithm, TPSN algorithm, Many-Sync algorithm, FTSP algorithm, etc. Table 2 compares the above several time synchronization algorithms: (1) time delay, Time delay determines the accuracy of synchronization, The synchronization accuracy is the key index of synchronization algorithm performance. The time delay in WSN includes: Time delay of sending, transmitting, receiving and processing, Eliminating these delays is the first problem that the time synchronization algorithm must solve.
(2) Reduce energy consumption, Most of the sensor nodes in WSN are one-time deployment, Its power supply is basically guaranteed by batteries, So saving energy is a very important link, Especially for the energy-saving design of the communication module is the core, Because 95% of energy consumption occurs in the process of data communication.
(3) Scalability, WSN is a dynamically scalable network, His topology is not fixed, This determines that the scalability of the entire network node must be considered when the algorithm is designed, So as to ensure the accuracy of time synchronization.

Cluster head election algorithm
During the establishment of WSN, A very important link is node clustering, Efficient node clustering algorithm can greatly reduce network overhead and improve data fusion. Here we use DEEC (Distributed Energy Efficient Clustering Algorithm,), The cluster head election strategy is adopted, By initializing for each node、the remaining energy judgment to select the cluster head, In other words, the larger the remaining energy, the more likely it is to become a cluster head, That is, the algorithm selects cluster heads according to the energy. Specifically, when using the DEEC algorithm to select cluster heads, All nodes in the network will be randomly selected according to a certain period, It's a random number between 0 and 1, If this number is less than This, it is the cluster head, The cluster head broadcasts within the capacity, The node that receives the message joins the cluster. If messages sent by two or more cluster heads are received at the same time, the strongest cluster is selected according to the signal strength. Is calculated as follows: In formula 1, Represents the proportion of cluster head nodes to all nodes, Indicates the number of election rounds, It means that there is a set of nodes that have been cluster heads in the last 1/P round.

Classical network hierarchy algorithm
Step1 Cluster the network

采用DEEC算法
Step2 Determine the root node and set the level to 0 Step3 The root node broadcasts the layer construction information, sends the layer number and ID message, and the cluster head layer number of all messages that receive the layer establishment message is +1. Step4 The cluster head of layer number 1 broadcasts its layer number and ID, and the cluster head node that receives the message updates the layer number+1 Whether its own level number is less than the level number of the received message Step5 All cluster heads have a layer number to form a layer 是 否 Figure 1 WSN Hierarchical Discovery Model Figure 2 Network level topology diagram Use the idea of clustering to establish the WSN level, the root node (Sink) broadcasts its 0 level and ID information, the receiving cluster head is updated to 1 level, and the level and ID information are broadcasted continuously. The received cluster head node level number is +1, all nodes are promoted and updated in turn, and the hierarchy is established. The specific process is shown in Figure 1 and

Algorithm optimization
The analysis of the classic synchronization algorithm shows that different time synchronization strategies are used between the cluster head and the nodes in the cluster. Cluster head synchronization: Because the cluster head itself is the time reference node of the lower layer, the error time will be accumulated during the synchronization process. It is necessary to adopt mathematical methods to reduce the error and improve the synchronization accuracy. Intra-cluster synchronization: When nodes in the cluster perform synchronization operations with each other, they can monitor channels randomly to achieve time synchronization with cluster heads, reduce redundant communication overhead, and reduce energy consumption.

Cluster head synchronization algorithm design.
Here we use the mathematical expression of Bayesian estimation based on the classic algorithm to reduce the time error accumulated by the cluster head and provide synchronization accuracy. Optimized cluster head synchronization can be achieved through the following steps: (1) Assume that the nth node obtains the synchronization time of the cluster head, this time point is ; and is the real time of the node obtained by Bayesian estimation; assumes is the use of Bayesian estimation the real time of the parent level node of the n node obtained by Si's estimation.
(2)The error between the synchronization time of n nodes and the real time satisfies the normal distributionN(0, ).
(3)Bayesian estimation after optimization: N( , ).The parameters are calculated by Bayesian estimation theory: (2) After the cluster head node is optimized by the mathematical expression of Bayesian estimation, the synchronization process is shown in Figure 3: Figure 3 Bayesian estimation optimizes cluster head process 3.3.2. In-cluster synchronization algorithm design. In order to reduce the energy overhead in the time synchronization process, this paper adopts the synchronization method of channel monitoring of members in the cluster, which greatly reduces the energy consumption of data packets during the receiving and sending process, and reduces the amount of receiving and sending to achieve the goal of energy saving. The specific implementation ideas are as follows. We use a model of 4 nodes in the cluster, as shown in Figure 4: Figure 4 Example diagrams of single-hop nodes in a cluster If node B sends a synchronization request to cluster head S, numbers A and C will obtain the time of node B after listening to the information. If the S node responds to the B number, the A and C numbers can also monitor the information and obtain the time information of the cluster head node. Therefore, this algorithm can achieve the goal of not requiring all nodes to send synchronization requests, but still obtaining time information. It only needs to select node B to send the request, which can significantly reduce communication overhead. The time relationship between node B and cluster head S node can be obtained： + ∆ + (5) In the formula, SB represents the time deviation value between the cluster head node S and the node B to be synchronized, and d represents the synchronization delay. Among them, the clock deviation ∆ between the cluster head and the node to be synchronized can be expressed by the following formula： ∆ = ( ) ( ) (6) In the whole process, the nodes A and C to be synchronized can obtain the time deviation between them and the cluster head node S through the information recorded by them, which can be expressed by the following formula: In the formula, ∆ and ∆ The meanings of the representatives are the time deviations between the cluster head node S, the node A and the node C, respectively. The meanings of and are the local clocks of the cluster head node S, node A and node Cat time 2 respectively.
When calculating the node clock, due to errors such as time deviation and propagation delay, the time must be corrected. Since the member nodes select the cluster head node according to the strength of the received cluster head broadcast signal during clustering, it is considered that the member node is closer to the cluster head, and its distance difference is small, and it is set as a fixed average d. Therefore, the corrected node times of A, B, and C are recorded as 、 、 , and calculated with the following formula: 4. Overall simulation of the algorithm Use MATLAB tools to simulate the improved optimization algorithm and classic algorithm. In the process of time synchronization, the number of data packets exchanged before and after the algorithm is improved and the energy consumption are used as comparison conditions to verify the simulation results of the optimized algorithm and the classic algorithm. In the experiment, the behavior of increasing the number of selected sensor nodes is simulated (the number of nodes is 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100). It can be seen from Figure 5 and Figure 6 that as the number of nodes increases, the number of data packets sent and received and the energy consumption of the optimized algorithm are smaller than those of the classic algorithm.   Figure 6 Energy consumption comparison Because the energy consumption in WSN is mainly concentrated in the data exchange process, the improved algorithm in this paper also reduces the energy consumption by reducing redundant data exchange. It can be seen through experiments that the time synchronization process using the new algorithm significantly reduces the data exchange process. The number of times, especially with the increase of experimental nodes, the effect is particularly obvious, which effectively proves that the optimization algorithm can significantly reduce the energy consumption of WSN. 5 conclusions Through analysis and calculation, the optimization ideas for cluster head and intra-cluster time synchronization algorithm proposed in the article can reduce the information transmission in the time synchronization process through cluster head layering and channel monitoring, thereby effectively reducing the energy consumption of WSN. In the next step of research, we will continue to study to reduce the time synchronization energy consumption of sensor nodes in the campus environment while ensuring the time accuracy of the algorithm, and to improve the robustness of the smart campus WSN system.