{'fraction_non_alphanumeric': 0.02721774193548387, 'fraction_numerical': 0.007471537001897533, 'mean_word_length': 4.655376704672479, 'pattern_counts': {'":': 0, '<': 4, '<?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}}
Zero Energy Network stack for Energy Harvested WSNs

We present our ``Zero Energy Network'' (ZEN) protocol stack for energy harvesting wireless sensor networks applications. The novelty in our work is $4$ fold: (1) Energy harvesting aware fully featured MAC layer. Carrier sensing, Backoff algorithms, ARQ, RTS/CTS mechanisms, Adaptive Duty Cycling are either auto configurable or available as tunable parameters to match the available energy (b) Energy harvesting aware Routing Protocol. The multi-hop network establishes routes to the base station using a modified version of AODVjr routing protocol assisted by energy predictions. (c) Application of a time series called ``Holt-Winters'' for predicting the incoming energy. (d) A distributed smart application running over the ZEN stack which utilizes a multi parameter optimized perturbation technique to optimally use the available energy. The application is capable of programming the ZEN stack in an energy efficient manner. The energy harvested distributed smart application runs on a realistic solar energy trace with a three year seasonality database. We implement a smart application, capable of modifying itself to suit its own as well as the network's energy level. Our analytical results show a close match with the measurements conducted over EHWSN testbed.


I. INTRODUCTION
Several disruptive sensing and control algorithms proposed for wireless sensor networks (WSNs) have remained abeyant due to power requirements for the hardware. However, recently Energy Harvesting wireless Sensor network (EHS) applications are a reality due to their independence from utility power and thus unleashing several interesting proposals in sensing and control. This possibility is because of advancements in nanoelectronics and materials, increased power efficiency of harvesting electronics and the rapid advancements in high integrated ultra low power microcontrollers and communication radios. The "ZigBee Green" [1] is specifically meant for running out of energy harvesting sources. Recent advancements in materials and MEMS research has made Thermo Energy Generators (TEGs) and vibration harvesters (unusable till recently) as potential energy sources. Other contributing parameters include system operating voltage & frequency of the microcontroller and radio, and finally the system's several low power modes. Operating voltages of about 1.8 volts with operating frequencies of less than 1MHz and sleep currents of the order of 100 nA are some of the recent technology trends for system parameters. Radio communication energies of about 10 nJ per bit [2] is fast becoming a reality. Also, energy storage in thin film batteries [3][4] and low leakage super capacitors [5] [6] with several thousand charge-discharge cycles offer efficient energy storage.
EHS find attractive applications wherever remote monitoring and control are required and cover a wide spectrum of scenarios. On the one end could lie an intrusion detection system deployed in a wireless tripwire paradigm for monitoring an international border, and the other end of the spectrum is a simple wireless switch application for home lighting systems. While the former application requires an energy storage buffer, the latter application requires energy generation and its usage on the fly. Also, these applications work in multi-hop and single-hop settings respectively. Other applications under this wide spectrum include intelligent transportation, smart buildings, pollution monitoring, agriculture and climate change, health care including body area networks and other similar applications. For outdoor applications, while photovoltaic panels offer significantly higher power compared to other harvesting sources, often sensor nodes packaged with these small panels could physically be placed where reflected light or even a partial shade might be present. This is especially true for intrusion detection where the purpose is to detect an intruder under a camouflage of the sensor node so as to avoid attention from the intruder. Additionally, seasonal variation in sunlight plays an important role in ensuring continuous and untethered operation of solar powered EHS nodes. Thus, applications perhaps have to continuously adjust to varying instantaneous power fluctuations and yet accomplish their primary assigned task. Since the EHS nodes are usually wide spread and the communication of these nodes are limited in range, multihop network is required with performance deterioration within acceptable limits. Thus, designing a multi-hop EHS sensor network under harsh incoming energy condition is indeed a challenge.
One key difference between battery driven WSNs and EHS networks concerns the optimization parameters such as: (a) energy consumption to increase the node's battery life and (b) A network wide policy such as support a network lifetime of about "X" (say) number of hours or support the largest partitioned network. A large body of work in WSN is limited to maximizing the policy subject to a given energy constraint or minimizing energy consumption to satisfy a network policy requirement. In direct contrast, for an energy harvested network, the objective is to maximize the network policies and also maximize the energy consumption. In other words, minimize the energy differential between the available and consumed energy in each discrete time slot and maximize the network policy. Our work in this paper uses a multi-criteria optimization approach to find the optimal network policy and energy differential curve. The significance of optimal network policy-energy differential curve is to show a trade-off between global perspective of network policy and energy differential. Also, when the requirement on either network policy or energy consumption varies, one can use the optimal network policyenergy differential curve to locate the new optimal trade-off. In this paper, the goal is to implement a distributed smart application for environment monitoring applications where the sensor and communication nodes are powered with harvested energy. We approach this goal by building a protocol stack called the "ZEN Stack" as shown in Fig. 1. At the application layer, we consider the application performance not only its own energy level, but also on its neighbour and parent forwarding nodes. We use energy measurements and time series predictions to change the behaviour of our base application in a manner that energy utilization is a maximum in the time slot. At the routing layer, since each node in the network can harvest different energy magnitudes and thus have a varying energy profile, finding network wide routes when energy levels on nodes vary continuously is a challenge. Hence, routing protocols have to consider the energy harvested to decide how to route packets to the base station. At the data link layer, we propose several enhancements to the existing Medium Access Control (MAC) Layer. Our goal is to study the performance of this stack in its ability to exploit the available energy to the maximum extent possible. Thus ensuring network wide "energy neutrality" condition. The analysis followed by implementation results are encouraging and also show that even "near real time" applications can perform reasonably well.

II. RELATED WORK
In recent times, a large body of work is being concentrated on Energy Harvesting Wireless Sensor Nodes (EHWSN). Several energy harvesting sources like solar, thermo, acoustic, wind, RF and wave for driving low power embedded devices are discussed in [7]. Many energy harvesting WSNs have been implemented in past like Trio [8], AmbiMax [9], Prometheus [10]. However, literature on Energy Harvesting systems is mostly limited to single node networks or extensive simulation study. Many of the work focus on the system building, efficiency and viability of energy harvesting mechanisms. In [10] authors shows improvement in lifetime where a supercapacitor and battery are charged together from a solar panel by adjusting their duty cycles. Recently Power management and data rate maximization in EHWSN was discussed in [11]. The authors analytically find the required amount of energy to be harvested to ensure energy neutral operation in each slot.
Accurate prediction of the energy is an important factor for energy neutral operations. Time series based energy predictions are commonly used for predicting solar energy. Exponential Weighted Moving Average (EWMA) is commonly applied for future energy predictions [12], [16] and assigns weights to data in the time series, assigning lower weights to older data and giving importance to more recently acquired data. Holt-Winters (HW) time series is widely used in stock markets trend analysis, production planning, healthcare decisions on staffing & purchasing, demand forecasting [14] and for predicting share prices where forecast value takes trend and seasonal variation into account [13], [15]. In [25] a three state markov chain model is used to predict the solar energy source and their transition probabilities are restricted for day time only. Energy samples from a simulation model are also generated from the model.
In the network layer, the work in [16] demonstrate the performance benefits in using AODVjr for ZigBee mesh networks. The work introduces an energy aware metric with future energy consumption using Exponential Weighted Moving Average (EWMA) time series model. The work is limited to simulation studies and also considers battery driven sensor nodes. In this work, we utilize AODVjr protocol [17] a simplified version of AODV routing protocol that reduces implementation complexity by eliminating certain features from the original AODV protocol. The work in [18] compares several energy harvesting based routing protocols in a simulation setup and show that R-MPRT routing protocol outperforms the other protocols. The work considers realistic MAC protocols suitable for energy harvesting networks and is limited to extensive simulation studies. In [19], authors propose a routing algorithm that takes into account distance and link quality information. The algorithm requires that all nodes in the network know about the position, which usually not available in sensor network deployments. The authors in [20], propose asymptotically Optimal Energy-Aware Routing for Multihop Wireless Networks named Energy-opportunistic Weighted Minimum Energy (E-WME). In E-WME the best route is decided based on the energy considerations, however, routing decisions should also take into account different channel conditions, especially in a wireless environment in order to minimize packet retransmissions and energy wastage.
At the data link layer, while there are several MAC protocols been designed for WSN, they are not optimized for energy harvesting sensor nodes. However there are quite a few MAC protocols designed for EHS, the work in [21] proposes dynamically adapting the duty cycle of a node by observing deviations in energy input from an estimated model to ensure energy-neutral operation. In [22] the authors propose to use adaptive control theory to formulate a linear-quadratic optimal tracking problem for maximizing task performance and minimal duty cycle variations. In [23] the authors present analytical models and performance metrics for different MAC protocols. The work however is limited to simulation studies and over single-hop network. In [24], performance of various sleep and wakeup strategies based on channel state, battery state and environmental factors are analysed. The authors propose a optimal sleep wakeup strategy using game theory approach which provides trade-off between packet dropping and blocking probabilities.
Several optimization techniques have been discussed in literature for battery driven multihop WSN's in the past where the objective is to maximize the network lifetime by minimizing energy consumption [26], [27]. With a view on utilizing the harvested energy in an optimized manner, adapting the performance of an application while respecting the limited and time-varying amount of available power in EHWSN is discussed in [28]. A formal model that actively adapts application parameters such as "rate of sensing" is used to optimize the performance. The simulation study does not consider network related parameters or network wide energy levels. A "Lazy Scheduling Algorithm" is proposed and tested for its effectiveness by assigning several power values to the system in [29]. Task admittance and future energy prediction is carried out with energy variability characterization curves generated by modeling the power source.
We demonstrate a distributed smart application which optimizes the necessary parameters to ensure maximization of application policy and minimization of residual energy. Contrasting to the work in literature, we believe performing Energy Neutral Operations based on node's own energy is not optimal. Instead we propose to derive the optimal number of operations and the residual energy based on the available energy on the node, predicted energy and network energy (i.e., neighbouring nodes). Particularly, we tune the duty cycle factor, transmission power factor and the application morphing factor to achieve optimal performance. Amongst the rich literature on EHWSN, inter alia, we position our work based on these attributes: (a) Harvested energy is the only available source; (b) EHWSN nodes are deployed in a testbed with MAC layer contention and adaptive duty cycling; (c) Inter-node distance of about 25 − 30ft with a realistic channel where Wi-Fi and other 2.4GHz radios are present; (d) Energy prediction from physical solar trace data including seasonality over a three year database is used; and (e) A smart application which morphs itself into several forms based on the energy level of the node as well as its network in a manner where performance deterioration is within acceptable limits.

III. EXPERIMENTAL SETUP
Our multi-hop EHWSN comprises of 4 nodes placed in a tree topology as shown in Fig 2. Our custom hardware motes uses TI's MSP430 microcontroller and Chipcon's IEEE 802.15.4 standard CC2520 radio. We broadly divide the network into data collecting sensor nodes and data relaying relay nodes. From Fig 2, nodes B,C are relay nodes and node D is the sensor node. Relay nodes have the task of forwarding packets to the base station. Node A is utility powered and configured as the base station or data sink node for the network. For our implementation, we used solar energy harvesters with varying energy profile across the network. Since we require realistic spatio-temporal varying power across all the network nodes, the power output solar trace database available from [30] is replicated over the experimental setup. The three year solar trace with trend and seasonality has power output for direct, diffused and reflected sunlight. In Fig 2, Node B runs on direct sunlight profile, node C runs on reflected sunlight profile and node D runs on diffused sunlight profile. The power output from the solar panels was varied by switching "on" and "off" electrical lamps in the solar harvesters. We scaled down the power output obtained from Lowry Range Solar Station (LRSS) to match the laboratory solar harvesters. Each node in the network has two modes of operation namely (a) active mode and (b) sleep mode. While, in active mode, a node can transmit and receive packets, in sleep mode, node turns off the radio transceiver to reduce the energy consumption. Switching between these two modes depends on the sleep and wakeup strategy used by that node. In our setup, based on the harvested energy we determine the sleep and wakeup periods. For the MAC layer channel sensing, we use Clear Channel Assessment Mode -1 (CCA Mode 1); a simple energy detection scheme available as part of the IEEE 802.15.4 standard.

IV. SMART APPLICATION -THE MODEL
We argue that node based task scheduling and pre-emption is perhaps not best suited for multihop EHWSN. For instance, it is possible that low priority tasks located at the head of the queue gets executed during energy stress disregarding network's requirement and energy budgets. We propose that applications have to be "smart". A typical WSN application comprises of operations such as sense, compute, store and communicate. These operations are required to be executed based on a policy over several time slots. Communication being an integral part of a node, it typically comprises of packet transmission and reception. Packet forwarding is essentially transmission but refers to relaying (reception and transmission) a neighbour's packet. Transmission power control is mandated due to energy considerations. The smart application is essentially a set of policy elements. Smart application design and its successful implementation require several parameters: (a) Available energy in the storage buffer. We call this the "real energy" (E A ). (b) Predicted energy that would be harvested in the next two or three time slots called "virtual energy" (E P ). (c) The "network energy" (E N ) which is essentially the energy available in the neighbouring nodes (can be extended to energy available along a route). Thus our smart application has to exploit the energy in the slot to the maximum such that the "residual energy" between the available energy and consumed energy in a slot is minimum. Since energy replenishment occurs in EHWSN, energy utilization should be such that maximum number of tasks or operations should be completed. As one can observe, Packet Reception Ratio (PRR) and application performance depends on accurate measurement of the above parameters. Since available energy is stored in a super-capacitor, we calculate the real energy by sensing the voltage across the capacitor. We use Holt-Winters model to predict the virtual energy in a node. We leverage on the RSSI values contained in routing messages for periodic update on the energy level in the network. Since available energy on each node varies, the application morphs itself into several forms in a manner that performance deterioration is within acceptable limits. Though our analysis and simulations can use many energy levels, for the purposes ease of implementation, we discretize the available energy levels into 4 levels represented by E i , i ∈ {0, 1, 2, 3}. E 0 , E 1 , E 2 and E 3 correspond to Lowest survivable, Minimum, Intermediate and High energy levels respectively. Similarly, the residual energy levels are represented by to Lowest survivable, Minimum, Intermediate and Higher energy levels respectively. Let the stored energy, harvested energy, predicted (virtual) energy at time slot k on node 'n' be represented by be the energy available on neighbouring node 's' at time slot k and E DC(k)(n) denotes the minimum energy required for the node for one duty cycle. We denote the maximum energy capacity of a supercapacitor as E max . The harvested energy for node n is E H(k)(n) ≥ 0 and it is a trivial assumption as no energy harvested can only stall the application execution. The available energy at each time slot k on node n is represented by

A. The Base Application and Morphing
As mentioned earlier, the base application essentially constitutes a set of policies which would be executed if available energy is high. At the beginning of each time slot, the application checks the available energy, virtual energy and the policy that requires to be executed. If there is sufficient harvested energy, the node initiates network support for its policy and prepares itself to execute the corresponding policy, else, the application on the node decides to morph into a slower version (lesser functionalities than the base application). In the event of network showing lack of support, e.g., neighboring nodes having lesser energy, the application will be again forced to morph itself to a further slower version. For example, when ensuing two time slots reports the virtual energy for the node is low and current energy level is low, the application morphs to a lower version by partial execution of the policy with a few operations backlogged for later execution. A partial fulfillment for a specific policy is necessary to ensure that priority for certain operations in the policy has soft guarantees.   6 captures the time varying energy profile for a node and shows the energy transitions based on real, virtual and network's energy. For instance, the state transition diagram shows when the node is high on own energy and virtual energy (i.e. both the energy values are at E 3 ), the node can complete its policy execution in the current time slot including any backlog operations. This energy expenditure is possible only when the network provides the necessary support. With its completion, the node can transit to either E 1 or E 0 depending on the level of energy depletion. At the same time, if the future time slots predict a low energy, the base application chooses to morph to a slower form and thus deplete lesser energy and transit to say either to E 2 or E 1 .

B. Policy Models 1) Policy Model -Operation Set::
The operation set includes the set of operations (both node and network) any wireless sensor node performs. Basic operations may include sensing, computing, communication and storage. Each element in the operation set is associated with fixed energy consumption. The typical energy requirements for each operation on our custom mote are given in Table I. 2) Policy Model -Policy Set (P):: A policy set P defines the set of operations and their order of execution obtained from an operation vector that a sensor node n has to follow. Typically, a sensor node might be associated with two or more policies, and the specific set of policy to be executed in a particular time slot is defined as part of the base application. Thus the policy set for a node can be defined as, A typical policy on a sensor node D can be P d = {P 1 , P 2 , P 3 } where, P 1 = {Sense, Transmit}, P 2 = {Sense, Compute, Write} and P 3 = {Read, Compute, Transmit}. For example, a relay node R may have the policy set P r = {P 4 , P 5 , P 6 } where, P 4 = {Receiving, Forwarding}, P 5 = {Read, Compute, Forward} and P 6 = {Receive, Write}. At each time slot, the node decides to execute subset of policy set denoted by P ′ . The energy required for policy execution in time slot k is given by, where, P ′ is the subset of the policy set, x the maximum number of policies and E i is the energy consumed for i th policy set.

V. SOLAR ENERGY PREDICTION MODEL
One of the key requirements for optimal application performance is accurate prediction of virtual energy on each node. Virtual energy availability has impact not only on node's own performance but also on the network's performance. As mentioned earlier, literature on time series models for energy prediction is a well researched area. However, none till date have performance results from a physical implementation. In order to study network wide efficacy of time series models, we used solar energy trace database with data collected over three years by lowry range solar station [30] from year May 2008 to August 2011. Three data sets are available from the website corresponds to direct sunlight, reflected sunlight, and diffused sunlight. Since the complete database of three years requires about 450 KB for each dataset, it was easily possible to load the database on individual sensor nodes. We applied these spatio-temporal data sets across the complete network as shown in Fig 2. We evaluated two of the most commonly used energy prediction models namely Exponentially Weighted Moving Average [EWMA] prediction model, and the Holt-Winters [HW] time series prediction model for these data sets.

A. EWMA Prediction Model
EWMA is a commonly used algorithm for predicting solar energy which assigns weights to data in time series, assigning lower weights to older data and giving importance to more recently acquired data. The forecast value using the EWMA algorithm is obtained from Eq. 3.
In the Eq. 3, E P (t + 1) indicates the predicted value for the time slot t + 1, E A indicates the measured available energy at time slot t and 0 < ǫ < 1 is the weighting factor. To predict the incoming energy, EWMA sums the last read real value to the previous value predicted with weights ǫ and 1-ǫ. If the weighing factor ǫ is high i.e. close to 1, previous values will have higher importance and vice versa. The best value for ǫ is choosen based on the least mean square error (LMSE). We found that ǫ value of 0.5 provides a minimum error for the EWMA algorithm which is the same as chosen in [12].

B. Holt-Winters Prediction Model
Since solar energy output can have seasonal variation, intelligent prediction algorithms should exploit the trend and seasonality available within the data sets. We applied Holtwinters time series prediction model as it is a commonly used time series model for forecasting when data follows a trend and seasonality. The Holt Winters algorithm computes forecast value based on the estimates of trend and seasonality from the previous data. HW algorithm uses the following set of equations for forecasting: In the above equations, E P is the predicted value, y is the current value, ǫ is the weighting factor, b is the trend factor, I is the seasonal index, t is the current time slot, l is the number of periods. The term ǫ, β, γ are constants whose values are estimated such that their LMSE is minimized and estimated it to be 0.906, 0.1 and 0.650 respectively.
VI. MULTI-CRITERIA OPTIMIZATION PROBLEM We mentioned in previous sections about efficient energy utilization in each time slot where the difference between available energy and consumed energy is minimized for a given real, virtual and network energy. The problem is to find an optimal policy execution. We cast this problem as multicriteria optimization with two objectives: (a) Maximizing application policy execution, and (b) Minimizing residual energy.

A. Maximizing application policy
In each time slot k, the objective is to maximize P ′ policies executed by a node. Thus the application policy utility U is given by, In Eq.(4), P i ′ is the set of policies to be executed and α i indicates the morphing factor for the i th policy set. When α i = 1, the entire policy set P is executed (i.e., P i ′ = P ).

B. Minimizing residual energy
Let X k be the total available energy in time slot k. This is a function of E A(k) , E P (k) and E N (k) . Let Y k be the energy required to execute the policies in time slot k as given by Eq. 2 and Z k is the energy required for operation of the node with a duty cycle factor of δ. In the event of X k <[Y k − Z k ], we haveŶ Y k is the consumed energy to execute the set of policies based on the morphing factor 'α' and Z k is the energy required for adaptive duty cycle based on harvested energy in each time slot. We define the residual energy utility, V , as where E ′ 0 is the lowest survivable residual energy level required for the system to be operational. Now, our multi-criteria optimization problem is formulated as, and First we consider a single objective optimization problem for a given V (i.e., fixing one of the objectives).
we obtain their corresponding OPT(V ), optimal points in application policy versus residual energy curve. This gives a mapping from V to U , which is denoted as f : V → U , where for each point (U, V ), U = f (V ) is the maximum application policy utility that can be obtained.
VII. SOLUTION The solution to OPT(V ) is obtained by using the special structure of linear programming such as the Parametric Analysis (PA). The overall approach is to obtain f (V ) by solving a finite number of linear programs to provide the morphing factor "α", transmission power factor and duty cycle factor "δ". These values ensure minimization of residual energy and maximization of application policies.
Using PA, we study the perturbation of V and its effect on the optimality of OPT(V ) to obtain the perturbation factor λ. We use boldface to denote matrices and vectors. For a given V , the current optimal basis of OPT(V ) could still be optimal when there is a perturbation on V . Thus, the range [E ′ 0 , E ′ 3 ] can be partitioned into consecutive small intervals, each corresponding to a different optimal basis. We use Dual simplex algorithm to find the optimal basis in each iteration. The dual simplex method is useful for reoptimizing a problem after a constarint has been added or some parameters have been changed so that the previous optimal basis is no longer feasible.
The algorithm starts with a basic solution that is dual feasible so all the elements of 'row 0' must be nonnegative. the iterative step of the algortihm first finds the variable that must leave the basis and then finds the variable that must enter the basis to maintian dual feasibility.
For a given V , let the optimal basis matrix be B and the non-basic matrix be N. Let the optimal solution to OPT(V ) is (x B , x N ), where x B and x N denote the values of basic and non-basic variables respectively. Further, let c B and c N denote the coefficient vectors of the objective function of application policy utility U for the basic and non-basic variables respectively. b is the vector with coefficients of V . The corresponding canonical equations are: Let the perturbation on parameter V be V + λ. Then the vector b is replaced by and accordingly the objective becomes c B B −1 (b+λb ′ ). As long as B −1 (b+λb ′ ) is non-negative, the current basis remains the optimal basis. The value of λ for another basis to become optimal can be determined as follows: If S = ∅, then the current basis is optimal for all values of λ ≥ 0. Otherwise, let Let λ 1 =λ, then the current optimal basis is optimal for λ ∈ [0, λ 1 ], where x B = B −1 (b+λb ′ ) and the optimal objective is c B B −1 (b+λb ′ ). When λ > λ 1 , the basis B is no longer optimal. Thus, we need to choose a variable x r to leave the basis, where the minimum in Eq.(10) is attained for i = r. x s is chosen by the dual simplex method rule [33] and we update the canonical equations based on the new optimal basis obtained and get (U, V ) pair as defined earlier for OPT(V ). The process is repeated to find the range [λ 1 , λ 2 ] over which the new basis is optimal.
Algorithm 1 descibes the steps to obtain the new optimal basis for a given basis matrix B. Thus, starting from V = E ′ 0 , we repeat the steps iteratively to find different bases until we reach E ′ 3 . The series ofλ for these bases will partition [E ′ 0 , E ′ 3 ] into small intervals. Thus, by executing the above steps repeatedly, we obtain a series of (U, V ) pairs, each corresponding to an optimal basis. We obtain the application policy versus residual energy optimal curve by connecting these endpoints consecutively. Algorithm 1 Basis Updation Algorithm using Dual simplex method 1: Input: An optimal basis matrix B for a given V.  Optimal application policy versus residual energy when available energy is E 3 Thus for each small interval with an optimal basis, we now Then, the objective value function f(V) can be computesd as In Eq 11. c B , B −1 , b, I are constants and E ′ i is the only variable and hence f(V) is a linear function. Fig.5(I) shows the simulation results where x-axis represents the residual energy (V) between the available and the consumed energy and y-axis represents the total number of operations executed by the node i.e., U . Fig.5(I) shows the optimal curve for a node when available energy is E 3 and its neighbour node energy is either E 1 or E 2 or E 3 . Curves 1 and 2 indicate the optimal curve when the energy prediction for future slots is high and low respectively. When the available energy on the node was E 3 , the morphing factor α obtained were 0.9890, 0.6269, 0.2797 for residual energy of E ′ 0 , E ′ 1 and E ′ 2 respectively. Similar curves are obtained for other available energy levels i.e., E 2 , E 1 on the source node. Fig.5(II) shows the time series of residual energy against the number of operations performed by the source node obtained via simulation and implementation. The source node runs the diffused energy profile from the LRSS. We can see that. the simulation result closely matches the implementation. The difference in number of operations between simulation and implementation is around 6% due to error in prediction. For instance, at time slot 3 of Fig.5(II), the available energy at the source node was wrongly predicted and hence the node performed more operations compared to the simulation result.

VIII. NETWORK AND MAC LAYER PROTOCOL ENHANCEMENTS FOR EHS NODES
In EHS, because each node in the network can harvest energy at various rates, it is necessary to use energy harvesting aware mechanisms at all layers in the protocol stack. Also, as our smart application is expected to run on a network of sensor nodes, in this section we list the key objectives of "energy harvesting aware" network and MAC layer. Furthermore, since routing and MAC layers are well researched in literature, our approach is to identify candidate routing and mac protocols and perform necessary modifications to meet our objectives. Our main focus is to design and develop a multi-node multihop energy harvested sensor nodes for outdoor applications like intrusion detection, smart buildings etc.

A. Network Layer Enhancements
Given a network wide varying energy profile, one major challenge in multi-hop energy harvested WSNs is to find stable routes from the source node to the sink (or base station) over a set of communication nodes. In a typical scenario shown in Fig  2, given a set of possible routes, the question is to find the best route from node D to node A. The selected transmission power at the source and relay nodes should ensure that receiver gain is sufficiently high such that it overcomes channel impairments such as fading. Due to this reason, transmission power control is one of the key requirements.
Since we have chosen 3 discrete energy levels, we have divided the supported radio transmission powers also into 3 discrete values as shown in the figure 6. We use this mapping in the multi criteria optimization setting as well. Due to energy fluctuations, an on-demand routing protocol is required to ensure route stability inspite of nodes abruptly shutting down and powering up. We selected AODVjr, a reactive routing protocol as a candidate. In the beginning, EHS nodes send out a beacon packet using a fixed transmission power. Relay nodes that listen to this beacon use it as a reference received power. The beacons are sent out at regular intervals to ensure that the reference is constantly adjusted to the environment and channel. From our measurements, RSSI reference level of -65 dBm was observed for a transmission power of 0 dBm at a typical inter-node distance of about 25 − 30 feet. Thus each relay node is apriori aware of the signal strength of packet reception from their downstream relays in the network. To setup routes, source nodes transmit route request packets called the RREQ broadcast packets using a transmission power supported by its available energy. This procedure is followed at each relay node that forwards the received RREQ from the source node towards the base station.
We develop a modified AODVjr protocol for EHWSN. In our Modified-AODVjr case, the sink node performs the weighted sum of the link quality against each candidate route and replies with an RREP packet that carries information about the best route back to the source. The best route is the one between the source and destination that has the least weighted sum of the link qualities obtained from Eq. 12 In Eq. 12, C (s,d) indicates the cost from source node to the destination node, RSSI i indicates the Received Signal Strength Indicator (RSSI) of node 'i' and 0 < µ ≤ 1 is the weight assigned based on the RSSI value at each hopnode in the path from source to destination node. The term µ is obtained from extensive measurements performed on our custom board by varying both transmission powers and internode distance.
Since the weighted sum at the sink node is dependant on the network wide energy fluctuations, another modification to AODVjr facilitates every RREQ message to be honoured even in the middle of a data transfer. The latest RREQ messages are used to recompute the weighted sum and if this sum is found to be lesser compared to the previously computed value, the same is conveyed back to the source node via a RREP message. Unlike AODVjr, we reintroduced source sequence numbers to RREQ messages to improve the route reliability. This modification also takes care of dropped and lost RREP packets. Thus Modified-AODVjr compares both the sequence number and overall link quality of the route before sending an RREP.

B. MAC Layer Enhancements
We believe "Virtual Energy Transfer" between peer nodes is an important objective for energy harvesting aware MAC layers. This comes in two related ways: (a) In energy harvested systems, since harvesting rate is dependent on the environmental conditions, the node has to optimize its sleep and wakeup schedules based on the harvested or available energy. For instance, the idle (reception) current for CC2520 is 22.3 mA. Thus, one of the important methods to reduce the energy consumption of the device is by duty cycling. However, an energy harvesting node high on energy would perhaps increase its duty cycle to support and respond to shorter preambles; thereby reducing the energy consumed by the sender. (b) Choice of transmission power for control and data packets should also be based on available energy. In CC2520, the transmission (0dBm) and reception currents are 25.8 mA & 18.5 mA respectively. A node high on energy can include table entries of other high energy nodes; thereby skip entries for low energy neighbours.
We perform enhancements on one of the well known and popular MAC protocols called the BOXMAC-2 protocol [31]. BOXMAC-2 is a random access MAC protocol and uses LPL with periodic check times for ongoing communication.
To reduce overhearing between neighbours, a long preamble is replaced by a short preamble that consists of packets containing the receivers address along with a small receive check period between successive packets. Hence, packet-based MAC protocol is well suited for harvesting systems due to the fact that it does not require any initial arbitration and only the sender and receiver pair spends energy. We have used its ability to draw cross-layer information such as the term δ to adapt the residual energy to the duty cycle.
Only system related operations Otherwise energy transf er is enabled In the event of δ taking a value 0, the node does only system related operations as there is no energy for communication. For all other values of δ the virtual energy is enabled with maximum transfer to neighbours at δ = 1.

IX. RESULTS
In this section, we discuss the results pertaining to: (a) Efficacy of energy prediction models, (b) Routing layer performance for varying energy profiles, and (c) Adaptive duty cycling on EHS nodes based on the harvested energy.

A. Evaluation of energy prediction models
We compare the real solar data with virtual solar data obtained from EWMA and HW prediction models for five days of a month. The first, second and the fourth days correspond to sunny conditions and the second, fifth day represents the cloudy situations as shown in Fig 7. Since EWMA prediction algorithm only uses values from previous days at the same time period, if the weather condition changes for the next day, this method presents a large error in prediction. Looking at the Fig. 7 it can be easily noticed that EWMA algorithm fails to adapt to changes in weather on consecutive days. The HW model computes the terms ǫ, β, γ based on the previous solar data to obtain the weighting, trend and seasonal factors. It can be clearly seen from the Fig. 7, HW prediction model has the ability to predict the solar values by considering both seasonal and weather condition changes from one day to another. This improvement in prediction of solar energy comes from the trend and seasonal factors considered by the prediction model. From the three year datasets, we evaluated the maximum average error percentage of about 45% for EWMA prediction model and around 7% for Holt-Winters energy prediction model. It is also noted from [32] that the channel coherence time is very high and hence change in RSSI is mainly due to change in transmission power. It is clear from the figure, transmission power change impacts RSSI and hence node changes the transmission power based on the energy level which is reflected on the RSSI value. We use this RSSI value to identify the neighbour nodes energy level and we call this as "Faking of RSSI" based on the energy level. Our Modified-AODVjr routing protocol decides the best route to the destination node based on the weighted sum of the link quality. To study the performance comparison between AODVjr and Modified-AODVjr, we implemented both the protocols on our custom mote. Our metric for comparison is the packet delivery ratio. The experimental setup is as shown in Fig. 2. Once the source node is powered up, it sends RREQ message to all its neighbours with the destination node replying either to the first RREQ (AODVjr) or reply based on the overall link quality of the route (Modified-AODVjr). In both the experiments the source node generates a data packet every 2 seconds with a payload of 22 bytes. Fig. 9 shows the comparison of packet delivery ratio between AODVjr and Modified AODVjr. The Modified-AODVjr protocol has a average packet delivery ratio of 72.7% whereas AODVjr has an average packet delivery ratio of 51.2 %. Thus, Modified-AODVjr routing protocol is necessary for energy harvested systems to improve packet delivery ratio and quick route convergence.

C. Adaptive Duty Cycling
As described previously, "Virtual Energy Transfer" between peer nodes is an important objective for energy harvesting aware MAC. We utilize the optimal δ value obtained from our optimization to set the duty cycle on EHS nodes. Fig. 10 shows three cases based on the δ value (a) The δ value of 0.05 corresponds to duty cycle of (5%) due to low energy available on the node (b) duty cycle of 15% was chosen when the node has intermediate energy level and the obtained δ value is 0.15, thus decreasing the sleep periods (c) when the harvested energy level is E 3 , δ obtained is 0.25, hence the duty cycle on the node is set to 25%. In Fig. 10, the source node has to send short packets as preamble for the duration of sleep time i.e., 100ms for (5%) duty cycle when the energy level is E 1 . When harvested energy level on the node is higher i.e E 2 , E 3 the number of packets sent as preamble by the source node to wakeup the neighbour should span the sleep interval of 35ms and 20ms respectively. Thus, reducing the number of short preambles sent by the sender and the energy spent by the source node when neighbour node is high on energy. Thus, enabling "Virtual Energy Transfer" between peer nodes at the MAC layer.

D. Application
We show the performance of the distributed smart application running on sensor Node D (in Fig.2) associated with a diffused energy profile. The solar emulator placed above Node D generates the diffused energy profile where most of the time either (E 1 ) or (E 2 ) amount of harvested energy is available. The sensor node uses the Holt-Winters energy prediction algorithm in every time slot to obtain the virtual energy. For generating a reference, we exposed Node D to a constant high energy profile to fix E 3 . Fig.11(I) shows the behaviour of the morphed application on sensor Node D. The plot shows the comparison for two cases: Case-1 is the reference (E 3 ) energy level and Case-2 when the node is subjected to the diffused energy profile.
In Case-1, the source and the neighbour's energy was always high at E 3 and thus Node D could perform all the policies associated with the energy level E 3 . This can be considered as the best case and serve as a reference for the distributed smart application. In Case-2, the source is associated with diffused energy profile and the neighbour node's energy profile is reflected. Fig.11(I) shows the results of application morphing under energy fluctuation. We captured these fluctuations as events and enumerated them as: (a) when the energy of node is low and predicted energy for future time slots is high and vice-versa; (b) when energy level of the node is high but the network's energy level is low and vice-versa. In Fig.11(I), several regions namely p, q, r, s, t show energy level transitions as well as application morphing. The region 'p' indicates the change in energy level from E 3 to E 2 on the source node. The region 'q' indicates the morphing of the application in one time slot before the change in energy level on the source node. The application morphed to a slower version of the base application as shown in region 'q' where the number of operations performed by the source node was significantly less compared to the previous time slot. This morphing improves the available energy on the energy buffer. The region 'r' shows the low energy profile E 1 on the source node and finally region 's' shows the application morphing to a slower version of the base application. This application morphing event is due to source node energy level being low and future time slot energy level is high. However, in the next time slot it can be clearly seen that Node D morphed to a faster version towards the base application as the future energy level is E 3 and region 't' indicates the increase in number of operations performed by the sensor Node D. Fig.11(II) shows the implementation result of application morphing on the source node for various energy profiles obtained from LRSS. The neighbouring node was running reflected energy profile. As expected, it can be clearly seen that application morphing was enabled even when the source node was running on direct energy profile. In summary, the upper bound on application performance is dependant on source node's own energy as well as network's energy. Application performance when source node runs other energy profiles is also shown.   12 shows the number of operations performed by the relay nodes B and C in each time slot. The relay node B runs direct energy profile and relay node C runs reflected energy profile. As can be observed from the figure, relay node B supported the source node to perform network related operations in most of the time slots. Figure 13 shows the number of operations performed by the source node with diffused energy profile. The figure shows the number of node's own operations and network operations performed. In time slot 9 the node was in intermediate energy level and the network returned intermediate support and hence, the source performed few network and its own operations. However, in the next time slot source node was in high energy level and network returned intermediate support, hence node performed less network operations and more node's own operations.
To study the efficacy of the optimization method, we enumerated number of node and network operations (refer Table  I) performed by each node for all energy profiles. When the source node has diffused energy profile and neighbour has reflected profile, the source performed 354 node operations and 172 network operations. The source node performed 475, 656 node operations and 190, 212 network operations for reflected and directed energy profiles respectively.

X. DISCUSSIONS
In this paper, we discuss energy harvesting aware routing and MAC protocols. The prediction of virtual energy plays an important role on the application performance. As shown in section V, we evaluated two of the most common time series prediction models. It can be clearly seen from Fig. 7, if the real energy level was E 3 , EWMA model forecasted the energy level as E 2 whereas HW model forecasted it as E 3 and when real energy level was E 2 , the forecasted values were E 1 and E 2 by EWMA and HW models respectively. From our datasets, we evaluated the maximum error percentage of about 45% for EWMA prediction model. Whereas, for HW model it is around 7%. Thus EWMA model based predictions deteriorate the application performance. In our experiments we found that when HW prediction model was used, on an average 64.5% of the operations were performed at the source node. The values of the parameters ǫ, β and γ used in HW prediction model vary for different solar power traces. Concerning the routing protocol, significant energy savings were seen due to absence of control messages such as Hello, RERR etc. While the base station uses weighted sum of the link quality metric to provide a route, in reality, since power control is used by nodes, the link quality is a direct manifestation of the available energy. In the MAC layer, we believe "virtual energy transfer" ensures energy neutral operations for a multi-hop multi-node network setting.

XI. CONCLUSIONS
We have implemented a multihop EHWSN using solar energy. The efficacy of the proposed optimization algorithm was studied by evaluating node and network operations for various energy profiles. Clearly, the predicted, network and available energy contribute to the working of the distributed application. The smart application was able to maximize its operations by adjusting its application policy (rate) to satisfy the least residual energy criteria. In this work the number of hops is limited and we have only showed possible way of building application morphing also considering available energy in the nodes of the network rather than source node alone. We are encouraged by the results and propose to extend the network to include more number of hops and entire routes to study the scalability of our scheme. To the best of our knowledge this is the first implementation of a multihop energy harvested WSN, albeit two hops. We believe that our results are a step forward towards larger EHWSN deployments. We plan to generalize this work by proposing a cognitive networking stack for EHWSNs. The idea here is to provide hooks that consider EH including predictions at every layer of the networking stack. Moreover, we propose to study the distributed algorithms also with handles such as dynamically varying available voltage and possible frequency scaling.