{'fraction_non_alphanumeric': 0.027244431868709326, 'fraction_numerical': 0.009862969400541655, 'mean_word_length': 4.578354002254791, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A Protocol for Self-Synchronized Duty-Cycling in Sensor Networks: Generic Implementation in Wiselib

In this work we present a protocol for self-synchronized duty-cycling in wireless sensor networks with energy harvesting capabilities. The protocol is implemented in Wiselib, a library of generic algorithms for sensor networks. Simulations are conducted with the sensor network simulator Shawn. They are based on the specifications of real hardware known as iSense sensor nodes. The experimental results show that the proposed mechanism is able to adapt to changing energy availabilities. Moreover, it is shown that the system is very robust against packet loss.


Introduction
Sensor networks [14] consist of a set of small, autonomous devices which may be used, for example, for environmental monitoring, patient monitoring in health care, and industrial machinery surveillance. As sensor nodes may be distributed in areas without power supply, or they may be mobile, they are generally equipped with batteries, which makes energy a scarce resource. A basic idea for saving energy is to periodically switch off the sensor nodes. The mechanism that establishes the alternation between the active and inactive states is generally called duty-cycling (see, for example, [13]). In some cases, duty-cycling is energy-aware (see, for example, [9,11,10]). The main disadvantage of these approaches is that they require a quite regular pattern for the availability of energy from the environment.
In previous work [8,7,6] we introduced and studied a possible technique for energy-aware dutycycling in (mobile) sensor networks with energy harvesting capabilities. This system is inspired by self-synchronized sleeping patterns of natural ant colonies [4]. The focus of these first studies was purely on the swarm intelligence aspects of the proposed system. The experiments were performed without considering, for example, packet loss, collisions and network failures. Before we outline the contributions of this work, we introduce already a glimpse of the basic behavior of this previously introduced system; see Figure 1. The solid line shows the fraction of active nodes over time, whereas the slashed line shows the average battery level of the nodes over time. Finally, the dotted line represents the sun power that is used to establish the amount of energy which can be harvested by the sensor nodes at each time step. Note that all three measures are scaled to [0,1]. At this point we would like the interested reader to understand the following two aspects. First, self-synchronized duty-cycling is indicated by the repetitive appearance of activity peaks over time (see solid line). Second, the adaptation to changing energy conditions is indicated by the changing height of the activity peaks. At times of lower battery levels, activity peaks are lower as well. This is the mechanism used by the sensor nodes to adapt to varying energy conditions. Contribution of this Work. The first contribution of this work is the design of a protocol that captures the essential aspects of the swarm intelligence system previously proposed in [8,7,6]. The second contribution consists in the implementation of this protocol in Wiselib [1], a library of generic algorithms for wireless sensor networks. Finally, we experimentally test our duty-cycling protocol in a real scenario, simulating iSense sensor nodes from Coalesenses GmbH [3] with the network simulator Shawn [12].
The organization of the paper is as follows. In Section 2 the extension of Wiselib for dutycycling algorithms is introduced, followed by the description of the protocol for self-synchronized duty-cycling in Section 3. Finally, experimental results are presented in Section 4, and conclusions and an outlook are given in Section 5.

Wiselib: Duty-Cycling Concept
The Wiselib [1,16] is a generic algorithm library for heterogeneous wireless sensor networks. The main objective concerns the implementation of algorithms that may be applied on different hardware and software platforms. Not only real sensor hardware such as MicaZ or TelosB nodes are supported by Wiselib, but also simulation environments such as Shawn and TOSSIM. The algorithms included in the Wiselib are organized in topics according to their functionality. In order to abstract the algorithms from the hardware and the operating system, a set of connectors specifies interfaces for interacting with them. A connector is also defined to interact with wireless sensor network simulators such as Shawn [12]. Those connectors are defined such that the same algorithm can be run on a physical platform or on a simulator.
The design of a new algorithm class in Wiselib requires the definition of a concept, that is, a specification of how an algorithm looks and behaves. In this paper we provide a generic concept for energy-aware duty-cycling algorithms, and provide one model for this concept (see Section 3). In particular, a duty-cycling algorithm must assist sensor nodes in their decision of being active or inactive. This is handled via a call-back to the sensor node when it is supposed to change mode. Based on this call-back, the sensor node is then responsible for the executing the corresponding action. Therefore, a duty-cycling algorithm has basically two functionalities: It can be enabled and disabled, and a call-back can be (un)registered to indicate changes in activity. The concept looks as follows: With the aid of this generic concept, it is possible to cover a broad range of duty-cycling algorithms. The exact behavior of a potential duty-cycling model is not mandatory. It can be asynchronous or synchronized, it may rely on exact time-synchronization or do not have any requirements. The important aspect is that the method signatures from the concept are implemented, so that it can be passed to other algorithms as a template parameter.

Proposed Duty-Cycling Model
As mentioned before, in [8,7,6] a swarm intelligence technique with the potential application of selfsynchronized duty-cycling in (mobile) wireless sensor networks with energy harvesting capabilities was introduced. This section aims at designing and implementing a duty-cycling protocol on the basis of this work. The current version of the protocol assumes that there is a time synchronization algorithm executed by a lower layer of the network. The protocol works in periods. Each period has a length of ∆ time units (say, seconds). Each period is divided in two phases: the first phase is dedicated to actions concerning the management of duty-cycling, whereas the second phase is dedicated to application-specific tasks that sensor nodes must perform (see Figure 2). The first phase of each period is very short. In this phase all nodes may receive transmissions from neighboring nodes and themselves they execute one duty-cycling event. The outcome of the first phase decides if a node will be active or inactive for the rest of the corresponding period. In case of being active a node is available for user-defined applications (environmental data monitoring, tracking, etc). However, if the state of a sensor node is set to inactive the node will turn off the radio and will sleep until the start of the following period.
In the following we focus on the description of the duty-cycling algorithm executed in the first phase of each period. This algorithm consists in a so-called duty-cycling event that is executed by each sensor node i exactly once. The time of executing this event is, at the moment, randomly chosen by each sensor node within the first phase of each period. Each sensor node i maintains a real-valued state variable S i . The value of this state variable is initially set to the so-called activity threshold S act , which is a parameter of the mechanism. Moreover, a i is a binary variable whose value determines if the sensor node i is active (a i = 1) or inactive (a i = 0) in phase of two of the corresponding period. The value of the variable a i is determined as follows: where θ act is the so-called activation threshold, and Φ(x) = 1 if x ≥ 0, and Φ(x) = 0 otherwise. Note that an inactive sensor node can return to the active state either due to local interactions (as explained below in Eq. 2) or spontaneously with a probability p a and an activity level S a . In addition, each sensor node maintains a queue Q i for incoming duty-cycling messages from neighboring sensor nodes. Each message m ∈ Q i contains a single field m activity , which is set to the activity S j of the sensor node j that has sent the message. When sensor node i executes its dutycycling event, the value of state variable S i is updated depending on the messages in Q i . Subsequently sensor node i sends a duty-cycling message, containing the new value of S i , using a certain transmission power level. Note that the choice of the transmission power level is a crucial component for the working of our duty-cycling technique. More specifically, the value of state variable S i of a sensor node i is computed as follows: where g is a gain parameter whose value determines how fast the value of variable S i diminishes.
After this update, all messages are deleted from Q i , that is Q i := ∅. Note that with this update the value S i of an inactive sensor may increase sufficiently enough in order to be greater than the activity threshold S act . For the working of the duty-cycling mechanism, the choice of the power level for the transmission of the duty-cycling messages plays a crucial role. Here we assume a standard antenna model which allows sensor nodes-for each transmission-to choose from a finite set P = {P 1 , . . . , P n } of different transmission power levels. 1 More specifically, the choice of a sensor node i depends on its battery level, which is denoted by b i ∈ [0, 1]. Hereby, b i = 1 corresponds to a full battery. In the following we first outline the determination of a so-called ideal transmission power level, which then leads to the choice of the real transmission power level. The ideal transmission power level (p i ) of a sensor i depends on the current battery level: where p min , respectively p max , are parameters that fix the minimum, respectively maximum, transmission power levels. Only when batteries are fully charged the ideal transmission power level may reach p max . The ideal transmission power level is then translated into the real transmission power level (T i ) as follows: At this point it is important to realize that the transmission power level T i is used only for sending the duty-cycling message. For other messages during the second phase of each period, the user application is responsible for choosing transmission power levels. The duty-cycling event described above is summarized in Algorithm 1. As mentioned above, the battery level of the sensor nodes is responsible for their choice of a transmission power level for sending the duty-cycling message. Therefore, the battery level of course affects the communication topology in the context of the duty-cycling mechanism.

Experimental Evaluation
In the following we first describe the experimental setup and the experimentation environment before we present the obtained results. The implementation of the presented protocol in the Wiselib provides us with options for executing it on real test-beds but also to perform simulations with some sensor network simulators. In the context of this paper we decided for the second option. More specifically we used the sensor network simulator Shawn [12], which is a discrete event simulator with a very high level of parameterization which is able to execute algorithms from the Wiselib. The user can easily run experiments simulating the behavior of different sensor nodes and also add own sensor node specifications. A peculiarity of Shawn is the fact that packet collisions are not explicitly considered. Instead Shawn simulates these collisions and the consequent packet loss under different constraints and in different scenarios. Thus, any packet-loss model can be implemented.
We decided to experiment with iSense sensor node hardware from Coalesenses GmbH [3]. For this purpose we added the specification of iSense nodes to Shawn. These sensor nodes use a Jennic JN5139 chip, a solution that combines the controller and the wireless communication transceiver in a single chip. The controller has a 32-bit RISC architecture and runs at 16Mhz. It is equipped with 96kb of RAM and 128kb of serial flash. The maximum transmission power level of iSense nodes reaches a distance of about 500m in all directions in open air conditions. Note that iSense nodes are being used by two of the currently largest European projects on sensor networks: WISEBED [2,15] and FRONTS [5]. In our simulations, iSense nodes are supposed to be equipped with solar panels. According to their documentation, iSense nodes require 0.025mA to work without using any additional peripheral such as the radio or the sensing devices. The state in which the radio is also turned on requires a power supply of 12.8mA. Additionally, to receive or send a message with 4 bytes of information, as required by duty-cycling messages, implies a consumption of 7.43µC. The batteries have a maximum capacity of 2600µC. Energy harvesting by solar panels can reach a maximum nominal value of 1.6W. This information is summarized in Table 1. Finally, let us mention that iSense nodes offer 6 possible transmission power levels, in addition to the state in which the radio is turned off. The five transmission power levels other than the maximum one are obtained by reducing the maximum transmission power level by 1 6 , 2 6 , 3 6 , 4 6 , and 5 6 . One of the aspects that has not been described so far is the simulation of the light source for energy harvesting. This was done as follows. The light source at time z > 0 has an intensity of s(z) ∈ [0, 1]. Hereby, s(z) = 0 corresponds to absolute darkness. In [8] we described a model for the evolution of the sun light intensities, that is, for the evolution of s(z) over time. Here we consider exactly the same model. Additionally, we assume a variable cloud density c(z) ∈ [0, 1]. Depending on the technical characteristics of the solar panels used, a sensor node i can transform a fraction f of the available light In the experiments presented in this article we do not consider any specific user application, that is, the energy consumption of phase two of the proposed protocol must be simulated. This is done by removing an amount of e app of energy from the battery for each execution of phase two. The parameter values used for simulation are as follows: p min p max g p a e app f 0.07 0.14 0.1 0.001 0.001 0.0027 It is important to note that the information which refers to the power profile of the iSense nodes is obtained by properly rescaling the values from Table 1 to the [0, 1] range that is used by the description of duty-cycling given in Section 3.

Experiments
Assuming that ∆-that is, the length of one period-corresponds to 60 seconds, the simulations that we conducted span 30 days (each day consists of 1440 periods). The first phase of each period, which is reserved for the duty-cycling events, was given 0.05 seconds. Information about the state of the sensor nodes (active versus inactive) is collected at the start of each period. The most important measure taken is the mean activity of the sensor network, which is measured-at any time-as follows: Note that, the greater A the more sensors are active at the specific time at which A was determined. Self-synchronization behavior is characterized by an oscillating value of A over time. This was shown already for a mobile sensor network with k = 120 sensor nodes in Figure 1 of the introduction (see solid line). However, the results from that figure were obtained in a perfect environment with no collisions or transmission failures and no propagation times. Moreover, the energy model that was used had no relation to real sensor node hardware. The experiments that we present in this section aim at proving the applicability of the proposed mechanism in real sensor networks. All experiments are done on the basis of a static network of k = 120 iSense nodes as simulated by the Shawn sensor network simulator. For the first experiment that we conducted we assumed a zero probability for packet collisions. Moreover, we assume a cloud density of zero, that is, c(z) = 0 for z ≥ 0. Figure 3 shows the obtained duty-cycling behavior. Again, the solid line shows the fraction of active sensor nodes over time, whereas the slashed line shows the average battery level of the sensor nodes over time. Finally, the dotted line represents the sun power that is used to establish the amount of energy which can be harvested by the sensor nodes at each time step. The graphic shows the behavior for one day of simulation, that is, 1440 periods. Selfsynchronized duty-cycling is indicated by the appearance of activity peaks over time. It is remarkable how the system adapts to the available energy resources, reducing the height of the peaks when the battery level of the nodes is reduced. Note that when a lot of energy is available the system can even prescind from switching off sensor nodes. This can be seen by the existence of a large activity peak of about 200 periods of length located around period 14000. Note that for this experiment the average fraction of nodes that are active at each period is approximately 0.6. This measure will henceforth be called the mean system activity.
Concerning the energy spent by the duty-cycling protocol with respect to the user application, we took measures over the whole simulation of 43200 periods (that is, 30 days).

Duty-cycling
User Appl. Tx Rx Idle Active Energy (%) 0.757 18.591 0.001 0.035 80.616 The energy spent by duty-cycling is hereby split into the "Idle" and "Active" states as well as the energy spent for transmitting the duty-cycling messages (Tx) and receiving duty-cycling messages (Rx). Note that message reception is the task which consumes most of the energy. In total, the dutycycling mechanism consumes approximately 20% of the total amount of spent energy. This may seem quite high at first. However, consider that this percentage strongly depends on the value of e app , which we have set to a very moderate value of 0.001. Increasing this value will obviously cause the decrease of the percentage of energy spent by duty-cycling. After these initial studies we will now test the duty-cycling mechanism in two adversarial scenarios. In first place, it is shown how the system responds to situations with communication failures. In second place, the behavior of the system is studied in scenarios where energy harvesting is limited, for example, due to cloudy weather. Finally, we present a mechanism for the automatic parameter adaptation of the system for what concerns different network sizes.

Effect of Packet Loss
With the next experiment we aim at studying the robustness of the system with respect to communication failures. The experiment consists in simulating the duty-cycling protocol under different packet loss rates. A packet loss rate of p loss ∈ [0, 1] means that the probability of correctly receiving a message is 1 − p loss . We repeated the initial experiment as outlined above for all packet loss rates between 0 and 1, in steps of 0.01. The results are shown in terms of the obtained mean system activity for each considered packet loss rate in Figure 4 (top). It can be observed that the behavior of the system does not visibly change until a packet loss rate of about 0.3. This means that the proposed system is quite robust against packet loss. Only for packet loss rates greater than about 0.3 the system behavior degrades.

Limited Energy Harvesting
Another interesting question concerns the possible change in system behavior when energy harvesting is restricted. Considering the example of solar panels, this is the case, for example, with bad weather conditions. Remember that the proposed model is able to simulate bad weather conditions by means of cloud densities greater than zero. We repeated the initial experiment (that is, without considering packet loss) for a range of different cloud densities between 0 and 1. Figure 4 (middle) shows the evolution of the obtained mean system activity when moving from low to high cloud densities. As expected, with increasing cloud density the mean system activity decreases. Interestingly, the relation between cloud density and the mean system activity is linear.

Adapting to Different Network Sizes
When changing to differently sized networks (we only considered 120 node networks so far), it is intuitively clear that some parameter values must be adjusted in order to maintain a functional system. Note that when changing the network size, the node density changes. Hence, it is reasonable to assume that for maintaining the shape of the activity peaks, the choice of the transmission power level and the probability of spontaneous activation should be adapted to the new network size. A way of obtaining the new system parameters is described in the following. With k new , p a new and t new we refer to the new number of sensor nodes, the probability of spontaneous activation and the transmission power level of the new, differently sized, network. First, in order to obtain the same wake-up rates as in the case of a 120-node network, the following rule can be applied: p a new := p a · k/k new , where p a and k are the parameters from the original network. Note that this rule increases the probability of spontaneous activation of the nodes when the network size is decreased, and vice-versa when the number of nodes increases. Moreover, the average number of nodes' spontaneous activations per time unit is maintained. Next we introduce a rule for adapting the transmission power level. The basic idea is to have a constant average number of sensors being reached by a transmission. Due to the fact that the sensor nodes form a random topology, the following reasoning was used. In general, the number of nodes that can be reached by the ideal transmission of a sensor can be estimated as follows: π · t · 2 · k/S, where k is the number of sensor nodes and S is the space in which the sensor nodes reside. In our case it holds that S = 1 2 = 1. Therefore, this term reduces to π · t · 2 · k. As t is known for the case of 120-node networks, an adjusted transmission power level can be calculated for networks of different sizes as follows: where k new is the size, respectively t new is the transmission power level, of the new network. However, note that the transmission power level is not directly modifiable as an algorithm parameter. The only parameters of our algorithm for what concerns to the transmission power level are p min and  p max . These values are used as the boundaries of the region for the ideal transmission power levels. Therefore, our scaling method consists in using Eq. 6 for obtaining p new min and p new max for delimiting the value of the new networks' ideal transmission power level.
With this scaling methodology we repeated the initial experiment (that is, without packet loss) for a range of different network sizes k ∈ [0, 300]. The graphic in Figure 4 (bottom) shows the evolution of the resulting mean system activity. Ideally we would have expected a more or less straight line at about 0.6. This would have meant that the introduced parameter scaling method leads to a system that behaves equally for all network sizes. However, as can be seen, the scaling method only works well for networks with more than 100 nodes. For smaller networks, the mean system activity decreases. However, this can be explained by the decreasing connectivity and communication ability.

Conclusions and future work
In this paper we introduced a protocol for self-synchronized duty-cycling in wireless sensor networks with energy harvesting capabilities. This protocol, inspired by real ant colonies, has been implemented in the generic algorithm library Wiselib. Moreover, experiments have been performed with the network simulator Shawn configured to simulate iSense hardware. The proposed technique adapts to changing energy conditions in a self-organized way. Moreover, it is very robust for what concerns packet loss and limitations of energy harvesting. In the future we plan to combine this protocol with real user applications such as monitoring or tracking. Moreover, we plan to verify the experiments on real hardware. Finally, as our technique does not depend on nodes being static, the results obtained in this paper can be reproduced for mobile sensor networks.