Adaptive Compensation for Time-Slotted Synchronization in Wireless Sensor Network

Since time division multiple access (TDMA) is employed to reduce power consumption, time synchronization is critically important for wireless sensor networks. Packet-based clock correction is one of main methods to maintain synchronization among nodes. However, in many real cases, such as industrial equipment monitoring and diagnosis, there is no need to exchange messages during relatively long time, while highly accurate time synchronization has to be maintained, which results in that additional packets have to be exchanged specifically for synchronization purpose. For addressing this problem, an adaptive compensation method is proposed in this paper to achieve a high synchronization precision without exchanging message frequently. We proved that the adaptive compensation method can achieve a high synchronization precision with much fewer packet exchanges. In addition, the performance of the proposed scheme has been evaluated in three different experimental settings. In the indoor experiment, compared with the synchronization method without using compensation, 98% of the synchronizing packets can be eliminated while maintaining synchronization precision at 100 μs. In the outdoor experiment with higher temperature fluctuation, 80% of the packets can be eliminated with 100 μs synchronization precision. In the case of sudden temperature changes of more than 10 ° C, the proposed compensation packet frequency regresses to the frequency of the synchronization method without compensation.


Introduction
As most wireless sensor networks (WSNs) [1] work with battery power, power consumption becomes a critical constraint for networks' nodes.Since radio transmitting is major consumer of a node's energy [2], it is important to minimize the radio-up time when designing WSNs.A good design for a low power WSN should keep the radio off whenever possible and only turn on radio when actively transmitting or receiving packets.
To achieve this goal, synchronization is required.Time synchronization makes two nodes share the same sense of time; thus they can coordinate their radio activity to achieve low power.This is particularly important for battery equipped devices used for industrial application, which usually require more than 5 years of operation life.As one of such synchronization techniques, time slotted channel hopping (TSCH) is adopted by major industrial low power wireless standards such as WirelessHART [3], ISA100 [4], and IEEE802.15.4e [5].
TSCH protocols use an agreed upon transmission schedule between two nodes.Figure 1 shows the case of TSCH in IEEE802.15.4e.Time is split into equal length time slots; the slot frame is defined as a constant number of slots repeated over time.Each slot has an absoluteslotnumber (ASN), which indicates how many slots have elapsed since the network was initialized.Once a node is synchronized, the communication by exchanging packets between pairs of nodes is scheduled for a specific time slot.All packets are transmitted exactly TxOffset after the beginning of a slot.To ensure that the packet is not missed when slight desynchronization happens, Guard Time is used to turn on the radio of the receiving node before the expected arrival of a packet.
Packet-based clock correction is one of main methods to maintain synchronization among nodes.Since packets are transmitted TxOffset after the beginning of a slot, every packet is implicitly timestamped at TxOffset after the beginning of a slot.A node synchronizes to its time parent Each node is scheduled to communicate at a specific slot.The packet is scheduled to be sent at TxOffset after the beginning of a slot.Nodes synchronize to their time parents by timestamping the reception of packets and comparing them to TxOffset.Guard Time is used to avoid missing an incoming transmission by turning on the radio of the receiving node before the expected arrival of a packet [5].
by timestamping arriving packets and comparing them with TxOffset.The accuracy of the timestamp is determined by the frequency of the crystal.A 32768 Hz crystal, typically in WSNs, is accurate with 1/32768, about 30 s.
Since clock drift will widen the synchronization error, nodes need to resynchronize frequently to maintain synchronization accuracy, which will cause bandwidth and energy consumption problems.Compensation is usually used to deal with such case.Nodes can stay synchronized through periodically adjusting the local clock at an opposite rate of drift.Many clock drift models are designed for compensation.Complicated models are heavy for a WSN node with limited resource and simple models make compensation inaccurate.In this paper, we propose a method to improve the accuracy of calculated drift through adjusting the interval of resynchronization, which is simple enough to be used in practice.This method, called Adaptive Compensation, is added to the implementation of the OpenWSN protocol stack [6] and used on real hardware.Though the implementation specifically uses IEEE802.15.4e as its MAC layer protocol, Adaptive Compensation should be available for any other slot-based MAC protocols.
In next section, we show some synchronization methods in WSNs and the difference between those methods and Adapative Compensation.Then we use equations to illustrate the problem Adaptive Compensation solved in Section 3. In Section 4, we describe a model of synchronization error using compensation and proposed Adaptive Compensation method.We implement our method based on OpenWSN's work in Section 5.In Section 6 we evaluate the performance of the proposed method in three different environments.Finally we make a conclusion from our work in Section 7.

Related Work
Time synchronization in wireless sensor network is a wellstudied field.Many algorithms for WSNs already exist.
Reference broadcast synchronization (RBS) [7] is a protocol in which synchronization happened between receivers.The sender broadcasts a packet to a set of receivers.The receivers record the timestamp when the packet was received and exchange the timestamps with other receivers in the synchronization set.RBS minimizes the undetermined delay from the sender side which improves the accuracy of synchronization.Time-sync protocol for sensor network (TPSN) [8] is a different protocol with RBS, which records the timestamp in the MAC layer at the sender side.Two communicating nodes exchange packets using a two-way method.This pairwise synchronization can remove the propagation delay.Flooding time synchronization protocol (FTSP) [9] records timestamp in the MAC layer at both the sender and receiver sides.It removes all kinds of undetermined delays except for propagation delay.The timestamp is added as a final step after encoding/decoding the SYNC byte so the node can achieve a high accuracy of time synchronization.TSCH protocol in IEEE802.15.4e just uses FTSP as its synchronization method.
Those synchronization protocols focus on high accuracy of synchronization when exchanging packets.To maintain such high accuracy they have to resynchronize frequently to deal with clock drift, which consumes a lot of energy and bandwidth.Some adaptive synchronization algorithms, through estimating drift, adjust the local clock to counteract the clock offset without exchanging packets for resynchronization.By modeling the clock drift of daytime, [10] presents an adaptive synchronization to deal with drift.However, the model is built based on offline measurement.It cannot handle the dynamical variation of drift.Self-correction clock, which is shown in [11], is another method that made a hardware clock which can do self-correction to deal with drift.This obviously increases the cost of node.
The Adaptive Compensation mechanism also focuses on how to maintain high accuracy without exchanging packets but using an advanced simple model.The simplest model for drift is averaging the clock offset in a period, which assumes that the drift is constant.This hypothesis is only true in several minutes or indoor environment.Furthermore, the accuracy of calculated drift is not enough to satisfy industry applications such as industrial equipment monitoring and diagnosis, which usually need to exchange packet infrequently.Additional packets are still required to be exchanged to maintain synchronization.However, averaging the clock offset in a period is simple enough to be used practically.Adaptive Compensation mechanism performs an iteration procedure based on this simple model to gradually increase accuracy of calculated drift.Using this accuracy-increased drift to adjust (compensate) on the local clock, a one-hour synchronization interval can be achieved for indoor case.A temperature sensor-based detective mechanism is also proposed in Adaptive Compensation to deal with the influence of temperature on clock drift.

Problem Definition
In general, compensation can be explained as periodically adjusting the local clock at a given rate, usually an estimated value of node's drift.For example, a node in a slotted network,  which has a 32768 Hz crystal with a drift of 10 ppm faster than its time parent's crystal, can keep synchronization by shortening its current time slot duration by one tick (30 s) every 3 seconds (Figure 2).Since the temperature is the main factor influencing clock drift [12], drift can be considered constant in shortterm or indoor environments where temperature fluctuations are small.In such environments, drift can be calculated by averaging a period of synchronization error as (1) shown.offset indicates the synchronization error, which is achieved by comparing the timestamp with TxOffset.Δ indicates the period since the last packet-based synchronization, called the synchronizing interval: The accuracy of offset is determined by the accuracy of the timestamp.A 32768 Hz crystal has a timestamp accuracy of 30 s.The calculated drift cannot counteract the real drift completely with such timestamp accuracy.Packet-based resynchronization is still required.The only effect is lengthening of the interval compared to synchronization without compensation.When Guard Time is given, the length of the resynchronization interval is determined by the accuracy of the calculated drift.One way to achieve higher accuracy is using a high frequency crystal.However a high frequency crystal itself would consume significant energy.Therefore, this solution is not suitable for the application in low power WSNs.
The offset achieved by comparing timestamp with TxOffset can be presented by real offset plus an error, where the error is smaller than one tick (2).Tick is a measurement of time which is determined by the frequency of the crystal.One tick for a 32768 Hz crystal equals 30 s or 1/32768 of a second.With (2), we substitute the offset in (1) and derive (3): As our goal is to improve the accuracy of drift, what we need to do is diminish the value of error/Δ in (3).Enlarging Δ is an obvious solution.Enlarging Δ can be explained as scheduling the next synchronizing packet to have a longer interval.However, excessively enlarging would make the synchronization error fall out of Guard Time before the next synchronization.The next question is how long the interval should be to avoid this falling out.In the following section, we will answer this question based on a model of synchronization error using compensation.

Adaptive Compensation
In this section, first we will show Adaptive Compensation in theory based on a model of synchronization error with compensation.Then we propose our Adaptive Compensation synchronization method.

Model of Synchronization Error with Compensation.
The model of synchronization error with compensation is depicted below (4).  and   indicate the real drift and calculated drift. indicates time. sync indicates synchronization error at .This error can be larger or smaller than zero, which means that the clock of node is in front of or behind its time parent.This model could be explained as that the inaccuracy of drift, which responds to (  −  ), will make synchronization error increase to  sync at : The key to answer the question is to know what time synhronization error will fall out of Guard Time.With this thought, we transform the model by exchanging the sides of  sync and  and replace  sync with Guard Time.As (5) shows, it is clear to see that  is the time when synchronization error will fall out of Guard Time.
As    −   should be smaller than 1 tick/Δ as shown in (6).By replacing   −   with 1 tick/Δ, we can derive an important inequality as (7) shows.This inequality means that the time point,  schedule , is earlier than the time when synchronization error falls out of Guard Time, which we can use to schedule next packet for synchronizing.Figure 3 depicts the meaning of (7) in practice.When a node is synchronizing at 1, it calculates the drift to its time parent by (1) and schedules next synchronizing packet at 2 to avoid falling out of Guard Time.When time comes to 2, the node will resynchronize and recalculate the drift by (1).Since the synchronizing interval (Δ) had expanded Guard Time/1 tick times, the error of calculated drift becomes smaller than previous calculated drift (error/Δ).This means that the calculated drift at 2 becomes more accurate than the drift calculated at 1 and real drift will be counteracted by compensation more accurately.As a result, the time when synchronization error increases to Guard Time would be further extended.A longer synchronizing interval can be used to schedule following synchronizing packet.
The procedure to calculate drift is an iteration procedure.The expanded synchronizing interval improves the accuracy of calculated drift.On the other hand, more accuracy of drift delays the time point at which synchronization error falls out of Guard Time, and thus synchronizing interval will be further expanded.
In the following section, we will discuss how nodes schedule their resynchronization packet according to (7) in practice and present a reboot mechanism based on temperature sensor to the temperature influence on clock drift.

Synchronization with Adaptive Compensation.
To use this Adaptive Compensation method in practice, two parameters are required: Initial Interval for synchronizing and Required Accuracy, or the length of Guard Time.Initial Interval is determined by Max Drift between two nodes and Guard Time.It can be calculated by (8).To typical 32768 Hz crystals, their drift between two crystals would not exceed 30 ppm.When Guard Time is set to 100 s, synchronization interval can be initialed as 3.3 seconds according to the following equation: When Required Accuracy is set to 100 s, we can expand the interval by 3.3 times if 32768 Hz crystal is used.In practice we can use a smaller value to avoid the slight fluctuation of drift.Since the expansion is exponential, smaller value will not reduce the performance of Adaptive Compensation.
When synchronization interval expands to some degree, the fluctuation of temperature will become more apparent.Crystal's drift will also fluctuate.In such case, (1) for calculating drift is not suitable yet.To deal with the influence of temperature, a reboot mechanism based on measurement of temperature is performed.
Using the equipped sensor, nodes can measure the temperature surrounding it periodically and compare it with the temperature which is recorded at last time when node exchanges packet for synchronization.Once nodes detect the fluctuation of temperature exceeding a threshold, it will send a packet to synchronize immediately and reset the synchronizing interval to initial value.Then Adaptive Compensation will start again.Setting the threshold to 2 ∘ C, in our experiments, can be tuned to match the crystals temperature sensitivity and the application requirements.Since nodes only need to store the temperature recorded at last time when exchanging packet for synchronization, it would not consume much energy to maintain this data.Also the power cost by sensing is quite small which need not 13 to be counted in.and packet-based synchronization defined in IEEE802.15.4e have already been implemented by OpenWSN.Since the synchronization of IEEE802.15.4e did not adopt compensation method yet, we add codes based on OpenWSN's implementation to make our compensation method work on IEEE802.15.4e.

Implementation
The hardware of this implementation is called GINA [13] platform which is made by Swarm Lab in UC Berkeley (Figure 4).GINA is a low-cost wireless node containing an MSP430F2618 [14] 16-bit microcontroller and a AT86RF231 [15] radio chip.An external crystal of 32768 Hz, with a drift of ±20 ppm, is used to provide a slot length of 10 ms.
When implementing Adaptive Compensation on GINA, four parts are needed.First is the calculation of drift.According to (1), offset and Δ are required.offset can be derived just by the synchronization of IEEE802.15.4e implemented by OpenWSN.Through absoluteslotnumber (ASN), nodes can get Δ counted by the number of elapsed time slots since last packet-based synchronization.Thus drift can be expressed by how many time slots are elapsed when two clocks move one tick apart.
Second is compensation.Since the drift is calculated by time slots, node can count the number of slots at the beginning of each slot.When the counter hits the value of calculated drift, the synchronized node will lengthen or shorten its current slot length by one tick for compensation.Another part is scheduling synchronizing packets.We can schedule the synchronizing packet with the timer in MSP430F2618.Once the timer fired, an interrupt is triggered to notify nodes to send a packet for resynchronization.The counter of timer will be reset to one time larger value which indicates next synchronizing interval.
The last part is reboot mechanism.There are kinds of sensor equipped on GINA, such as 3-axis gyroscope, 3-axis magnetometer, and temperature sensor.With the temperature sensor, we can detect the fluctuation of temperature and implement reboot mechanism on GINA.TMP20 [16], which is selected to be the temperature sensor of GINA, operates from −55 ∘ C to +130 ∘ C on a supply voltage of 2.7 V to 5.5 V with a supply current of 4 A.The deviation would be ±0.23 when temperature ranges from −10 ∘ C to +60 ∘ C. To both the temperature accuracy and energy efficiency, TMP20 can totally meet the application requirements.

Evaluation
To evaluate the performance of Adaptive Compensation, we did experiments in different scenarios with the implementation.As mentioned before that temperature is the main factor influencing drift, we define three scenarios to evaluate the performance of proposed method: constant temperature, temperature with daily fluctuation, and sudden change in temperature.Those scenarios with different fluctuation of temperature result in diversified performances for Adaptive Compensation.In this section, we describe the settings of those experiments and experimental results in the three scenarios, respectively.Through comparing the slot boundary between nodes A and B, we can record the synchronization error of each slot.Matlab is used for statistics and analysis of the performance of Adaptive Compensation.
The experimental synchronized node has a drift of 12 ppm.Synchronization accuracy of 100 s is needed to be maintained for the node.Synchronizing interval is initialed to 8 seconds and it would expand by 2 times when using Adaptive Compensation.The experimental scenarios and results are shown in Figures 6 and 7.

Constant Temperature.
To indoor environment, the temperature is usually considered as constant.As shown in Figure 6(a), temperature in 24 hours ranges from 25 ∘ C to 28 ∘ C and varies smoothly.In such environment, the temperature would not influence the drift of crystal.The indoor performance of Adaptive Compensation will be the best in three scenarios.resynchronizing interval to go up to few minutes when using improved compensation.The outdoor performance of Adaptive Compensation is discounted comparing with constant temperature scenarios.

Sudden Change in Temperature.
In some cases like industrial application, temperature may increase more than 10 ∘ C in less than one minute.To evaluate the performance of proposed method in such scenario, a hot-air gun was used to heat up synchronized node every 8 minutes (Figure 6(c)).
Because of the great influence on clock drift, frequently packet-based resynchronizations are required to maintain synchronization.In such case, the performance of Adaptive Compensation would regress to the synchronization without using compensation.The slope of fitting line corresponds to   −   in (4), which expresses the part of drift that was not counteracted by compensation.In Figure 7(a), the slope of fitting line became smaller and smaller since synchronizing interval became longer.In other words, the accuracy of calculated drift has been improved with expanded synchronizing interval.To indoor case, the synchronizing interval could increase to about one hour long.As the initial of synchronizing interval is set to 8 seconds, only 9 synchronizing packets are used during the period of one hour.If we only use packet-based synchronization, synchronizing packet needs to be sent about every 8 seconds to maintain synchronizing accuracy of 100 s.Thus 450 packets are required in one hour.98% packets could be eliminated by Adaptive Compensation method.

6.3.2.
Temperature with Daily Fluctuation.Since the fluctuation of temperature outdoor is heavier than indoor case, synchronizing interval can only expand to several minutes' level and the reboot mechanism would be triggered then.Figure 7(b) showed the result of outdoor experiment.The tendency of synchronization error indicated the relationship between   and   .When the tendency of synchronization error is up, it means that the compensated drift is insufficient.Synchronization error will still increase at the rate of   −   .When the tendency is down, it means that the compensated drift is excessive and synchronization error will increase in an opposite rate of   −   .
Temperature fluctuated heavily after 600 s.The tendency of synchronization error was down after 250 s as calculated drift was greater than real drift.The fluctuation of temperature during 700 s to 800 s made real drift bigger than calculated drift and the tendency turned to up.At about 850 s, TMP20 detected the fluctuation of temperature exceeded the threshold of 2 ∘ C. Then the synchronized node reset synchronizing interval to 8 seconds and restarted the compensation procedure.
Because of the fluctuation of outdoor temperature, the synchronizing interval using improved compensation can increase to 4 minutes on average and 6 packets are required to maintain the accuracy of 100 s.If we use packet-based synchronization only, 30 synchronizing packets are required in 4 minutes, and 80% of packets could be eliminated.

Sudden Change in Temperature.
The performance of proposed compensation method when temperature changed suddenly is shown in Figure 7(c).When the great change of temperature happened on synchronized node, the node would send packet every second, the same rate with temperature sampling, to keep synchronizing, as the periods from 120 s to 340 s and 590 s to 820 s showed.The blue line with wide width from 120 s to 340 s or from 590 s to 820 s consists of hundreds of triangles which are overlapped with each other.Since there are too many triangles (every second there will be one triangle corresponded), they just look like a line in Figure 7(c).
There is no compensation during those periods.After temperature became stabilized, compensation would be started again.Since synchronized node keeps sending packets and no compensation procedure occurred, the performance of Adaptive Compensation regresses to the synchronization without using compensation if reboot mechanism is also used. 1 makes a conclusion of the performance of packet-based synchronization without compensation, fixed compensation, and Adaptive Compensation in those environments.Fixed compensation is a compensation method usually used for extending synchronization interval with limited degree since it only calculates drift one time.The numbers in the table indicate the average of packets used for maintaining 100 s of synchronization accuracy in 10 minutes.Since the synchronization without compensation needs sending synchronizing packet every 8 seconds (100 s/12 ppm), 75 packets are required to maintain the accuracy of 100 s.The Fixed Compensation method only calculated the drift once with the Initial Interval.Using this Fixed Compensation method, the drift of about 9 ppm can be counteracted.The remaining 3 ppm drift needs to be dealt with by packet-based synchronization every 33 seconds (18 packets in 10 minutes).Since the synchronizing intervals are short, Fixed Compensation method or the synchronization without compensation would not be influenced by the temperature indoor and outdoor.

Number of Packets for Synchronization. Table
The numbers of packets in 10 minutes indoor and outdoor using Adaptive Compensation are average values according the experiments results mentioned above.For indoor case, Adaptive Compensation needs 9 packets in one hour to maintain accuracy of 100 s, 1.5 packets in 10 minutes on average.For outdoor case, 6 packets in 4 minutes means 15 packets in 10 minutes on average.
To deal with sudden temperature change, a temperature detective mechanism is necessary, or the synchronization error will fall out Guard Time and lose synchronization.The number of packets when temperature suddenly changed is determined by the rate of temperature sampling.The value of packet number recorded in Table 1 is measured at the rate of sampling every second.
According to Table 1, the synchronizing packets using Adaptive Compensation indoor is much fewer than Fixed Compensation and the synchronization only exchanging packets.To outdoor case, packets using Adaptive Compensation are a little fewer than Fixed Compensation but still much fewer than only packet-based synchronization.
When temperature suddenly changed, three methods have the same packet number for synchronizing if they use the same sampling rate.

Conclusion
This paper proposed a method called Adaptive Compensation, which improving the accuracy of calculated drift by increasing synchronizing interval gradually.This method is used for avoiding frequently packet-based resynchronization to meet the industrial requirement.The improved compensation method was implemented on GINA platform based on OpenWSN's work.Compared with the synchronization without using compensation, the experiments done indoor and outdoor showed 98% and 80% resynchronization packets are eliminated.The performance of Adaptive Compensation regressed to the synchronization without using compensation when temperature changed suddenly.

2 InternationalFigure 1 :
Figure1: In slot-based communication, time is sliced up into repeating frames.Each node is scheduled to communicate at a specific slot.The packet is scheduled to be sent at TxOffset after the beginning of a slot.Nodes synchronize to their time parents by timestamping the reception of packets and comparing them to TxOffset.Guard Time is used to avoid missing an incoming transmission by turning on the radio of the receiving node before the expected arrival of a packet[5].

Figure 2 :
Figure 2: Compensation in time-slotted networks.The node's slot duration is 100 ticks.It compensates drift to its time parent by periodically shortening (or lengthening, if slower than its time parent) by one tick.

Figure 3 :
Figure 3: Current time is 1.The next synchronizing packet should be scheduled before 3 since synchronization error will increase to Guard Time long at 3.According the inequality, scheduling next synchronizing packet at 2, with an interval of Δ × Guard Time, can make sure the falling out would not happen.
We implemented Adaptive Compensation based on OpenWSN's work.OpenWSN project provides open-source implementations of a complete protocol stack based on Internet of Things standards.It uses IEEE802.15.4e as MAC layer protocol of the stack.Basic time slot communication

Figure 4 :
Figure4: The guidance and inertial navigation assistant (GINA) platform is a low power wireless mote augmented with inertial measurement capabilities[13].

6. 1 .
Experimental Settings.During experiments, slot boundary and synchronizing points are recorded by logic analyzer.

Figure 5
shows a snapshot for a simple network of two synchronized nodes, which are running Adaptive Compensation implementation.Node A represents the time parent.The activities of two nodes are indicated by three digital signals: (i) Synchronization toggles when a resynchronization happened on node B; (ii) Slot of Node B toggles at each new slot of node B. Each slot is 10 ms long; (iii) Slot of Node A toggles at each new slot of node A. Each slot is 10 ms long.

6. 3 . Experimental Result 6 . 3 . 1 .
Constant Temperature.As shown in Figure7(a), synchronization error increased more slowly after each resynchronization, which can be derived from the slope of fitting lines A and B. Synchronizing points are indicated by blue triangles.The synchronization error from the synchronizing points 255 s to 511 s and 1024 s to 2047 s is fitted by line A and line B. The slop of line B is smaller than line A, which means that the calculated drift at 1024 s is more accurate than the drift calculated at 255 s.
we have got the time, what we should do is schedule next synchronizing packet before .However, we did not know the specific time point to guide node to schedule next synchronizing packet since   −   is unknown.
Actually   −   is the error/Δ in (3), which is caused by the inaccuracy of drift.Since error is smaller than one tick,

Table 1 :
Number of packets for synchronization in average within 10 minutes.