Edge Computing-Based ERBS Time Synchronization Algorithm in WSNs

. In the practical application of large-scale photovoltaic module monitoring, adopting wireless sensor network (WSN) technology is a method worth researching. With increasing nodes in the wireless sensor network, widely existing clock skew, increased geometrically, is bringing about greater energy consumption. Due to the random distribution of nodes, in order to improve the transmission e ﬃ ciency and reduce the computational load of the coordinator, the node processor needs to the use edge computing for preliminary analysis. This paper puts forward an improved energy-e ﬃ cient reference broadcast synchronization algorithm (ERBS). This algorithm ﬁ rstly calculates the average phase o ﬀ set of nonadjacent nodes in the network after receiving a message. It then uses the least square method to solve the clock skew to achieve high-precision synchronization of the whole network. Simulation results show that compared with RBS, the time synchronization precision of ERBS is greatly improved and synchronization times are greatly reduced, decreasing energy consumption signi ﬁ cantly.


Introduction
With the development of microelectromechanical system (MEMS), wireless communications, Internet of Things, big data, and AI transforming distributed sensing, edge computing, and communication into wireless sensor nodes at a low cost and low power consumption is becoming the focus of research. These sensor nodes transmit data packets and form the network via multihop communication collaboration, which has been widely used in home appliance automation, military surveillance, environment, and human health monitoring [1][2][3]. However, in most practical applications, wireless sensor networks have some limitations such as limited energy, unreliability, and large-scale sensor nodes. The study on time synchronization protocol with effective energy and time synchronization precision is one of the key points in the current research [4,5]. Clock synchronization is a basic service that provides the concept of common time in any distributed system. In particular, in different application environments, wireless sensor networks need clock synchronization of different precisions because it needs to provide a common time base for different nodes to handle the distributed tasks. The precision of time synchronization is necessary for various tasks including data fusion, locating and tracking power management, and effective media access control [6]. As sensor network nodes are used operationally at once and will be in operation for a long time after deployment, it is common to periodically set sensor network nodes to sleep mode to save battery power. Maintaining a relative time base is very important for waking up sensor nodes so that the success rate of data exchange can be improved. Therefore, a simple and efficient clock synchronization mechanism is likely to be used, where all timestamps use the same time base instead of multiple local clocks. For such a synchronization protocol, the two most important parameters that conflict with each other are high synchronization precision and low power consumption. In many applications, minimum synchronization errors must be maintained, needing resynchronization start-ups many times, increasing power consumption. Therefore, it is necessary to balance synchronization precision and energy consumption in the application.
Edge computing refers to an open platform integrating network, computing storage and application core capabilities at the edge of the network near the object or data source to provide edge intelligent services nearby, so as to meet the key requirements of industry digitization in terms of agile connection, real-time business, data optimization, application intelligence, security, and privacy protection. In terms of privacy protection, based on bilinear pairing and Paillier homomorphic encryption, Zhao et al. designed a data aggregation scheme for edge computing. The scheme can not only realize the batch processing of data but also protect the integrity and source authentication of vehicle organization network data. It can improve the network data processing efficiency and reduce communication costs while protecting users [7]. Based on the consideration of the safety of automatic driving technology, Xiong et al. proposed an IDP architecture for VANET, which has a high detection accuracy and high efficiency of data processing, and can improve the safety of automatic driving. The effectiveness of its architecture in preventing VANET intrusion in a complex environment is verified by a case study [8]. Considering the security of point-to-point transaction, Nawaz et al. built a concept verification intelligent contract platform by using edge computing technology. Compared with other platforms, the intelligent contract platform does not need intermediary in data transaction and can reduce the space occupied by it as much as possible under the premise of ensuring the ownership of data and user privacy [9]. In order to improve the computational efficiency, Wu et al. proposed an online optimization algorithm based on device data analysis, maximizing fairness and throughput balance and using Lyapunov and convex optimization to improve the effectiveness of resource allocation through numerical simulation, aiming at the randomness of wireless mobile edge traffic arrival, the time coupling of uplink and downlink decision-making, and the incompleteness of system state knowledge [10]. In view of the delay problem of terminal equipment processing dense data, on the basis of multiaccess edge calculation method, Li et al. through the establishment of mixed integer nonlinear programming model, and then using genetic algorithm to optimize, the stable convergence solution was obtained, which improved the data calculation efficiency of terminal equipment and effectively reduced the energy consumption of equipment [11]. Zakarya et al. put forward the resource management technology of game theory to improve the efficiency of data processing and effectively reduce the cost of equipment and energy consumption [12]. Zeng et al. proposed a fast search algorithm for the optimal pricing strategy of vehicle edge computing server based on the genetic algorithm by analyzing the interaction between the vehicle and edge computing server. Through simulation and comparison with other schemes, the efficiency of the algorithm was verified and the calculation cost was reduced [13,14]. In real-time business, Zhai and others proposed a service framework based on environment and resource constraints and a dynamic edge service migration algorithm. Through modeling and simulation, the temperature of the service framework and the effectiveness of the algorithm in reducing traffic were verified. However, its algorithm also has certain limitations. The data migration process has a certain delay, and the migration process will consume corresponding resources, which will limit the efficiency of data migration to a certain extent [15]. Arunan et al. introduced a self-adaptive feature extraction fault detection and fault identification protection scheme based on edge calculation feature extraction for monitoring fault current of a microgrid. Through simulation and comparison, the effectiveness and strong noise resistance of this method in power grid protection are verified [16,17]. On the basis of pervasive edge computing, Pei and others proposed a nonorthogonal multipervasive edge computing power allocation framework and a total power optimization algorithm for the internet of vehicles. This framework can minimize the system delay, and the effectiveness of the optimization algorithm is verified by simulation analysis [18]. Quan et al. proposed a multiagent deep reinforcement learning algorithm based on the delay problem of vehicle edge computing. By maximizing the distributed communication, computing, and path planning, the scalability of the algorithm was verified by experiments, which reduced the service delay and data migration cost [19,20].
With the expansion of WSN, the number of network nodes has increased dramatically. A feature of traditional reference broadcast synchronization (RBS) algorithms is that error sources are concentrated mainly in the processing time of receiving nodes and higher synchronization precision [21][22][23], but with the increasing network overhead, it will influence the energy consumption of the whole system [24,25]. This paper will complete the collection and transmission of parameters using WSN in the process of photovoltaic module monitoring. Photovoltaic module monitoring makes more demands on nodes as the source node is applied as the receiver in the photovoltaic module. Therefore, an improved ERBS algorithm is proposed based on the analysis of the RBS algorithm. The ERBS algorithm firstly calculates the average phase offset of nonadjacent nodes in the subnet of photovoltaic module monitoring after receiving a message. Then, it will solve the clock skew by the least square method. In the process of solving clock skew, the influence of environmental temperature will be considered in photovoltaic module monitoring and the synchronization precision of the whole network can be achieved, providing the basis for photovoltaic module monitoring and fault diagnosis. Different applications have different requirements for various supporting technologies of WSN. This paper studies the WSN time synchronization method for photovoltaic module monitoring field. The proposed ERBS algorithm can effectively reduce network energy consumption and enhance the reliability of network time synchronization on the basis of ensuring synchronization accuracy. It can be applied in large-scale WSN construction.

Problem Description
RBS is a typical synchronization method based on a receiverreceiver mechanism. It can synchronize a set of child nodes 2 Wireless Communications and Mobile Computing that receive a beacon message from a common sender (the reference node is the parent node). Figure 1 is a schematic diagram of the RBS synchronization mechanism. A parent node P and other nodes, A and B, within the communication range of the parent node will complete a group of synchronization. As shown in Figure 2, it is assumed that the parent node (P) periodically sends reference broadcast beacons. Nodes A and B receive the i th beacon sent by the parent node (P) at local time T Að2,iÞ and T Bð2,iÞ , respectively. Nodes A and B record the arrival time of the broadcast group and exchange timestamps with each other.
Assuming that X i ðPAÞ represents an uncertain delaying part (random delay), d ðPAÞ represents the certain delaying part from node P to node A (propagation delay), then T Að2,iÞ can be recorded as where T 1,i is the sending time of the parent node and φ ðPAÞ and ω ðPAÞ are the clock phase offset and frequency offset of node A compared to parent node P. In the same method, the arrival time of node B is where d ðPBÞ , X i ðPBÞ , φ ðPBÞ , and ω ðPBÞ represent fixed delay, random delay, clock phase offset, and frequency offset of node B to the reference node, respectively. From formulas (1) and (2), we can get Among them φ ðBAÞ ≜ φ ðPBÞ − φ ðPAÞ and ω ðBAÞ ≜ ω ðPBÞ − ω ðPAÞ are phase offset and frequency offset of nodes A and B while receiving the i th broadcast group from the parent node, X i ðPAÞ and X i ðPBÞ are random variables of a normal distribution with a mean value of μ and variance of σ 2 /2. Elson et al. proved that after receiving the reference message, the phase offset of the local time difference between any two receiving nodes follows Gaussian distribution that μ = 0, σ = 11:1 μs [21].
The RBS algorithm uses the broadcast characteristics of the wireless channel to send multiple reference broadcast synchronization messages to the sender and the receiving nodes adjust their own time by calculating the local time difference of receiving synchronization messages and exchanging timestamps, so synchronization is achieved.
The main error source of RBS algorithms is the time delay of the receiver, and its biggest feature is to eliminate the sending time delay and access time delay of the reference broadcast message on the critical path from the sending node to the receiving node. Therefore, the time synchronization of the receiving node will be closer. While solving the synchronization problem of WSN, the accessing time of channels in the media access control (MAC) layer is the biggest source of error, so it is very important to further study the defects in the RBS algorithm and find an improved algorithm.

Design of ERBS Algorithm
Due to the characteristics of phase offset and frequency offset of the RBS algorithm [26,27], the realization of the ERBS algorithm can be divided into two steps. The first step is to estimate the uncertain phase offset and the second is to estimate the frequency offset of nodes. In estimating frequency offset, the influence of temperature on synchronization precision needs to be considered and then the overall evaluation can be conducted on the performances of the improved algorithm.
Clock drift is accumulated in one period, and random delay is closely related to timestamps. Figure 3 shows the relationship between synchronization error, clock skew, and random delay, which applies to discussions about the ERBS algorithm. In Figure 3, measurement modeling refers to the establishment of the functional relationship of the measurement model according to clock drift and random delay. Calculation of the estimated value refers to estimating the relationship between synchronization error and clock drift by linear regression based on the measurement model of timestamps. Taylor approximation expansion refers to the linearization of nonlinear calculations based on the relationship among synchronization error, clock drift, and random delay, which can reduce computational complexity and improve the execution efficiency of the algorithm on the premise of ensuring synchronization precision and energy consumption [28,29]. The absolute error refers to the phenomenon that the node may lead or lag the master node in the synchronization process, and the adoption of absolute error is to solve this problem. The analysis of the synchronization error source shown in Figure 3 provides effective support for the design of the ERBS algorithm.
In a WSN composed of photovoltaic module monitoring nodes, each monitoring subnet contains n + 1 nodes (generally set as 200 ≤ n ≤ 500) when the parent node of the subnet sends a message (mainly including the photovoltaic module ID, voltage, current, temperature, and timestamp). Under the application background, commonly used RBS algorithms require each node in the monitoring subnet to exchange information with other n nodes and then calculate the time difference by exchanging information. With the increase of 3 Wireless Communications and Mobile Computing n, to achieve time synchronization of the whole network, the amount of information exchanging between nodes has increased sharply, putting enormous pressure on the whole WSN communication overhead. Aiming to increase energy consumption caused by synchronization data interaction in the RBS algorithm, the ERBS algorithm was improved accordingly.
The specific implementation steps of the ERBS algorithm are as follows:  Figure 4 shows the estimation of the phase offset of three receiving nodes. Compared to the traditional RBS algorithm with an increasing number of nodes and sent messages, the increase of algorithm execution time for the ERBS algorithm is not obvious, the growth of algorithm complexity is limited, and the increase of the network's energy consumption is limited. The main reason is that the ERBS algorithm gave up any information interaction between two nodes, and it did not focus on the information transmission of nonadjacent nodes, effectively saving the amount of data interaction and improving the energy efficiency of time synchronization [30,31].

Wireless Communications and Mobile Computing
While estimating the phase offset, the focus is to calculate two nonadjacent nodes. Assuming that as p and q, p ∈ n, q ∈ n , and p − q ≠ ±1: because it is nonadjacent, T r,k represents the recorded local time, while node r receiving the information packet k, among that r ∈ n. m represents the amount of information, and φ represents the phase offset.
Otherwise, according to literature [21], assuming that the phase offset follows Gaussian distribution with an average of 0 and variance of σ n if the condition is φ then the measurement value of phase offset is x = ½x 1 , x 2 , ⋯x N T , and the conditional probability density function is Then, the probability density function φ is We assume that the condition is When C is the minimum value, the right side integral is the maximum. If b φ is the estimated value of the phase offset, then the necessary condition for the maximum value is Formula (8) is the biggest posterior equation of φ: By getting the logarithm towards formulas (9) and (10) and partial derivative of φ, the solution definition of b φ is as follows: Because φ conforms to the Gaussian distribution, the equation above can be simplified as After further simplifying, we can get Formula (14) is the estimated value of phase offset.

Estimation of Clock Frequency
Offset. The clock drift of WSN nodes is caused by changes in the frequency of the crystal oscillator. The counter will reduce by one for each oscillation. When it is reduced to 0, one interrupt process is generated, which can realize the sending of a packet. During this process, if the crystal oscillator has a larger clock skew, the timestamp carried by the sending packet will have a large error, resulting in the network time synchronization generating an offset value, which is more than a set. After realizing one interrupt process, the counter will reload the starting value from the hold register. It is assumed ρ is the maximum drift speed; if two clocks drift in opposite directions relative to UTC, the possible difference value is 2ρΔt during the time Δt after synchronization. For a WSN operating system, assuming the difference between every two clocks does not exceed δ, then it must resynchronize at least within δ/2ρ. In this algorithm, the local time of node i at the physical time

Wireless Communications and Mobile Computing t is defined as
f 0 is nominal frequency, f i ðtÞ is the real frequency of the crystal oscillator, in usual cases that f i ðtÞ ≠ 1; σ i is the time offset of node i accumulated before moment t; and t and t 0 are real physical times. In the short term, the frequency of the crystal oscillator is fixed, assuming that f i ðtÞ = ν, we can get a more simplified time model.
where ν represents the frequency drift of nodes and σ represents the initial phase offset of nodes. Based on formula (16), a linear model is adopted to realize parametric fitting through the least square method.
By fitting parameter r like formula (19), the compensation of clock frequency drift can be completed.
The above discussion is one that assumes that the output frequency of the crystal oscillator has a stabilized value. The reality is that, no matter what the model the oscillator is, it has its clock parameters. For example, the clock frequency of a quartz crystal oscillator changes by 40 ppm, which means that in every second the derivation of the clock will reach 40 ms due to different nodes, that is to say, each oscillator has different migration parameters of -20~20 ppm. This is similar to the core processor adopted in the photovoltaic modules monitoring system; it externally uses a 32 kHz crystal oscillator that deviates between 5 and approximately 30 ppm.
Additionally, the temperature and humidity of the environment, vibration, and the working voltage of the node influence the crystal oscillator, especially in the working environment of photovoltaic modules, where the performance of temperature parameters are very obvious. Figure 5 shows changes in temperature over time (the curve monitoring in situ temperature in a photovoltaic system from 8.00 a.m. to 6.00 p.m.). The sensor network nodes integrated with the components are very sensitive to the temperature parameter and in time synchronization; it is necessary to consider the influence of temperature on the precision of synchronization.
Based on the above discussion, the relational expression between clock skew and the temperature is shown as where s i t0 is the clock skew of the reference temperature of node i at moment t 0 , k i is the shift coefficient of the node, t i ½n is the temperature of node i in the n th sampling interval, ω i ½n is the random shift noise brought by other environmental elements and quantization error, and it follows the Nð0, σ 2 ω Þ normal distribution [32,33]. In this paper, every sensor node has a temperature sensor that can measure the realtime environmental temperature. According to the parameter manual of the crystal oscillator, you can check the influence of reference temperature on the clock skew. However, due to different photovoltaic modules, different nodes have a different clock skew and drift coefficient that is related to the air humidity, the node's supply voltage, and the life of the crystal oscillator. In different application backgrounds, these factors need to adopt different calibration methods.
Considering the influence of temperature on clock frequency offset, to obtain complete-time synchronization, it is necessary to estimate the clock frequency offset based on the estimation of the clock phase offset. Based on formula (3) in the assumed model of clock frequency offset, T Bð2,iÞ is known and the set of the observed quantity of delay between node A and node B can be expressed as follows: Among them,X k ′ = ωX k , Y k ′ = ωY k , and d ′ = ωd, after further observation, the Gaussian delay model is used to conduct a joint estimation of phase offset and frequency offset towards the information model described in equations (21) and (22), and the following expressions can be obtained:

Simulation Environment and Settings of Parameters.
To verify the effectiveness of the improved ERBS algorithm, the mathematical model of node clocks has been established using the software environment MATLAB, whose parameter of the crystal oscillator is -30~30 ppm. The interrupting counting value of nodes is 921600 per second and there are three nodes, the parent node P, node A, and node B. The round number of synchronizations changes from 2 to approximately 50 and the simulations are synchronized 1000 times. After 1000 repeated experiments, the average synchronization error value can be obtained. Meanwhile, a synchronous experimental test platform with one reference node and two receiving nodes is set up on-site. The experimental time is from 8.00 a.m. to 6.00 p.m. The curve of temperature changes during the experiment is shown in Figure 5.
The reference node broadcasts a beacon periodically every second. The receiving node will timestamp the received beacon, transmit the result to the coordinator, and then connect with the PC via RS232 for real-time processing of online data. After the broadcasting node sends the data, the receiving node returns one beacon immediately. The coordinator will collect all the beacons with timestamps and analyze the intervals of beacons, the numbers of every synchronization    7 Wireless Communications and Mobile Computing beacon, and measurement numbers. To eliminate the influence of different datasets on the synchronization algorithm, the measurement of synchronization errors will adopt the same standard of beacon including the ID of photovoltaic modules, voltage, current, temperature, timestamps, and other data. To open the timestamps at the MAC layer, CC530 is used to offer initial frame data and chip timers are used to produce local timestamps.

Analysis of Time Synchronization Precision.
While setting rounds of synchronization n that change from 2 to approximately 50, the average synchronization errors of the RBS and ERBS algorithms are shown in Figure 6. The average synchronization errors of the RBS and ERBS algorithms are 40~50 μs and 10~20 μs, respectively. The analysis found that the average synchronization errors of the RBS and ERBS algorithms are not affected much by n. The main reason is that these two algorithms only use data with a single-wheel timestamp to calculate the time deviation value. In general, the ERBS algorithm shows obvious improvement in synchronization precision. Table 1 shows the single-hop synchronization precision of the RBS and ERBS algorithms when the round of synchronization is n = 20. The ERBS algorithm has the lowest error average and best stability of synchronization precision mainly because it calculates the average phase offset towards nonadjacent nodes, which makes full use of statistic features of time synchronization data, reducing the complexity of the operation process.
To further analyze the performances of the algorithm, if there is no timestamp on the MAC layer, Figure 7 shows the average synchronization error. Due to the large access delay and the software operating delay of the sending node, compared with Figure 6, the accuracy of the algorithm decreases to varying degrees, with an increase of about 10 μs. However, compared with the RBS algorithm, the increase of the ERBS algorithm's average errors is the smallest. The simulation results show that random delay and operating system delay can be reduced by adding timestamps at the MAC layer, and this method influences clock skew so that the compensation of clock skew can be realized. Of course, in the network of too large scale, this algorithm may have the limitation of serious precision decline, mainly because it saves too much data exchange between adjacent nodes, and the statistical characteristics of time synchronization data and the method of adding timestamp in MAC layer are not enough to solve this problem, so it is not necessarily applicable in large-scale WSN network.
In the process of wireless transmission, the packet loss rate is always an important factor affecting synchronization precision. The influence of bit error rates in different groups on synchronization precision is simulated by the experimental addition of timestamps at MAC and analyzing the change regulations between synchronization precision and packet loss rate. Figure 8 shows the synchronization precision in cases of different packet loss rates. Observation found that with the increase of packet loss rate, the average error of the RBS algorithm increased significantly because it depends on the surrounding nodes. When the packet loss rate of data reaches 10%, the average synchronization error increases more than 20 times. The results can be a good reference for the design of a photovoltaic module monitoring system.

Analysis of the Minimum Mean Square Error of Clock
Skew. The ultimate goal of parameter estimation is to look for the reachable minimum mean square error to provide support for the design of an estimator. However, the best mean squared error (MSE) design in theories is very difficult. Figure 9 shows the curves between phase offset MSE of the RBS and ERBS algorithms and rounds of synchronization and variance.

Wireless Communications and Mobile Computing
As can be seen from Figure 9, when n increases and the variance decreases, the MSE of the clock phase offset gradually decreases. This is because when n increases, a more local data timestamp of nodes participates in the estimation of phase offset, thus reducing system synchronization error. Figure 10 is the relationship between clock frequency offset MSE and rounds of synchronization and synchronous interval cycles whose variance is one. As can be seen from the figure, with the increase of round synchronization n and synchronous interval cycles, the MSE of the clock frequency gradually decreases. However, the increase of synchronization rounds will lead to greater message overhead, so the increase in the synchronous interval cycle can also reduce synchronization efficiency. Therefore, it is necessary to make overall considerations and find a balance point between the MSE of clock frequency, rounds of synchronization, and synchronous interval cycles. As mentioned above, in Figure 11, when the MSE of clock frequency decreases, it is still necessary to increase the rounds of synchronization n and the synchronous interval cycles, which reflect the importance of considering these factors from other aspects.  9 Wireless Communications and Mobile Computing performs better. Figure 12 quantitatively analyzes the relationship between the number of nodes and the synchronization data packets in a synchronization cycle. In the case of the same number of nodes, data packets transmitted synchronously by the ERBS algorithm are fewer than that of the RBS algorithm, thus achieving better energy efficiency.
To further analyze the energy consumption of the RBS and ERBS algorithms, simulations with 300 nodes have been conducted. The result is as shown in Figure 13. The analysis found that with the increase in nodes, the energy consumption of both algorithms increased. However, compared with the RBS algorithm, the increase of energy consumption of the ERBS algorithm was smaller and was only one-third of the RBS. This is due to the fact that the information exchange between adjacent nodes is not considered, thus reducing the number of data exchange nodes and saving energy consumption. When the number of nodes increases, the energy consumption of the ERBS algorithm increases steadily, which is beneficial in solving the problem of large-scale WSN time synchronization.

Conclusion
Aiming at the practical application background of photovoltaic module state monitoring, this paper analyzes and discusses the problems with the RBS algorithm. Though the RBS algorithm has high synchronization precision, it is costly in terms of the network. This paper puts forward an energyefficient WSN time synchronization algorithm, ERBS. The phase offset and frequency offset of the nodes can be solved by estimating signal parameters, effectively saving partial network expenses. The differences between the ERBS and RBS algorithms are synchronization precision, the minimum mean square error of clock skew, and energy consumption; this was put forward by a MATLAB simulation platform through comparison and validation. Simulation results show that the synchronization precision of the ERBS algorithm is 27.17 μs higher than that of the RBS algorithm. Compared with the RBS algorithm, the improved ERBS algorithm can be applied to the synchronous topology structure of largescale photovoltaic module monitoring with higher synchronization precision and lower energy consumption. After further expansion, it can be applied to other large-scale state monitoring scenarios [34,35].

Data Availability
The data used to support the findings of this study are available from the corresponding author upon reasonable request.

Conflicts of Interest
The authors declare that there is no conflict of interest regarding the publication of this article.